summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-02-22 01:02:00 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-02-22 01:02:00 +0100
commitafa1299370ae0ba2d058bc3f6b35fce5b8514dbc (patch)
tree18e0b4cb6f499d67f975b4221ab0382b70758826
parentf3181eaa423fa9fc2b30e7d66726ccdf9e84d3c7 (diff)
downloadRustAndDust-afa1299370ae0ba2d058bc3f6b35fce5b8514dbc.zip
RustAndDust-afa1299370ae0ba2d058bc3f6b35fce5b8514dbc.tar.gz
MenuCtrl: support OkCancel from menus
-rw-r--r--core/src/ch/asynk/rustanddust/menu/MainMenu.java6
-rw-r--r--core/src/ch/asynk/rustanddust/menu/MenuCtrl.java27
-rw-r--r--core/src/ch/asynk/rustanddust/menu/OptionsMenu.java6
-rw-r--r--core/src/ch/asynk/rustanddust/menu/PlayMenu.java28
-rw-r--r--core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java6
5 files changed, 57 insertions, 16 deletions
diff --git a/core/src/ch/asynk/rustanddust/menu/MainMenu.java b/core/src/ch/asynk/rustanddust/menu/MainMenu.java
index 19567ce..6023ce8 100644
--- a/core/src/ch/asynk/rustanddust/menu/MainMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/MainMenu.java
@@ -83,6 +83,12 @@ public class MainMenu extends Patch implements MenuCtrl.Panel
}
@Override
+ public void postAnswer(boolean ok) { }
+
+ @Override
+ public String getAsk() { return null; }
+
+ @Override
public MenuCtrl.MenuType prepare() { return MenuCtrl.MenuType.MAIN; }
@Override
diff --git a/core/src/ch/asynk/rustanddust/menu/MenuCtrl.java b/core/src/ch/asynk/rustanddust/menu/MenuCtrl.java
index 56015fd..960ada3 100644
--- a/core/src/ch/asynk/rustanddust/menu/MenuCtrl.java
+++ b/core/src/ch/asynk/rustanddust/menu/MenuCtrl.java
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.engine.gfx.Drawable;
+import ch.asynk.rustanddust.ui.OkCancel;
public class MenuCtrl implements Disposable, Drawable
{
@@ -17,6 +18,8 @@ public class MenuCtrl implements Disposable, Drawable
TUTORIALS(2),
PLAY(3),
NONE(4),
+ OK(64),
+ OKKO(65),
BEGIN(66),
EXIT(666);
public int i;
@@ -28,11 +31,14 @@ public class MenuCtrl implements Disposable, Drawable
public MenuType prepare();
public void computePosition();
public MenuType touch(float x, float y);
+ public String getAsk();
+ public void postAnswer(boolean ok);
}
public boolean visible;
private Panel []panels;
private MenuType current;
+ private OkCancel okCancel;
public MenuCtrl(final RustAndDust game)
{
@@ -41,14 +47,23 @@ public class MenuCtrl implements Disposable, Drawable
this.panels[MenuType.OPTIONS.i] = new OptionsMenu(game);
this.panels[MenuType.TUTORIALS.i] = new TutorialsMenu(game);
this.panels[MenuType.PLAY.i] = new PlayMenu(game);
+ this.okCancel = new OkCancel(game.font, game.bgPatch, game.getUiRegion(game.UI_OK), game.getUiRegion(game.UI_CANCEL));
this.current = MenuType.MAIN;
+ this.okCancel.visible = false;
this.visible = true;
}
public boolean touch(float x, float y)
{
+ if (okCancel.hit(x, y)) {
+ visible = true;
+ okCancel.visible = false;
+ panels[current.i].postAnswer(okCancel.ok);
+ return false;
+ }
+
MenuType next = panels[current.i].touch(x, y);
if (next == MenuType.BEGIN) return true;
@@ -59,6 +74,15 @@ public class MenuCtrl implements Disposable, Drawable
return false;
}
+ if ((next == MenuType.OK) || (next == MenuType.OKKO)) {
+ okCancel.visible = true;
+ okCancel.show(panels[current.i].getAsk());
+ if (next == MenuType.OK)
+ okCancel.noCancel();
+ visible = false;
+ return false;
+ }
+
if (next != MenuType.NONE) {
while(current != next) {
current = next;
@@ -80,11 +104,13 @@ public class MenuCtrl implements Disposable, Drawable
{
for (int i = 0; i < MenuType.NONE.i; i++)
panels[i].dispose();
+ okCancel.dispose();
}
@Override
public void draw(Batch batch)
{
+ okCancel.draw(batch);
if (visible)
panels[current.i].draw(batch);
}
@@ -92,6 +118,7 @@ public class MenuCtrl implements Disposable, Drawable
@Override
public void drawDebug(ShapeRenderer debugShapes)
{
+ okCancel.drawDebug(debugShapes);
if (visible)
panels[current.i].drawDebug(debugShapes);
}
diff --git a/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java b/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java
index 04796a2..146d38b 100644
--- a/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java
@@ -149,6 +149,12 @@ public class OptionsMenu extends Patch implements MenuCtrl.Panel
}
@Override
+ public void postAnswer(boolean ok) { }
+
+ @Override
+ public String getAsk() { return null; }
+
+ @Override
public MenuCtrl.MenuType prepare() { return MenuCtrl.MenuType.OPTIONS; }
@Override
diff --git a/core/src/ch/asynk/rustanddust/menu/PlayMenu.java b/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
index 0ed7f95..1bac295 100644
--- a/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
@@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import ch.asynk.rustanddust.ui.Label;
import ch.asynk.rustanddust.ui.Bg;
-import ch.asynk.rustanddust.ui.OkCancel;
import ch.asynk.rustanddust.ui.Patch;
import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.game.hud.ObjectivesPanel;
@@ -28,7 +27,6 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
private ObjectivesPanel objectivesPanel;
protected Bg okBtn;
protected Bg cancelBtn;
- private OkCancel okCancel;
public PlayMenu(RustAndDust game)
{
@@ -47,7 +45,6 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
this.objectives = new Label(game.font);
this.objectives.write("Battle Objectives");
this.objectivesPanel = new ObjectivesPanel(game);
- this.okCancel = new OkCancel(game.font, game.bgPatch, game.getUiRegion(game.UI_OK), game.getUiRegion(game.UI_CANCEL));
if (game.config.battle == null) {
battleIdx = 0;
@@ -75,6 +72,15 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
}
@Override
+ public void postAnswer(boolean ok) { }
+
+ @Override
+ public String getAsk()
+ {
+ return String.format("'%s' Game Mode not implemented yet.", game.config.gameMode.s);
+ }
+
+ @Override
public void computePosition()
{
float h = (title.getHeight() + TITLE_PADDING + (2 * PADDING));
@@ -111,11 +117,7 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
@Override
public MenuCtrl.MenuType touch(float x, float y)
{
- if (okCancel.hit(x, y)) {
- this.visible = true;
- okCancel.visible = false;
- return MenuCtrl.MenuType.NONE;
- } else if (objectivesPanel.hit(x, y)) {
+ if (objectivesPanel.hit(x, y)) {
this.visible = true;
objectivesPanel.visible = false;
return MenuCtrl.MenuType.NONE;
@@ -140,12 +142,8 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
}
private MenuCtrl.MenuType apply() {
- if (!game.config.gameModeImplemented()) {
- this.visible = false;
- okCancel.show(String.format("'%s' Game Mode not implemented yet.", game.config.gameMode.s));
- okCancel.noCancel();
- return MenuCtrl.MenuType.NONE;
- }
+ if (!game.config.gameModeImplemented())
+ return MenuCtrl.MenuType.OK;
return MenuCtrl.MenuType.BEGIN;
}
@@ -187,13 +185,11 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
battleValue.dispose();
okBtn.dispose();
cancelBtn.dispose();
- okCancel.dispose();
}
@Override
public void draw(Batch batch)
{
- okCancel.draw(batch);
objectivesPanel.draw(batch);
if (!visible) return;
diff --git a/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java b/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java
index 5a8d03f..3224e29 100644
--- a/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java
@@ -25,6 +25,12 @@ public class TutorialsMenu extends Patch implements MenuCtrl.Panel
}
@Override
+ public void postAnswer(boolean ok) { }
+
+ @Override
+ public String getAsk() { return null; }
+
+ @Override
public MenuCtrl.MenuType prepare() { return MenuCtrl.MenuType.TUTORIALS; }
@Override