diff --git a/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java b/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java index 5e73284be60b6f69a8c66afb0fa050daa778e219..61f352696871c33224c615ad08d43d0786a8c96b 100644 --- a/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java +++ b/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java @@ -334,13 +334,15 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> { } } //in case we canceled rotation animation, rotate piece to correct angle - grid.addAction(Actions.sequence(new RotatePieceToClosestAngle((PuzzlePiece) draggedPiece), Actions.run(new Runnable() { - @Override - public void run() { - // check if puzzle is solved after possible rotation animation - checkEndGameCondition(); - } - }))); + if (!isRotatedWithDoubleTap()) { //in case of double tap next action will rotate piece back to the ange before the rotation + grid.addAction(Actions.sequence(new RotatePieceToClosestAngle((PuzzlePiece) draggedPiece), Actions.run(new Runnable() { + @Override + public void run() { + // check if puzzle is solved after possible rotation animation + checkEndGameCondition(); + } + }))); + } } checkEndGameCondition(); return true; diff --git a/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java b/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java index 6229bbb32e872618420aed0e84a442b3d3bbc028..74d55847b0479bdfa90b5a5a45007ffac682df70 100644 --- a/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java +++ b/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java @@ -35,6 +35,7 @@ public class DragAndRotateActorListener extends InputListener { private boolean performingAction; private boolean pieceAnimationDone; private Touch lastTouch, newTouchDown; + private boolean rotatedWithDoubleTap; private RotateAndMovePieceInPosition pieceTranslationAction; @@ -123,28 +124,22 @@ public class DragAndRotateActorListener extends InputListener { @Override public void touchUp(InputEvent event, final float x, final float y, int pointer, int button) { - if (pointer==0 && button !=1) { //don't react on right mouse button double tap - Touch newTouchUp = new Touch(((Grid) parentActor).pieceAtPoint(x, y), TimeUtils.millis()); - if (newTouchDown != null) { - if (Touch.isTap(newTouchUp,newTouchDown)) { - if (lastTouch != null) { - if (Touch.isDoubleTap(newTouchUp,lastTouch) && !lastTouch.getTouchedActor().hasActions()) { - final Actor actorToRotate = lastTouch.getTouchedActor(); - final float newRotationAngle = ArithmeticsHelper.getClosestRightAngle(actorToRotate.getRotation()-90); - // FIXME: 22.8.16 sometime piece is rotaed back to the original rotation - actorToRotate.addAction(Actions.sequence(Actions.rotateTo(newRotationAngle, ROTATION_ANIMATION_DURATION), Actions.run(new Runnable() { - @Override - public void run() { - rotated(newRotationAngle, actorToRotate); - dropped(x,y,actorToRotate); - } - }))); - } else { - lastTouch = new Touch(draggedActor, (newTouchUp.getTime() + newTouchDown.getTime()) / 2); //not double - save least touch + if (pointer == 0 && button != 1) { //don't react on right mouse button double click + Touch newTouchUp = new Touch(((Grid) parentActor).pieceAtPoint(x, y), TimeUtils.millis()); + if (newTouchDown != null) { // check if there is record of last touchDown event + if (isCorrectDoubleTap(newTouchUp, newTouchDown)) { //check if those touches can be doubleTap gesture + setRotatedWithDoubleTap(true); // prevent animation canceling on drop event + final Actor actorToRotate = lastTouch.getTouchedActor(); + final float newRotationAngle = ArithmeticsHelper.getClosestRightAngle(actorToRotate.getRotation() - 90); + actorToRotate.addAction(Actions.sequence(Actions.rotateTo(newRotationAngle, ROTATION_ANIMATION_DURATION), Actions.run(new Runnable() { + @Override + public void run() { + rotated(newRotationAngle, actorToRotate); + dropped(x, y, actorToRotate); // force check if rotated piece isn't completing the map } - } else { - lastTouch = new Touch(draggedActor, (newTouchUp.getTime() + newTouchDown.getTime()) / 2); - } + }))); + } else { + resetLastTouch(newTouchUp, newTouchDown); } } } @@ -199,6 +194,34 @@ public class DragAndRotateActorListener extends InputListener { } + /** + * Check is new touchDown+touchUp is tap and check if this new tap can be double tap gesture with last recorded tap + * @param newTouchUp + * @param newTouchDown + * @return + */ + private boolean isCorrectDoubleTap(Touch newTouchUp, Touch newTouchDown) { + return Touch.isTap(newTouchUp, newTouchDown) && lastTouch != null && Touch.isDoubleTap(newTouchUp, lastTouch); + } + + /** + * Resets last correct tap + * @param newTouchUp + * @param newTouchDown + */ + private void resetLastTouch(Touch newTouchUp, Touch newTouchDown) { + setRotatedWithDoubleTap(false); + lastTouch = new Touch(draggedActor, (newTouchUp.getTime() + newTouchDown.getTime()) / 2); + } + + public boolean isRotatedWithDoubleTap() { + return rotatedWithDoubleTap; + } + + public void setRotatedWithDoubleTap(boolean rotatedWithDoubleTap) { + this.rotatedWithDoubleTap = rotatedWithDoubleTap; + } + public interface IOnRotationFinished { void onDragAndRotationFinished(); }