diff options
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/Ctrl.java | 5 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/Hud.java | 52 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/hud/ActionButtons.java | 29 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java | 46 |
4 files changed, 24 insertions, 108 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Ctrl.java b/core/src/ch/asynk/rustanddust/game/Ctrl.java index b9520ff..024bd02 100644 --- a/core/src/ch/asynk/rustanddust/game/Ctrl.java +++ b/core/src/ch/asynk/rustanddust/game/Ctrl.java @@ -103,7 +103,7 @@ public class Ctrl implements Disposable { boolean inAnimation = (this.stateType == StateType.ANIMATION); - if (!blockHud && hud.touchDown(hudTouch.x, hudTouch.y, inAnimation)) + if (!blockHud && hud.hit(hudTouch.x, hudTouch.y, inAnimation)) return; if (!blockMap && state.downInMap(mapTouch.x, mapTouch.y)) @@ -112,9 +112,6 @@ public class Ctrl implements Disposable public void touchUp() { - if (!blockHud && hud.touchUp(hudTouch.x, hudTouch.y)) - return; - if (!blockMap && state.upInMap(mapTouch.x, mapTouch.y)) state.touchUp(); } diff --git a/core/src/ch/asynk/rustanddust/game/Hud.java b/core/src/ch/asynk/rustanddust/game/Hud.java index a90507f..1e869f4 100644 --- a/core/src/ch/asynk/rustanddust/game/Hud.java +++ b/core/src/ch/asynk/rustanddust/game/Hud.java @@ -33,8 +33,6 @@ public class Hud implements Disposable, Animation private final RustAndDust game; private final Ctrl ctrl; - private Object hit; - public PlayerInfo playerInfo; public ActionButtons actionButtons; @@ -184,19 +182,17 @@ public class Hud implements Disposable, Animation return playerInfo.drag(x, y, dx, dy); } - public boolean touchDown(float x, float y, boolean isInAnimation) + public boolean hit(float x, float y, boolean isInAnimation) { - hit = null; - if (optionsBtn.hit(x, y)) { - hit = optionsBtn; + toggleOptionsPanel(); return true; } if (dialogs.size() > 0) { Widget dialog = dialogs.peek(); if (dialog.hit(x, y)) { - hit = dialog; + closeDialog(); return true; } return false; @@ -205,46 +201,12 @@ public class Hud implements Disposable, Animation if (isInAnimation) return false; - if (hit == null) { - if (actionButtons.touchDown(x, y)) - hit = actionButtons; - else if (playerInfo.touchDown(x, y)) - hit = playerInfo; - } - - return (hit != null); - } - - public boolean touchUp(float x, float y) - { - if (hit == null) - return false; - - if (hit == optionsBtn) { - if (optionsBtn.hit(x, y)) - toggleOptionsPanel(); + if (actionButtons.hit(x, y)) + return true; + else if (playerInfo.hit(x, y)) return true; - } - - if (dialogs.size() > 0) { - Widget dialog = dialogs.peek(); - if (hit == dialog) { - if (dialog.hit(x, y)) - closeDialog(); - hit = null; - } - } else { - if (hit == actionButtons) { - actionButtons.touchUp(x, y); - } - else if (hit == playerInfo) { - playerInfo.touchUp(x, y); - } - - hit = null; - } - return true; + return false; } private void closeDialog() diff --git a/core/src/ch/asynk/rustanddust/game/hud/ActionButtons.java b/core/src/ch/asynk/rustanddust/game/hud/ActionButtons.java index ef15222..51ba8a0 100644 --- a/core/src/ch/asynk/rustanddust/game/hud/ActionButtons.java +++ b/core/src/ch/asynk/rustanddust/game/hud/ActionButtons.java @@ -35,7 +35,6 @@ public class ActionButtons extends Widget } private Sprite bg; - private int idx; private Bg buttons []; private StateType states []; @@ -45,7 +44,6 @@ public class ActionButtons extends Widget this.ctrl = game.ctrl; this.visible = false; this.position = Position.BOTTOM_RIGHT; - this.idx = Buttons.NONE.i; this.buttons = new Bg[Buttons.LAST.i]; this.buttons[Buttons.DONE.i] = new Bg(game.factory.getHudRegion(game.factory.ACT_DONE)); @@ -130,38 +128,19 @@ public class ActionButtons extends Widget this.visible = true; } - public boolean touchDown(float x, float y) + public boolean hit(float x, float y) { - idx = Buttons.NONE.i; - if (!super.hit(x,y)) return false; for (int i = 0; i < Buttons.LAST.i; i++) { if (buttons[i].hit(x, y)) { - idx = i; - break; + ctrl.setState(states[i]); + return true; } } - return (idx != Buttons.NONE.i); - } - - public boolean touchUp(float x, float y) - { - if (idx == Buttons.NONE.i) - return false; - - boolean ret = false; - - if (super.hit(x,y) && buttons[idx].hit(x, y)) { - ctrl.setState(states[idx]); - ret = true; - } - - idx = Buttons.NONE.i; - - return ret; + return false; } @Override diff --git a/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java b/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java index a7dea32..ab5c368 100644 --- a/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java +++ b/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java @@ -22,8 +22,6 @@ public class PlayerInfo implements Disposable, Drawable, Animation private final Ctrl ctrl; - private Object hit; - private Bg flag; private Bg usFlag; private Bg geFlag; @@ -136,43 +134,23 @@ public class PlayerInfo implements Disposable, Drawable, Animation return true; } - public boolean touchDown(float x, float y) - { - hit = null; - - if (reinforcement.hit(x, y)) - hit = reinforcement; - else if (unitDock.hit(x, y)) - hit = unitDock; - else if (turns.hit(x,y)) - hit = turns; - - return (hit != null); - } - - public boolean touchUp(float x, float y) + public boolean hit(float x, float y) { - if (hit == null) - return false; - - if (hit == turns) { - if (turns.hit(x, y)) - ctrl.hud.askEndOfTurn(); + if (turns.hit(x, y)) { + ctrl.hud.askEndOfTurn(); + return true; } - else if (hit == reinforcement) { - if (reinforcement.hit(x, y)) - ctrl.reinforcementHit(); + else if (reinforcement.hit(x, y)) { + ctrl.reinforcementHit(); + return true; } - else if (hit == unitDock) { - if (unitDock.hit(x, y)) { - ctrl.hud.notify(unitDock.select(x, y).toString(), Position.TOP_CENTER); - ctrl.showEntryZone(); - } + else if (unitDock.hit(x, y)) { + ctrl.hud.notify(unitDock.select(x, y).toString(), Position.TOP_CENTER); + ctrl.showEntryZone(); + return true; } - hit = null; - - return true; + return false; } @Override |