diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-12-19 18:51:36 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-12-19 18:52:34 +0100 |
commit | bfdcabc73be8b8d4df7207d3ea030091e693a886 (patch) | |
tree | 966ff1afaae1547e44a3601b42efdf1ea334f519 /core/src/ch/asynk/rustanddust/game/hud | |
parent | cdb78a4dd7f117d6fdcd1b84ba057db9e4ba81ac (diff) | |
download | RustAndDust-bfdcabc73be8b8d4df7207d3ea030091e693a886.zip RustAndDust-bfdcabc73be8b8d4df7207d3ea030091e693a886.tar.gz |
Hud: replace touchUp + touchDown with hit(int, int)
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/hud')
-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 |
2 files changed, 16 insertions, 59 deletions
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 |