summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/menu
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-07-19 13:20:33 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2015-07-19 13:20:33 +0200
commitde0463bcf0f76ef8b07f2719679c9e0d72745c5d (patch)
tree9a33df947ceeea16a3e20b400585b1d3c304e77e /core/src/ch/asynk/rustanddust/menu
parente66f9f2a61d3dab4545e996046486de0d44e2901 (diff)
downloadRustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.zip
RustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.tar.gz
welcome RustAndDust
Diffstat (limited to 'core/src/ch/asynk/rustanddust/menu')
-rw-r--r--core/src/ch/asynk/rustanddust/menu/MainMenu.java67
-rw-r--r--core/src/ch/asynk/rustanddust/menu/OptionsMenu.java257
-rw-r--r--core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java141
-rw-r--r--core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java94
4 files changed, 559 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/menu/MainMenu.java b/core/src/ch/asynk/rustanddust/menu/MainMenu.java
new file mode 100644
index 0000000..769adb3
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/menu/MainMenu.java
@@ -0,0 +1,67 @@
+package ch.asynk.rustanddust.menu;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+
+import ch.asynk.rustanddust.ui.Menu;
+
+public class MainMenu extends Menu
+{
+ public enum Items implements Menu.MenuItem
+ {
+ EXIT(0),
+ OPTIONS(1),
+ TUTORIALS(2),
+ SCENARIOS(3),
+ NONE(4);
+ public int i;
+ Items(int i)
+ {
+ this.i = i;
+ }
+ public int i() { return i; }
+ public int last() { return NONE.i; }
+ };
+
+ public MainMenu(BitmapFont font, TextureAtlas atlas)
+ {
+ super(Items.NONE, font, atlas.createPatch("typewriter"));
+
+ label(Items.OPTIONS).write("Options");
+ label(Items.TUTORIALS).write("Tutorials");
+ label(Items.SCENARIOS).write("Scenarios");
+ label(Items.EXIT).write("Exit");
+
+ this.visible = true;
+ }
+
+ public Items getMenu()
+ {
+ return (Items) menuItem;
+ }
+
+ @Override
+ public boolean hit(float x, float y)
+ {
+ boolean ret = false;
+ menuItem = Items.NONE;
+
+ if (!visible) return ret;
+
+ if (label(Items.SCENARIOS).hit(x, y)) {
+ menuItem = Items.SCENARIOS;
+ ret = true;
+ } else if (label(Items.TUTORIALS).hit(x, y)) {
+ menuItem = Items.TUTORIALS;
+ ret = true;
+ } else if (label(Items.OPTIONS).hit(x, y)) {
+ menuItem = Items.OPTIONS;
+ ret = true;
+ } else if (label(Items.EXIT).hit(x, y)) {
+ Gdx.app.exit();
+ }
+
+ return ret;
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java b/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java
new file mode 100644
index 0000000..9a7c675
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/menu/OptionsMenu.java
@@ -0,0 +1,257 @@
+package ch.asynk.rustanddust.menu;
+
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.GlyphLayout;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+
+import ch.asynk.rustanddust.ui.Label;
+import ch.asynk.rustanddust.ui.Bg;
+import ch.asynk.rustanddust.ui.Patch;
+import ch.asynk.rustanddust.ui.OkCancel;
+
+import ch.asynk.rustanddust.RustAndDust;
+
+public class OptionsMenu extends Patch
+{
+ public static int PADDING = 40;
+ public static int OK_PADDING = 10;
+ public static int TITLE_PADDING = 30;
+ public static int VSPACING = 5;
+ public static int HSPACING = 30;
+ public static String CHECK = "#";
+
+ private final RustAndDust game;
+ private final BitmapFont font;
+
+ private String [] checkStrings = {
+ "Debug",
+ "Must Validate",
+ "Can Cancel",
+ "Show Enemy Possibilities",
+ "Show Moves Assists",
+ "Show Targets",
+ "Show Moves",
+ };
+ private String [] fxStrings = { "OFF", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "ON" };
+
+ private float checkDy;
+ private Label title;
+ private Label fxVolume;
+ private Label fxVolumeValue;
+ private Label graphics;
+ private Label graphicsValue;
+ private Label gameMode;
+ private Label gameModeValue;
+ private Label [] checkLabels;
+ private boolean [] checkValues;
+ private OkCancel okCancel;
+ protected Bg okBtn;
+
+ public OptionsMenu(RustAndDust game, BitmapFont font, TextureAtlas atlas)
+ {
+ super(atlas.createPatch("typewriter"));
+ this.game = game;
+ this.font = font;
+ this.okCancel = new OkCancel(font, atlas);
+ this.okBtn = new Bg(atlas.findRegion("ok"));
+ this.title = new Label(font);
+ this.title.write("- Options");
+ this.fxVolume = new Label(font);
+ this.fxVolume.write("Fx Volume");
+ this.fxVolumeValue = new Label(font);
+ this.fxVolumeValue.write(fxStrings[(int) (game.config.fxVolume * 10)]);
+ this.graphics = new Label(font);
+ this.graphics.write("Graphics");
+ this.graphicsValue = new Label(font);
+ this.graphicsValue.write(game.config.graphics.s);
+ this.gameMode = new Label(font);
+ this.gameMode.write("Game mode");
+ this.gameModeValue = new Label(font);
+ this.gameModeValue.write(game.config.gameMode.s);
+ this.checkValues = new boolean[checkStrings.length];
+ this.checkLabels = new Label[checkStrings.length];
+ for (int i = 0; i < checkLabels.length; i++) {
+ Label l = new Label(font, 5f);
+ l.write(checkStrings[i]);
+ this.checkLabels[i] = l;
+ }
+ getValues();
+ GlyphLayout layout = new GlyphLayout();
+ layout.setText(font, CHECK);
+ checkDy = layout.height + 5;
+
+ this.visible = false;
+ }
+
+ private void getValues()
+ {
+ checkValues[6] = game.config.showMoves;
+ checkValues[5] = game.config.showTargets;
+ checkValues[4] = game.config.showMoveAssists;
+ checkValues[3] = game.config.showEnemyPossibilities;
+ checkValues[2] = game.config.canCancel;
+ checkValues[1] = game.config.mustValidate;
+ checkValues[0] = game.config.debug;
+ }
+
+ private boolean apply()
+ {
+ game.config.showMoves = checkValues[6];
+ game.config.showTargets = checkValues[5];
+ game.config.showMoveAssists = checkValues[4];
+ game.config.showEnemyPossibilities = checkValues[3];
+ game.config.canCancel = checkValues[2];
+ game.config.mustValidate = checkValues[1];
+ game.config.debug = checkValues[0];
+ if (!game.config.gameModeImplemented()) {
+ this.visible = false;
+ okCancel.show(String.format("'%s' Game Mode not implemented yet.", game.config.gameMode.s));
+ okCancel.noCancel();
+ return false;
+ }
+ return true;
+ }
+
+ private void cycleFxVolume()
+ {
+ int i = (int) (game.config.fxVolume * 10) + 1;
+ if (i > 10) i = 0;
+ float fx = fxVolumeValue.getX();
+ float fy = fxVolumeValue.getY();
+ fxVolumeValue.write(fxStrings[i]);
+ fxVolumeValue.setPosition(fx, fy);
+ game.config.fxVolume = (i / 10f);
+ }
+
+ private void cycleGraphics()
+ {
+ game.config.graphics = game.config.graphics.next();
+ float fx = graphicsValue.getX();
+ float fy = graphicsValue.getY();
+ graphicsValue.write(game.config.graphics.s);
+ graphicsValue.setPosition(fx, fy);
+ }
+
+ private void cycleGameMode()
+ {
+ game.config.gameMode = game.config.gameMode.next();
+ float fx = gameModeValue.getX();
+ float fy = gameModeValue.getY();
+ gameModeValue.write(game.config.gameMode.s);
+ gameModeValue.setPosition(fx, fy);
+ }
+
+ public void setPosition()
+ {
+ float h = (title.getHeight() + TITLE_PADDING + ((checkLabels.length - 1) * VSPACING) + (2 * PADDING));
+ for (int i = 0; i < checkLabels.length; i++)
+ h += checkLabels[i].getHeight();
+ h += (graphics.getHeight() + VSPACING);
+ h += (gameMode.getHeight() + VSPACING);
+ h += (fxVolume.getHeight() + VSPACING);
+
+ float w = title.getWidth();
+ for (int i = 0; i < checkLabels.length; i++) {
+ float t = checkLabels[i].getWidth();
+ if (t > w)
+ w = t;
+ }
+ w += (2 * PADDING) + HSPACING;
+
+ float x = position.getX(w);
+ float y = position.getY(h);
+ setPosition(x, y, w, h);
+
+ okBtn.setPosition((x + w - okBtn.getWidth() + OK_PADDING), (y - OK_PADDING));
+
+ y += PADDING;
+ x += PADDING + HSPACING;
+ float dy = (VSPACING + checkLabels[0].getHeight());
+
+ graphics.setPosition(x, y);
+ graphicsValue.setPosition((x + graphics.getWidth() + 10), y);
+ y += dy;
+ gameMode.setPosition(x, y);
+ gameModeValue.setPosition((x + gameMode.getWidth() + 10), y);
+ y += dy;
+ fxVolume.setPosition(x, y);
+ fxVolumeValue.setPosition((x + fxVolume.getWidth() + 10), y);
+ y += dy;
+ for (int i = 0; i < checkLabels.length; i++) {
+ checkLabels[i].setPosition(x, y);
+ y += dy;
+ }
+ y += (TITLE_PADDING - VSPACING);
+ title.setPosition(x, y);
+ }
+
+ @Override
+ public boolean hit(float x, float y)
+ {
+ if (okCancel.hit(x, y)) {
+ this.visible = true;
+ okCancel.visible = false;
+ return false;
+ }
+
+ if (!visible) return false;
+
+ if (okBtn.hit(x, y)) {
+ return apply();
+ } else if (fxVolume.hit(x, y) || fxVolumeValue.hit(x, y)) {
+ cycleFxVolume();
+ } else if (graphics.hit(x, y) || graphicsValue.hit(x, y)) {
+ cycleGraphics();
+ } else if (gameMode.hit(x, y) || gameModeValue.hit(x, y)) {
+ cycleGameMode();
+ } else {
+ for (int i = 0; i < checkLabels.length; i++) {
+ if (checkLabels[i].hit(x, y))
+ checkValues[i] =! checkValues[i];
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ title.dispose();
+ okBtn.dispose();
+ okCancel.dispose();
+ fxVolume.dispose();
+ fxVolumeValue.dispose();
+ graphics.dispose();
+ graphicsValue.dispose();
+ gameMode.dispose();
+ gameModeValue.dispose();
+ for (int i = 0; i < checkLabels.length; i++)
+ checkLabels[i].dispose();
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ okCancel.draw(batch);
+
+ if (!visible) return;
+ super.draw(batch);
+ title.draw(batch);
+ okBtn.draw(batch);
+ fxVolume.draw(batch);
+ fxVolumeValue.draw(batch);
+ graphics.draw(batch);
+ graphicsValue.draw(batch);
+ gameMode.draw(batch);
+ gameModeValue.draw(batch);
+ for (int i = 0; i < checkLabels.length; i++) {
+ Label l = checkLabels[i];
+ l.draw(batch);
+ if (checkValues[i])
+ font.draw(batch, CHECK, (l.getX() - HSPACING) , l.getY() + checkDy);
+ }
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java b/core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java
new file mode 100644
index 0000000..d5b99ed
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/menu/ScenariosMenu.java
@@ -0,0 +1,141 @@
+package ch.asynk.rustanddust.menu;
+
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.GlyphLayout;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+
+import ch.asynk.rustanddust.ui.Label;
+import ch.asynk.rustanddust.ui.Bg;
+import ch.asynk.rustanddust.ui.Patch;
+import ch.asynk.rustanddust.RustAndDust;
+import ch.asynk.rustanddust.game.Battle;
+
+public class ScenariosMenu extends Patch
+{
+ public static int PADDING = 40;
+ public static int BTN_PADDING = 10;
+ public static int TITLE_PADDING = 30;
+ public static int VSPACING = 5;
+ public static int HSPACING = 30;
+ public static String CHECK = "#";
+
+ private final RustAndDust game;
+ private final BitmapFont font;
+
+ private float checkDy;
+ private Label title;
+ protected Bg okBtn;
+ protected Bg cancelBtn;
+ private Label [] battleLabels;
+
+ public boolean launch;
+
+ public ScenariosMenu(RustAndDust game, BitmapFont font, TextureAtlas atlas)
+ {
+ super(atlas.createPatch("typewriter"));
+ this.game = game;
+ this.font = font;
+ this.okBtn = new Bg(atlas.findRegion("ok"));
+ this.cancelBtn = new Bg(atlas.findRegion("cancel"));
+ this.title = new Label(font);
+ this.title.write("- Scenarios");
+ this.battleLabels = new Label[game.factory.battles.length];
+ for (int i = 0; i < battleLabels.length; i++) {
+ Label l = new Label(font, 8f);
+ l.write(game.factory.battles[i].getName());
+ battleLabels[i] = l;
+ }
+ GlyphLayout layout = new GlyphLayout();
+ layout.setText(font, CHECK);
+ checkDy = layout.height + 9;
+
+ this.visible = false;
+ this.launch = false;
+ }
+
+ public void setPosition()
+ {
+ float h = (title.getHeight() + TITLE_PADDING + ((battleLabels.length - 1) * VSPACING) + (2 * PADDING));
+ for (int i = 0; i < battleLabels.length; i++)
+ h += battleLabels[i].getHeight();
+
+ float w = title.getWidth();
+ for (int i = 0; i < battleLabels.length; i++) {
+ float t = battleLabels[i].getWidth();
+ if (t > w)
+ w = t;
+ }
+ w += (2 * PADDING) + HSPACING;
+
+ float x = position.getX(w);
+ float y = position.getY(h);
+ setPosition(x, y, w, h);
+
+ okBtn.setPosition((x + w - okBtn.getWidth() + BTN_PADDING), (y - BTN_PADDING));
+ cancelBtn.setPosition((x - BTN_PADDING), okBtn.getY());
+
+ y += PADDING;
+ x += PADDING + HSPACING;
+ float dy = (VSPACING + battleLabels[0].getHeight());
+
+ for (int i = (battleLabels.length - 1); i > -1; i--) {
+ battleLabels[i].setPosition(x, y);
+ y += dy;
+ }
+ y += (TITLE_PADDING - VSPACING);
+ title.setPosition(x, y);
+ }
+
+ @Override
+ public boolean hit(float x, float y)
+ {
+ if (!visible) return false;
+
+ if (okBtn.hit(x, y)) {
+ this.launch = (game.config.battle != null);
+ return true;
+ } else if (cancelBtn.hit(x, y)) {
+ this.launch = false;
+ return true;
+ } else {
+ for (int i = 0; i <battleLabels.length; i++) {
+ if (battleLabels[i].hit(x, y)) {
+ if (game.config.battle == game.factory.battles[i])
+ game.config.battle = null;
+ else
+ game.config.battle = game.factory.battles[i];
+ }
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ title.dispose();
+ okBtn.dispose();
+ cancelBtn.dispose();
+ for (int i = 0; i < battleLabels.length; i++)
+ battleLabels[i].dispose();
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ if (!visible) return;
+ super.draw(batch);
+ title.draw(batch);
+ okBtn.draw(batch);
+ cancelBtn.draw(batch);
+ for (int i = 0; i < battleLabels.length; i++) {
+ Label l = battleLabels[i];
+ l.draw(batch);
+ if (game.config.battle == game.factory.battles[i])
+ font.draw(batch, CHECK, (l.getX() - HSPACING) , l.getY() + checkDy);
+ }
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java b/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java
new file mode 100644
index 0000000..7f54aad
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/menu/TutorialsMenu.java
@@ -0,0 +1,94 @@
+package ch.asynk.rustanddust.menu;
+
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+
+import ch.asynk.rustanddust.ui.Label;
+import ch.asynk.rustanddust.ui.Bg;
+import ch.asynk.rustanddust.ui.Patch;
+import ch.asynk.rustanddust.RustAndDust;
+
+public class TutorialsMenu extends Patch
+{
+ public static int PADDING = 40;
+ public static int OK_PADDING = 10;
+ public static int TITLE_PADDING = 30;
+ public static int VSPACING = 20;
+
+ private final RustAndDust game;
+ private final BitmapFont font;
+
+ private Label title;
+ private Label msg;
+ protected Bg okBtn;
+
+ public TutorialsMenu(RustAndDust game, BitmapFont font, TextureAtlas atlas)
+ {
+ super(atlas.createPatch("typewriter"));
+ this.game = game;
+ this.font = font;
+ this.okBtn = new Bg(atlas.findRegion("ok"));
+ this.title = new Label(font);
+ this.title.write("- Tutorials");
+ this.msg = new Label(font);
+ this.msg.write("Not implemented yet.");
+
+ this.visible = false;
+ }
+
+ public void setPosition()
+ {
+ float h = (title.getHeight() + TITLE_PADDING + (2 * PADDING));
+ h += msg.getHeight();
+
+ float w = title.getWidth();
+ if (msg.getWidth() > w)
+ w = msg.getWidth();
+ w += (2 * PADDING);
+
+ float x = position.getX(w);
+ float y = position.getY(h);
+ setPosition(x, y, w, h);
+
+ okBtn.setPosition((x + w - okBtn.getWidth() + OK_PADDING), (y - OK_PADDING));
+
+ y += PADDING;
+ x += PADDING;
+
+ msg.setPosition(x, y);
+
+ y += (msg.getHeight() + TITLE_PADDING);
+ title.setPosition(x, y);
+ }
+
+ @Override
+ public boolean hit(float x, float y)
+ {
+ if (!visible) return false;
+
+ if (okBtn.hit(x, y))
+ return true;
+
+ return false;
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ title.dispose();
+ msg.dispose();
+ okBtn.dispose();
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ if (!visible) return;
+ super.draw(batch);
+ title.draw(batch);
+ msg.draw(batch);
+ okBtn.draw(batch);
+ }
+}