summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/menu/MainMenu.java114
-rw-r--r--core/src/ch/asynk/tankontank/menu/OptionsMenu.java189
-rw-r--r--core/src/ch/asynk/tankontank/menu/ScenariosMenu.java123
-rw-r--r--core/src/ch/asynk/tankontank/menu/TutorialsMenu.java94
4 files changed, 520 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/menu/MainMenu.java b/core/src/ch/asynk/tankontank/menu/MainMenu.java
new file mode 100644
index 0000000..ed03d08
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/menu/MainMenu.java
@@ -0,0 +1,114 @@
+package ch.asynk.tankontank.menu;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+
+import ch.asynk.tankontank.ui.Label;
+import ch.asynk.tankontank.ui.Patch;
+
+public class MainMenu extends Patch
+{
+ public static int PADDING = 40;
+ public static int VSPACING = 20;
+
+ private Label options;
+ private Label scenarios;
+ private Label tutorial;
+ private Label exit;
+
+ public enum Menu {
+ OPTIONS,
+ TUTORIALS,
+ SCENARIOS,
+ NONE
+ };
+ private Menu menu;
+
+ public MainMenu(BitmapFont font, TextureAtlas atlas)
+ {
+ super(atlas.createPatch("typewriter"));
+ this.options = new Label(font);
+ this.scenarios = new Label(font);
+ this.tutorial = new Label(font);
+ this.exit = new Label(font);
+ this.menu = Menu.NONE;
+
+ options.write("Options");
+ scenarios.write("Scenarios");
+ tutorial.write("Tutorial");
+ exit.write("Quit");
+ }
+
+ public Menu getMenu()
+ {
+ return menu;
+ }
+
+ public void setPosition()
+ {
+ float h = ((4 * tutorial.getHeight()) + (2 * PADDING) + (3 * VSPACING));
+ float w = (scenarios.getWidth() + (2 * PADDING));
+ float x = position.getX(w);
+ float y = position.getY(h);
+ setPosition(x, y, w, h);
+
+ y += PADDING;
+ x += PADDING;
+ float dy = (VSPACING + tutorial.getHeight());
+
+ exit.setPosition(x, y);
+ y += dy;
+ options.setPosition(x, y);
+ y += dy;
+ tutorial.setPosition(x, y);
+ y += dy;
+ scenarios.setPosition(x, y);
+ }
+
+ @Override
+ public boolean hit(float x, float y)
+ {
+ boolean ret = false;
+ menu = Menu.NONE;
+
+ if (!visible) return ret;
+
+ if (scenarios.hit(x, y)) {
+ menu = Menu.SCENARIOS;
+ ret = true;
+ } else if (tutorial.hit(x, y)) {
+ menu = Menu.TUTORIALS;
+ ret = true;
+ } else if (options.hit(x, y)) {
+ menu = Menu.OPTIONS;
+ ret = true;
+ } else if (exit.hit(x, y)) {
+ Gdx.app.exit();
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ scenarios.dispose();
+ tutorial.dispose();
+ options.dispose();
+ exit.dispose();
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ if (!visible) return;
+ super.draw(batch);
+ scenarios.draw(batch);
+ tutorial.draw(batch);
+ options.draw(batch);
+ exit.draw(batch);
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/menu/OptionsMenu.java b/core/src/ch/asynk/tankontank/menu/OptionsMenu.java
new file mode 100644
index 0000000..4257ac6
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/menu/OptionsMenu.java
@@ -0,0 +1,189 @@
+package ch.asynk.tankontank.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.tankontank.ui.Label;
+import ch.asynk.tankontank.ui.Bg;
+import ch.asynk.tankontank.ui.Patch;
+
+import ch.asynk.tankontank.TankOnTank;
+
+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 = 20;
+ public static int HSPACING = 30;
+ public static String CHECK = "#";
+
+ private final TankOnTank game;
+ private final BitmapFont font;
+
+ private String [] checkStrings = {
+ "Debug",
+ "Use Reqular Pawns",
+ "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 [] checkLabels;
+ private boolean [] checkValues;
+ protected Bg okBtn;
+
+ public OptionsMenu(TankOnTank 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("- 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.checkValues = new boolean[checkStrings.length];
+ this.checkLabels = new Label[checkStrings.length];
+ for (int i = 0; i < checkLabels.length; i++) {
+ Label l = new Label(font);
+ l.write(checkStrings[i]);
+ this.checkLabels[i] = l;
+ }
+ getValues();
+ checkDy = font.getMultiLineBounds(CHECK).height;
+
+ this.visible = false;
+ }
+
+ private void getValues()
+ {
+ checkValues[7] = 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.regularPawns;
+ checkValues[0] = game.config.debug;
+ }
+
+ private void apply()
+ {
+ game.config.showMoves = checkValues[7];
+ game.config.showTargets = checkValues[6];
+ game.config.showMoveAssists = checkValues[5];
+ game.config.showEnemyPossibilities = checkValues[4];
+ game.config.canCancel = checkValues[3];
+ game.config.mustValidate = checkValues[2];
+ game.config.regularPawns = checkValues[1];
+ game.config.debug = checkValues[0];
+ }
+
+ 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);
+ }
+
+ 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 += (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 + title.getHeight());
+
+ 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 (!visible) return false;
+
+ if (okBtn.hit(x, y)) {
+ apply();
+ return true;
+ } else if (fxVolume.hit(x, y)) {
+ cycleFxVolume();
+ } 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();
+ fxVolume.dispose();
+ fxVolumeValue.dispose();
+ for (int i = 0; i < checkLabels.length; i++)
+ checkLabels[i].dispose();
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ if (!visible) return;
+ super.draw(batch);
+ title.draw(batch);
+ okBtn.draw(batch);
+ fxVolume.draw(batch);
+ fxVolumeValue.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/tankontank/menu/ScenariosMenu.java b/core/src/ch/asynk/tankontank/menu/ScenariosMenu.java
new file mode 100644
index 0000000..e101a2f
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/menu/ScenariosMenu.java
@@ -0,0 +1,123 @@
+package ch.asynk.tankontank.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.tankontank.ui.Label;
+import ch.asynk.tankontank.ui.Bg;
+import ch.asynk.tankontank.ui.Patch;
+import ch.asynk.tankontank.TankOnTank;
+import ch.asynk.tankontank.game.Battle;
+
+public class ScenariosMenu extends Patch
+{
+ public static int PADDING = 40;
+ public static int OK_PADDING = 10;
+ public static int TITLE_PADDING = 30;
+ public static int VSPACING = 20;
+ public static int HSPACING = 30;
+ public static String CHECK = "#";
+
+ private final TankOnTank game;
+ private final BitmapFont font;
+
+ private float checkDy;
+ private Label title;
+ protected Bg okBtn;
+ private Label [] battleLabels;
+
+ public ScenariosMenu(TankOnTank 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("- Scenarios");
+ this.battleLabels = new Label[game.factory.battles.length];
+ for (int i = 0; i < battleLabels.length; i++) {
+ Label l = new Label(font);
+ l.write(game.factory.battles[i].getName());
+ battleLabels[i] = l;
+ }
+ checkDy = font.getMultiLineBounds(CHECK).height;
+
+ this.visible = 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() + OK_PADDING), (y - OK_PADDING));
+
+ y += PADDING;
+ x += PADDING + HSPACING;
+ float dy = (VSPACING + title.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)) {
+ return true;
+ } else {
+ for (int i = 0; i <battleLabels.length; i++) {
+ if (battleLabels[i].hit(x, y)) {
+ game.config.battle = game.factory.battles[i];
+ }
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ title.dispose();
+ okBtn.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);
+ 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/tankontank/menu/TutorialsMenu.java b/core/src/ch/asynk/tankontank/menu/TutorialsMenu.java
new file mode 100644
index 0000000..28f7276
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/menu/TutorialsMenu.java
@@ -0,0 +1,94 @@
+package ch.asynk.tankontank.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.tankontank.ui.Label;
+import ch.asynk.tankontank.ui.Bg;
+import ch.asynk.tankontank.ui.Patch;
+import ch.asynk.tankontank.TankOnTank;
+
+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 TankOnTank game;
+ private final BitmapFont font;
+
+ private Label title;
+ private Label msg;
+ protected Bg okBtn;
+
+ public TutorialsMenu(TankOnTank 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);
+ }
+}