From 57bebfaade1651e4de7f5ff49063937b4f427c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 31 May 2020 19:35:33 +0200 Subject: BoardScreen : clean up touch management --- .../ch/asynk/gdx/boardgame/test/BoardScreen.java | 55 ++++++++++++---------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java index c5306d3..6d762fa 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java @@ -73,36 +73,43 @@ public class BoardScreen extends AbstractScreen public boolean touch(float x, float y, boolean down) { board.toBoard(x, y, v); - GdxBoardTest.debug("BoardScreen", String.format("touchDown [%d;%d] => [%d;%d] => %d", (int)x, (int)y, (int)v.x, (int)v.y, board.genKey((int)v.x, (int)v.y))); - float d0 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TCHEBYCHEV); - float d1 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TAXICAB); - float d2 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.EUCLIDEAN); - if (board.isOnMap((int)v.x, (int)v.y)) { - GdxBoardTest.debug("BoardScreen", String.format(" from [%d;%d] => %d :: %d :: %f", (int)pos.x, (int)pos.y, (int)d0, (int)d1, d2)); - if (down) { - Tile tile = getTile((int)v.x, (int)v.y); - if (!dragging && panzer.isOn(tile)) { - dragging = true; - clearAdjacents(); - } else { - pos.set(v); - handleAdjacents(); - board.centerOf((int)v.x, (int)v.y, v); - panzer.centerOn(v.x, v.y); - panzer.setRotation(Orientation.fromR(panzer.getRotation()).left().r()); - GdxBoardTest.debug("BoardScreen", String.format(" => [%d;%d]", (int)v.x, (int)v.y)); - } + if (!board.isOnMap((int)v.x, (int)v.y)) + return false; + if (down) { + Tile tile = getTile((int)v.x, (int)v.y); + if (!dragging && panzer.isOn(tile)) { + dragging = true; + clearAdjacents(); } else { - if (dragging) { - handleAdjacents(); - panzer.dropOnBoard(board, v); - dragging = false; - } + touchInfo(x, y); + pos.set(v); + handleAdjacents(); + board.centerOf((int)v.x, (int)v.y, v); + panzer.centerOn(v.x, v.y); + panzer.setRotation(Orientation.fromR(panzer.getRotation()).left().r()); + GdxBoardTest.debug("BoardScreen", String.format(" => [%d;%d]", (int)v.x, (int)v.y)); + } + } else { + if (dragging) { + touchInfo(x, y); + handleAdjacents(); + panzer.dropOnBoard(board, v); + GdxBoardTest.debug("BoardScreen", String.format(" => [%d;%d]", (int)v.x, (int)v.y)); + dragging = false; } } return true; } + private void touchInfo(float x, float y) + { + GdxBoardTest.debug("BoardScreen", String.format("touchDown [%d;%d] => [%d;%d] => %d", (int)x, (int)y, (int)v.x, (int)v.y, board.genKey((int)v.x, (int)v.y))); + float d0 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TCHEBYCHEV); + float d1 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TAXICAB); + float d2 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.EUCLIDEAN); + GdxBoardTest.debug("BoardScreen", String.format(" from [%d;%d] => %d :: %d :: %f", (int)pos.x, (int)pos.y, (int)d0, (int)d1, d2)); + } + public boolean drag(float dx, float dy) { if (dragging) { -- cgit v1.1-2-g2b99