summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/rustanddust/game/Ctrl.java66
-rw-r--r--core/src/ch/asynk/rustanddust/game/Hud.java44
2 files changed, 49 insertions, 61 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Ctrl.java b/core/src/ch/asynk/rustanddust/game/Ctrl.java
index 7a5b140..29c674c 100644
--- a/core/src/ch/asynk/rustanddust/game/Ctrl.java
+++ b/core/src/ch/asynk/rustanddust/game/Ctrl.java
@@ -33,11 +33,12 @@ class Event
public enum Type
{
STATE_CHANGE,
- TURN_END;
+ HUD_ANSWER;
}
public Type type;
public Object data;
+ public boolean status;
}
public abstract class Ctrl implements Disposable
@@ -177,6 +178,17 @@ public abstract class Ctrl implements Disposable
events.enqueue(evt);
}
+ public void postAnswer(Hud.OkCancelAction what, boolean status)
+ {
+ Event evt = freeEvents.pop();
+ if (evt == null)
+ evt = new Event();
+ evt.type = Event.Type.HUD_ANSWER;
+ evt.data = what;
+ evt.status = status;
+ events.enqueue(evt);
+ }
+
public void processEvent()
{
if (events.size() <= 0)
@@ -187,8 +199,11 @@ public abstract class Ctrl implements Disposable
case STATE_CHANGE:
setState((StateType) evt.data);
break;
+ case HUD_ANSWER:
+ handleHudAnswer(evt);
+ break;
default:
- RustAndDust.error(String.format("Unhandled Event Type : %s", evt.type));
+ RustAndDust.error(String.format("Unhandled Event Type : %s %s", evt.type, evt.data));
}
freeEvents.push(evt);
}
@@ -263,9 +278,31 @@ public abstract class Ctrl implements Disposable
// Hud callbacks
- public void endGame()
+ private void handleHudAnswer(Event evt)
{
- game.switchToMenu();
+ switch((Hud.OkCancelAction) evt.data) {
+ case EXIT_BOARD:
+ if (evt.status) setState(StateType.DONE);
+ else setState(StateType.ABORT);
+ break;
+ case ABORT_TURN:
+ if (evt.status) {
+ this.state.abort();
+ turnDone();
+ }
+ break;
+ case END_DEPLOYMENT:
+ if (evt.status) {
+ this.state.execute();
+ turnDone();
+ }
+ break;
+ case QUIT_BATTLE:
+ if (evt.status)
+ game.switchToMenu();
+ break;
+
+ }
}
public void showEntryZone()
@@ -274,27 +311,6 @@ public abstract class Ctrl implements Disposable
state.touch(null);
}
- public void endDeployment()
- {
- this.state.execute();
- turnDone();
- }
-
- public void endPlayerTurn(boolean abort)
- {
- if (abort)
- state.abort();
- turnDone();
- }
-
- public void exitBoard(boolean doit)
- {
- if (doit)
- setState(StateType.DONE);
- else
- setState(StateType.ABORT);
- }
-
public void reinforcementHit()
{
if (this.stateType == StateType.SELECT)
diff --git a/core/src/ch/asynk/rustanddust/game/Hud.java b/core/src/ch/asynk/rustanddust/game/Hud.java
index aac5edb..ec58233 100644
--- a/core/src/ch/asynk/rustanddust/game/Hud.java
+++ b/core/src/ch/asynk/rustanddust/game/Hud.java
@@ -217,50 +217,22 @@ public class Hud implements Disposable, Animation
Widget dialog = dialogs.pop();
dialog.visible = false;
- if (dialog == okCancel)
- closeOkCancel();
- else
+ if (dialog == okCancel) {
+ if (okCancel.ok) game.playEnter();
+ else game.playType();
+ ctrl.postAnswer(okCancelAction, okCancel.ok);
+ } else if (dialog == stats) {
+ game.playEnter();
+ ctrl.postAnswer(OkCancelAction.QUIT_BATTLE, true);
+ } else
game.playType();
- if (dialog == stats)
- ctrl.endGame();
-
if (dialogs.size() > 0)
dialogs.peek().visible = true;
else
ctrl.blockMap = false;
}
- private void closeOkCancel()
- {
- boolean ok = okCancel.ok;
- if (ok)
- game.playEnter();
- else
- game.playType();
-
- switch(okCancelAction) {
- case EXIT_BOARD:
- ctrl.exitBoard(ok);
- break;
- case ABORT_TURN:
- if (ok)
- ctrl.endPlayerTurn(true);
- break;
- case END_DEPLOYMENT:
- if (ok)
- ctrl.endDeployment();
- break;
- case QUIT_BATTLE:
- if (ok) {
- closeDialog();
- ctrl.endGame();
- }
- break;
-
- }
- }
-
public void notifyAnimationsEnd()
{
delay = CLOSE_DELAY;