# HG changeset patch # User dermetfan # Date 1422306446 -3600 # Mon Jan 26 22:07:26 2015 +0100 # Node ID c4e6601114bbb449c1f8165def4af50e62e58774 # Parent b2eff5d9b467b57b04673d4646d41c770ae9c36a fixed some bugs, Piece#hit(..) now only hits if on polygon diff --git a/core/src/net/dermetfan/jigsawPuzzle/puzzle/JigsawPuzzle.java b/core/src/net/dermetfan/jigsawPuzzle/puzzle/JigsawPuzzle.java --- a/core/src/net/dermetfan/jigsawPuzzle/puzzle/JigsawPuzzle.java +++ b/core/src/net/dermetfan/jigsawPuzzle/puzzle/JigsawPuzzle.java @@ -14,6 +14,7 @@ package net.dermetfan.jigsawPuzzle.puzzle; +import com.badlogic.gdx.math.Polygon; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Group; @@ -39,8 +40,8 @@ private final SnapshotArray placedPieces, remainingPieces; public JigsawPuzzle() { - remainingPieces = new SnapshotArray(); - placedPieces = new SnapshotArray(); + remainingPieces = new SnapshotArray(Piece.class); + placedPieces = new SnapshotArray(Piece.class); } /** @param pieces the amount of pieces that will probably be in this puzzle */ @@ -118,12 +119,14 @@ /** @return the {@link #placedPieces} */ public Piece[] getPlacedPieces() { placedPieces.end(); + placedPieces.shrink(); return placedPieces.begin(); } /** @return the {@link #remainingPieces} */ public Piece[] getRemainingPieces() { remainingPieces.end(); + remainingPieces.shrink(); return remainingPieces.begin(); } @@ -242,6 +245,20 @@ slotX = slotY = 0; } + private final Polygon tmpPolygon = new Polygon(); + + @Override + public Actor hit(float x, float y, boolean touchable) { + Actor hit = super.hit(x, y, touchable); + if(hit == this) { + tmpPolygon.setVertices(((PolygonRegionDrawable) getDrawable()).getRegion().getVertices()); + tmpPolygon.setPosition(-slotX, -slotY); + if(!tmpPolygon.contains(x / getWidth() * GeometryUtils.width(tmpPolygon.getVertices()), y / getHeight() * GeometryUtils.height(tmpPolygon.getVertices()))) + return null; + } + return hit; + } + /** @param ref the piece in relation to which to snap into this piece's spot */ public void snap(Piece ref) { Vector2 refPuzzlePoint = Pools.obtain(Vector2.class).set(ref.getX(), ref.getY()).sub(ref.slotX, ref.slotY); diff --git a/core/src/net/dermetfan/jigsawPuzzle/screens/PlayScreen.java b/core/src/net/dermetfan/jigsawPuzzle/screens/PlayScreen.java --- a/core/src/net/dermetfan/jigsawPuzzle/screens/PlayScreen.java +++ b/core/src/net/dermetfan/jigsawPuzzle/screens/PlayScreen.java @@ -133,8 +133,8 @@ } }); - dialog.getContentTable().add(board).expand().fill().minSize(bank.getWidth(), bank.getHeight()).row(); - dialog.getContentTable().add(bank).expand().fill(); + dialog.getContentTable().add(board).expand().fill().row(); + dialog.getContentTable().add(bank).expand().fill().minSize(bank.getWidth(), bank.getHeight()); dialog.show(stage); } diff --git a/core/src/net/dermetfan/jigsawPuzzle/utils/Board.java b/core/src/net/dermetfan/jigsawPuzzle/utils/Board.java --- a/core/src/net/dermetfan/jigsawPuzzle/utils/Board.java +++ b/core/src/net/dermetfan/jigsawPuzzle/utils/Board.java @@ -15,11 +15,11 @@ package net.dermetfan.jigsawPuzzle.utils; import com.badlogic.gdx.scenes.scene2d.Actor; -import com.badlogic.gdx.scenes.scene2d.Group; +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 Group { +public class Board extends WidgetGroup { /** wraps this Board's size around its children */ public void pack() {