Skip to content
Snippets Groups Projects
Commit 35174f05 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko
Browse files

#470 Fixed rotation been canceled when after doubleTap puzzle piece was...

#470 Fixed rotation been canceled when after doubleTap puzzle piece was dropped to early and therefore was rotated back to initial angle.
parent db229f86
Branches
Tags
No related merge requests found
......@@ -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;
......
......@@ -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();
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment