diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-27 16:34:36 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-27 16:34:36 +0100 |
commit | 78c2768388dfeaf7da10168c0cafdc77e4c3f247 (patch) | |
tree | 065145a6618d741ce0ec95740b5bd8cbc65929b3 /core/src/ch | |
parent | c65ee999c4377c0a6d6f5826c3b8b52b1d7ed670 (diff) | |
download | RustAndDust-78c2768388dfeaf7da10168c0cafdc77e4c3f247.zip RustAndDust-78c2768388dfeaf7da10168c0cafdc77e4c3f247.tar.gz |
Hud,Ctrl,OkCancel: Hud stacks dialogs
Diffstat (limited to 'core/src/ch')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Ctrl.java | 5 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Hud.java | 117 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/OkCancel.java | 23 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/states/StateAnimation.java | 2 |
4 files changed, 75 insertions, 72 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index 3390863..9971bfa 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -195,6 +195,10 @@ public class Ctrl implements Disposable nextState = actionDone(); } + if (stateType == StateType.ANIMATION) { + this.blockMap = hud.dialogActive(); + } + this.state.leave(nextState); TankOnTank.debug(" switch to : " + nextState); @@ -222,6 +226,7 @@ public class Ctrl implements Disposable this.state = escapeState; break; case ANIMATION: + this.blockMap = true; this.state = animationState; break; case REINFORCEMENT: diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index da3c31c..d5a14bb 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -1,5 +1,7 @@ package ch.asynk.tankontank.game; +import java.util.LinkedList; + import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.graphics.g2d.Batch; @@ -37,19 +39,7 @@ public class Hud implements Disposable private Statistics stats; private Engagement engagement; private OkCancel okCancel; - private DialogAction dialogAction; - private Widget[] dialogs; - - enum DialogAction - { - EXIT_BOARD, - ABORT_TURN, - END_TURN, - END_DEPLOYMENT, - END_GAME, - END_ENGAGEMENT, - NONE - } + private LinkedList<Widget> dialogs = new LinkedList<Widget>(); public Hud(final Ctrl ctrl, final TankOnTank game) { @@ -66,8 +56,6 @@ public class Hud implements Disposable okCancel = new OkCancel(font, atlas.findRegion("disabled"), atlas, 10f); stats = new Statistics(font, atlas.findRegion("disabled"), atlas, 10f); engagement = new Engagement(font, atlas.findRegion("disabled"), atlas, 10f); - dialogs = new Widget[] { okCancel, stats, engagement}; - dialogAction = DialogAction.NONE; } @Override @@ -135,14 +123,13 @@ public class Hud implements Disposable { hit = null; - for (Widget w : dialogs) { - if (w.visible) { - if (w.hit(x, y)) { - hit = w; - break; - } - return false; + if (dialogs.size() > 0) { + Widget dialog = dialogs.getFirst(); + if (dialog.hit(x, y)) { + hit = dialog; + return true; } + return false; } if (ctrl.isInAnimation()) @@ -163,16 +150,14 @@ public class Hud implements Disposable if (hit == null) return false; - for (Widget w : dialogs) { - if (hit == w) { - if (w.hit(x, y)) + if (dialogs.size() > 0) { + Widget dialog = dialogs.getFirst(); + if (hit == dialog) { + if (dialog.hit(x, y)) closeDialog(); hit = null; - break; } - } - - if (hit != null) { + } else { if (hit == actionButtons) { actionButtons.touchUp(x, y); } @@ -188,9 +173,26 @@ public class Hud implements Disposable private void closeDialog() { + Widget dialog = dialogs.removeFirst(); + dialog.visible = false; + + if (dialog == okCancel) + closeOkCancel(); + else if (dialog == stats) + ctrl.endGame(); + // else if (dialog == engagement) + + if (dialogs.size() > 0) + dialogs.getFirst().visible = true; + else + ctrl.blockMap = false; + } + + private void closeOkCancel() + { boolean ok = okCancel.ok; - switch(dialogAction) - { + + switch(okCancel.action) { case EXIT_BOARD: ctrl.exitBoard(ok); break; @@ -206,73 +208,56 @@ public class Hud implements Disposable if (ok) ctrl.endDeployment(); break; - case END_GAME: - stats.visible = false; - ctrl.endGame(); - break; - case END_ENGAGEMENT: - engagement.visible = false; - break; - case NONE: - default: - break; } - okCancel.visible = false; - ctrl.blockMap = false; - dialogAction = DialogAction.NONE; } - public boolean dialogOn() + public boolean dialogActive() { - return (dialogAction != DialogAction.NONE); + return (dialogs.size() > 0); } - private void setDialogAction(DialogAction action) + private void pushDialog(Widget dialog) { - if (dialogAction != DialogAction.NONE) - System.err.println(":::: BUG :::: dialogAction is already set to " + dialogAction); - dialogAction = action; + ctrl.blockMap = true; + if (dialogs.size() != 0) + dialog.visible = false; + dialogs.addLast(dialog); } public void notifyEndOfTurn() { - ctrl.blockMap = true; - setDialogAction(DialogAction.END_TURN); - okCancel.show("You have no more Action Points left.", Position.MIDDLE_CENTER, false); + okCancel.show("You have no more Action Points left.", OkCancel.Action.END_TURN); + okCancel.noCancel(); + pushDialog(okCancel); } public void askExitBoard() { - ctrl.blockMap = true; - setDialogAction(DialogAction.EXIT_BOARD); - okCancel.show("Do you want this unit to escape the battle fierd ?", Position.MIDDLE_CENTER); + okCancel.show("Do you want this unit to escape the battle fierd ?", OkCancel.Action.EXIT_BOARD); + pushDialog(okCancel); } public void askEndOfTurn() { - ctrl.blockMap = true; - setDialogAction(DialogAction.ABORT_TURN); - okCancel.show("You still have Action Points left.\nEnd your Turn anyway ?", Position.MIDDLE_CENTER); + okCancel.show("You still have Action Points left.\nEnd your Turn anyway ?", OkCancel.Action.ABORT_TURN); + pushDialog(okCancel); } public void askEndDeployment() { - ctrl.blockMap = true; - setDialogAction(DialogAction.END_DEPLOYMENT); - okCancel.show("Deployment unit count reached.\nEnd Deployment phase ?", Position.MIDDLE_CENTER); + okCancel.show("Deployment unit count reached.\nEnd Deployment phase ?", OkCancel.Action.END_DEPLOYMENT); + pushDialog(okCancel); } public void engagementSummary(int d1, int d2, int cnt, int flk, int def, int tdf, int wdf, String msg) { - ctrl.blockMap = true; - setDialogAction(DialogAction.END_ENGAGEMENT); engagement.show(d1, d2, cnt, flk, def, tdf, wdf, msg, Position.BOTTOM_CENTER); + pushDialog(engagement); } public void victory(Player winner, Player loser) { - ctrl.blockMap = true; - setDialogAction(DialogAction.END_GAME); stats.show(winner, loser, Position.MIDDLE_CENTER); + pushDialog(stats); } } diff --git a/core/src/ch/asynk/tankontank/game/hud/OkCancel.java b/core/src/ch/asynk/tankontank/game/hud/OkCancel.java index 56c3e96..472d066 100644 --- a/core/src/ch/asynk/tankontank/game/hud/OkCancel.java +++ b/core/src/ch/asynk/tankontank/game/hud/OkCancel.java @@ -13,6 +13,15 @@ public class OkCancel extends Bg protected Label label; protected Bg okBtn; protected Bg cancelBtn; + public Action action; + + public enum Action + { + EXIT_BOARD, + ABORT_TURN, + END_TURN, + END_DEPLOYMENT, + } public OkCancel(BitmapFont font, TextureRegion region, TextureAtlas atlas, float padding) { @@ -24,13 +33,15 @@ public class OkCancel extends Bg this.padding = padding; } - public void show(String msg, Position position) + public void show(String msg, Action action) { - show(msg, position, true); + show(msg, action, Position.MIDDLE_CENTER); } - public void show(String msg, Position position, boolean canCancel) + public void show(String msg, Action action, Position position) { + this.action = action; + label.write(msg); float height = (label.getHeight() + (4 * padding) + okBtn.getHeight()); @@ -46,7 +57,11 @@ public class OkCancel extends Bg label.setPosition((x + padding), (y + okBtn.getHeight() + (2 * padding))); visible = true; ok = false; - cancelBtn.visible = canCancel; + } + + public void noCancel() + { + cancelBtn.visible = false; } public boolean hit(float x, float y) diff --git a/core/src/ch/asynk/tankontank/game/states/StateAnimation.java b/core/src/ch/asynk/tankontank/game/states/StateAnimation.java index 6738beb..86bf61c 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateAnimation.java +++ b/core/src/ch/asynk/tankontank/game/states/StateAnimation.java @@ -5,14 +5,12 @@ public class StateAnimation extends StateCommon @Override public void enter(StateType prevState) { - ctrl.blockMap = true; ctrl.hud.actionButtons.hide(); } @Override public void leave(StateType nextState) { - ctrl.blockMap = false; } @Override |