From 25f0e73ec6a9c4479dd68357bf126da73e8e7f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 11 Nov 2014 18:24:58 +0100 Subject: Hud,PlayerInfo: simplify touchUp/Down control --- core/src/ch/asynk/tankontank/game/Hud.java | 28 ++++++++++++--------- .../ch/asynk/tankontank/game/hud/PlayerInfo.java | 29 +++++++++++----------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index 3afd2dc..f39a1e7 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -119,18 +119,16 @@ public class Hud implements Disposable { hit = null; - if (playerInfo.touchDown(x, y)) - hit = playerInfo; - else if (actionButtons.touchDown(x, y)) + if (actionButtons.touchDown(x, y)) hit = actionButtons; + else if (playerInfo.touchDown(x, y)) + hit = playerInfo; else if (okCancel.hit(x, y)) hit = okCancel; else if (stats.hit(x, y)) hit = stats; - else - return false; - return true; + return (hit != null); } public boolean touchUp(float x, float y) @@ -138,14 +136,20 @@ public class Hud implements Disposable if (hit == null) return false; - if (hit == actionButtons) + if (hit == actionButtons) { actionButtons.touchUp(x, y); - else if (hit == playerInfo) + } + else if (hit == playerInfo) { playerInfo.touchUp(x, y); - else if ((hit == okCancel) && okCancel.hit(x, y)) - closeDialog(); - else if ((hit == stats) && stats.hit(x, y)) - closeDialog(); + } + else if (hit == okCancel) { + if (okCancel.hit(x, y)) + closeDialog(); + } + else if (hit == stats) { + if (stats.hit(x, y)) + closeDialog(); + } hit = null; diff --git a/core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java b/core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java index bb4ad93..7e751bf 100644 --- a/core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java +++ b/core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java @@ -135,15 +135,10 @@ public class PlayerInfo implements Disposable, Drawable hit = reinforcement; else if (unitDock.hit(x, y)) hit = unitDock; - else { - hideUnitDock(); - if (turns.hit(x,y)) - hit = turns; - else - return false; - } + else if (turns.hit(x,y)) + hit = turns; - return true; + return (hit != null); } public boolean touchUp(float x, float y) @@ -151,12 +146,18 @@ public class PlayerInfo implements Disposable, Drawable if (hit == null) return false; - if ((hit == turns) && turns.hit(x, y)) - ctrl.hud.askEndTurn(); - else if ((hit == reinforcement) && reinforcement.hit(x, y)) - unitDock.toggle(); - else if ((hit == unitDock) && unitDock.hit(x, y)) - ctrl.setState(StateType.ENTRY); + if (hit == turns) { + if (turns.hit(x, y)) + ctrl.hud.askEndTurn(); + } + else if (hit == reinforcement) { + if (reinforcement.hit(x, y)) + ctrl.toggleState(StateType.ENTRY, StateType.SELECT); + } + else if (hit == unitDock) { + if (unitDock.hit(x, y)) + ctrl.stateTouchUp(); + } hit = null; -- cgit v1.1-2-g2b99