summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-05-10 14:16:39 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-05-10 14:16:39 +0200
commita9feaf4eab16f38b3f8a8d8e511fd924b4e0fc8f (patch)
treeff0129e55665badbc09edba04bf03a2fadb268e0 /core/src/ch
parenta9adb5d0f27ac64b09d4df660137abac8d6572c9 (diff)
downloadRustAndDust-a9feaf4eab16f38b3f8a8d8e511fd924b4e0fc8f.zip
RustAndDust-a9feaf4eab16f38b3f8a8d8e511fd924b4e0fc8f.tar.gz
add menu/ResumeMenu
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/rustanddust/menu/ResumeMenu.java140
1 files changed, 140 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/menu/ResumeMenu.java b/core/src/ch/asynk/rustanddust/menu/ResumeMenu.java
new file mode 100644
index 0000000..70ff025
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/menu/ResumeMenu.java
@@ -0,0 +1,140 @@
+package ch.asynk.rustanddust.menu;
+
+import com.badlogic.gdx.graphics.g2d.Batch;
+
+import ch.asynk.rustanddust.ui.Label;
+import ch.asynk.rustanddust.ui.Patch;
+import ch.asynk.rustanddust.RustAndDust;
+import ch.asynk.rustanddust.game.Config;
+
+public class ResumeMenu extends Patch implements MenuCtrl.Panel
+{
+ private static final int PADDING = 40;
+ private static final int VSPACING = 8;
+ private static final int TITLE_SPACING = 12;
+
+ enum Item
+ {
+ RESUME(3, " * Resume", MenuCtrl.MenuType.NONE),
+ REPLAY_LAST(2, " * Replay Last Actions", MenuCtrl.MenuType.NONE),
+ REPLAY_BATTLE(1, " * Replay Battle", MenuCtrl.MenuType.NONE),
+ CANCEL(0, " * Cancel", MenuCtrl.MenuType.PLAY),
+ NONE(4, null, MenuCtrl.MenuType.NONE);
+
+ public int i;
+ public String s;
+ public MenuCtrl.MenuType t;
+ Item(int i, String s, MenuCtrl.MenuType t)
+ {
+ this.i = i;
+ this.s = s;
+ this.t = t;
+ }
+ };
+
+ protected Label title;
+ protected Label []labels;
+ private final RustAndDust game;
+
+ public ResumeMenu(RustAndDust game)
+ {
+ super(game.bgPatch);
+ this.game = game;
+ this.title = new Label(game.font, 10);
+ this.title.write("- Play");
+ this.labels = new Label[Item.NONE.i];
+ for (int i = 0; i < Item.NONE.i; i++)
+ labels[i] = new Label(game.font, 10);
+ labels[Item.RESUME.i].write(Item.RESUME.s);
+ labels[Item.REPLAY_LAST.i].write(Item.REPLAY_LAST.s);
+ labels[Item.REPLAY_BATTLE.i].write(Item.REPLAY_BATTLE.s);
+ labels[Item.CANCEL.i].write(Item.CANCEL.s);
+ }
+
+ @Override
+ public void computePosition()
+ {
+ float h = 0f;
+ float w = 0f;
+ for (int i = 0; i< Item.NONE.i; i ++) {
+ h += labels[i].getHeight();
+ float t = labels[i].getWidth();
+ if (t > w)
+ w = t;
+ }
+ h += (2 * PADDING) + ((Item.NONE.i - 1) * VSPACING);
+ w += (2 * PADDING);
+ h += title.getHeight() + TITLE_SPACING;
+
+ float x = position.getX(w);
+ float y = position.getY(h);
+ setPosition(x, y, w, h);
+
+ y += PADDING;
+ x += PADDING;
+
+ for (int i = 0; i< Item.NONE.i; i ++) {
+ labels[i].setPosition(x, y);
+ y += (VSPACING + labels[i].getHeight());
+ }
+ y+= TITLE_SPACING;
+ title.setPosition(x, y);
+ }
+
+ @Override
+ public MenuCtrl.MenuType postAnswer(boolean ok) { return MenuCtrl.MenuType.NONE; }
+
+ @Override
+ public String getAsk() { return null; }
+
+ @Override
+ public MenuCtrl.MenuType prepare() { return MenuCtrl.MenuType.RESUME; }
+
+ @Override
+ public boolean drag(float x, float y, int dx, int dy) { return true; }
+
+ @Override
+ public MenuCtrl.MenuType touch(float x, float y)
+ {
+ int idx = -1;
+
+ if (labels[Item.CANCEL.i].hit(x, y)) {
+ game.playType();
+ return Item.CANCEL.t;
+ }
+ else if (labels[Item.RESUME.i].hit(x, y))
+ return setConfig(Config.LoadMode.RESUME);
+ else if (labels[Item.REPLAY_LAST.i].hit(x, y))
+ return setConfig(Config.LoadMode.REPLAY_LAST);
+ else if (labels[Item.REPLAY_BATTLE.i].hit(x, y))
+ return setConfig(Config.LoadMode.REPLAY_BATTLE);
+
+ return MenuCtrl.MenuType.NONE;
+ }
+
+ private MenuCtrl.MenuType setConfig(Config.LoadMode loadMode)
+ {
+ game.playType();
+ game.config.loadMode = loadMode;
+ return MenuCtrl.MenuType.BEGIN;
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ title.dispose();
+ for (int i = 0; i < Item.NONE.i; i ++)
+ labels[i].dispose();
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ if (!visible) return;
+ super.draw(batch);
+ title.draw(batch);
+ for (int i = 0; i < Item.NONE.i; i ++)
+ labels[i].draw(batch);
+ }
+}