M core/src/net/dermetfan/jigsawPuzzle/screens/PlayScreen.java +11 -33
@@ 15,10 15,7 @@
package net.dermetfan.jigsawPuzzle.screens;
import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Input.TextInputListener;
-import com.badlogic.gdx.InputAdapter;
-import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.Batch;
@@ 28,12 25,12 @@ import com.badlogic.gdx.scenes.scene2d.S
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
+import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import net.dermetfan.jigsawPuzzle.Assets;
import net.dermetfan.jigsawPuzzle.Constants;
import net.dermetfan.jigsawPuzzle.puzzle.JigsawPuzzle;
import net.dermetfan.jigsawPuzzle.puzzle.JigsawPuzzle.Piece;
-import net.dermetfan.jigsawPuzzle.utils.Board;
import net.dermetfan.jigsawPuzzle.utils.PolygonRegionDrawable;
/** a UI for a {@link JigsawPuzzle}
@@ 62,29 59,7 @@ public class PlayScreen extends ScreenAd
@Override
public void show() {
- Gdx.input.setInputProcessor(!Constants.debug ? stage : new InputMultiplexer(new InputAdapter() {
-
- @Override
- public boolean keyDown(int keycode) {
- if(keycode == Keys.R && (Gdx.input.isKeyPressed(Keys.CONTROL_LEFT) || Gdx.input.isKeyPressed(Keys.CONTROL_RIGHT))) {
- Gdx.input.getTextInput(new TextInputListener() { // temporary solution - ask user for name of the level directory to load psh files (pieces) from
- @Override
- public void input(String level) {
- initUI(level);
- }
-
- @Override
- public void canceled() {
- Gdx.app.log("PlayScreen", "no level selected, not changing");
- }
-
- }, "select new level", "", "enter new level name");
- return true;
- }
- return false;
- }
-
- }, stage)); // make sure the stage receives input events
+ Gdx.input.setInputProcessor(stage); // let the stage receive input events
}
/** creates the UI and puzzle
@@ 103,14 78,17 @@ public class PlayScreen extends ScreenAd
dialog.setResizable(true);
final JigsawPuzzle puzzle = new JigsawPuzzle();
- final Board bank = new Board(); // the board that pieces will be dragged from
- final Board board = new Board(); // the board pieces will be dropped on
+ final WidgetGroup bank = new WidgetGroup(); // the group that pieces will be dragged from
+ final WidgetGroup board = new WidgetGroup(); // the group that pieces will be dropped on
+ float nextX = 0, tallest = 0;
for(FileHandle psh : Assets.puzzlePSHs(level)) { // set up the pieces on the bank
Piece piece = new Piece(new PolygonRegionDrawable(Assets.manager.get(psh.path(), PolygonRegion.class)));
+ puzzle.addRemaining(piece);
bank.addActor(piece);
- piece.setX(bank.getWidth());
- bank.pack();
- puzzle.addRemaining(piece);
+ piece.setX(nextX);
+ nextX += piece.getWidth();
+ if(piece.getHeight() > tallest)
+ tallest = piece.getHeight();
}
puzzle.setUp(bank, board, new Runnable() {
@@ 134,7 112,7 @@ public class PlayScreen extends ScreenAd
});
dialog.getContentTable().add(board).expand().fill().row();
- dialog.getContentTable().add(bank).expand().fill().minSize(bank.getWidth(), bank.getHeight());
+ dialog.getContentTable().add(bank).expandX().fill().minSize(nextX, tallest);
dialog.show(stage);
}
R core/src/net/dermetfan/jigsawPuzzle/utils/Board.java => +0 -38
@@ 1,38 0,0 @@
-/** Copyright 2014 Robin Stumm (serverkorken@gmail.com, http://dermetfan.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. */
-
-package net.dermetfan.jigsawPuzzle.utils;
-
-import com.badlogic.gdx.scenes.scene2d.Actor;
-import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
-
-/** a group that simply wraps its size around its children in {@link #pack()}
- * @author dermetfan */
-public class Board extends WidgetGroup {
-
- /** wraps this Board's size around its children */
- public void pack() {
- float width = Float.NEGATIVE_INFINITY, height = Float.NEGATIVE_INFINITY, childXandWidth, childYandHeight;
- for(Actor child : getChildren()) {
- if((childXandWidth = child.getX() + child.getWidth()) > width)
- width = childXandWidth;
-
- if((childYandHeight = child.getY() + child.getHeight()) > height)
- height = childYandHeight;
- }
-
- setSize(width, height);
- }
-
-}
No newline at end of file