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/TankOnTank.java77
-rw-r--r--core/src/ch/asynk/tankontank/game/Ctrl.java2
-rw-r--r--core/src/ch/asynk/tankontank/screens/LoadScreen.java145
-rw-r--r--core/src/ch/asynk/tankontank/screens/MenuBgCamera.java46
-rw-r--r--core/src/ch/asynk/tankontank/screens/MenuScreen.java268
-rw-r--r--core/src/ch/asynk/tankontank/screens/OptionsScreen.java214
6 files changed, 376 insertions, 376 deletions
diff --git a/core/src/ch/asynk/tankontank/TankOnTank.java b/core/src/ch/asynk/tankontank/TankOnTank.java
index 95c7d6b..52c16a1 100644
--- a/core/src/ch/asynk/tankontank/TankOnTank.java
+++ b/core/src/ch/asynk/tankontank/TankOnTank.java
@@ -8,8 +8,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
-import ch.asynk.tankontank.screens.LoadScreen;
-import ch.asynk.tankontank.screens.OptionsScreen;
+import ch.asynk.tankontank.screens.MenuScreen;
import ch.asynk.tankontank.screens.GameScreen;
import ch.asynk.tankontank.game.Ctrl;
import ch.asynk.tankontank.game.Config;
@@ -23,9 +22,18 @@ public class TankOnTank extends Game
public Config config;
public TextureAtlas uiAtlas;
+ public TextureAtlas menuAtlas;
public BitmapFont fontB;
public BitmapFont fontW;
+ public enum State
+ {
+ MENU,
+ GAME,
+ NONE
+ }
+ private State state;
+
public static void debug(String msg)
{
debug("", msg);
@@ -46,13 +54,37 @@ public class TankOnTank extends Game
factory = new Factory(this);
config = new Config();
+ state = State.NONE;
loadUiAssets();
- this.setScreen(new LoadScreen(this));
+ switchToMenu();
+ }
+
+ public void switchToMenu()
+ {
+ if (state == State.GAME) {
+ unloadGameAssets();
+ factory.dispose();
+ ctrl.dispose();
+ getScreen().dispose();
+ }
+ loadMenuAssets();
+ state = State.MENU;
+ setScreen(new MenuScreen(this));
}
- public void loadAssets()
+ public void switchToGame()
+ {
+ unloadMenuAssets();
+ getScreen().dispose();
+ factory.assetsLoaded();
+ state = State.GAME;
+ setScreen(new GameScreen(this));
+ }
+
+ public void loadGameAssets()
{
debug("TankOnTank", " load assets : " + (Gdx.app.getJavaHeap()/1024.0f) + "KB");
+ // TODO load only needed map
manager.load("data/map_a.png", Texture.class);
manager.load("data/map_b.png", Texture.class);
manager.load("data/hex.png", Texture.class);
@@ -74,10 +106,10 @@ public class TankOnTank extends Game
manager.load("sounds/promote.mp3", Sound.class);
}
- public void unloadAssets()
+ private void unloadGameAssets()
{
debug("TankOnTank", "unload assets : " + (Gdx.app.getJavaHeap()/1024.0f) + "KB");
- debug("TankOnTank", "diagnostics:\n" + manager.getDiagnostics() );
+ // TODO load only needed map
manager.unload("data/map_a.png");
manager.unload("data/map_b.png");
manager.unload("data/hex.png");
@@ -97,10 +129,9 @@ public class TankOnTank extends Game
manager.unload("sounds/explosion.mp3");
manager.unload("sounds/explosion_short.mp3");
manager.unload("sounds/promote.mp3");
- debug("TankOnTank", "diagnostics:\n" + manager.getDiagnostics() );
}
- public void loadUiAssets()
+ private void loadUiAssets()
{
manager.load("data/ui.atlas", TextureAtlas.class);
manager.finishLoading();
@@ -109,7 +140,7 @@ public class TankOnTank extends Game
fontW = new BitmapFont(Gdx.files.internal("skin/veteran.fnt"), uiAtlas.findRegion("veteran-white"));
}
- public void unloadUiAssets()
+ private void unloadUiAssets()
{
fontB.dispose();
fontW.dispose();
@@ -117,15 +148,19 @@ public class TankOnTank extends Game
manager.unload("data/ui.atlas");
}
- public void switchToOptions()
+ private void loadMenuAssets()
{
- factory.assetsLoaded();
- setScreen(new OptionsScreen(this));
+ manager.load("data/map_a.png", Texture.class);
+ manager.load("data/menu.atlas", TextureAtlas.class);
+ manager.finishLoading();
+ menuAtlas = manager.get("data/menu.atlas", TextureAtlas.class);
}
- public void switchToGame()
+ private void unloadMenuAssets()
{
- setScreen(new GameScreen(this));
+ menuAtlas.dispose();
+ manager.unload("data/map_a.png");
+ manager.unload("data/menu.atlas");
}
// @Override
@@ -147,10 +182,20 @@ public class TankOnTank extends Game
public void dispose()
{
debug("TankOnTank", "dispose()");
+ debug("TankOnTank", "diagnostics:\n" + manager.getDiagnostics() );
getScreen().dispose();
- factory.dispose();
unloadUiAssets();
- unloadAssets();
+ switch(state) {
+ case MENU:
+ unloadMenuAssets();
+ break;
+ case GAME:
+ unloadGameAssets();
+ factory.dispose();
+ ctrl.dispose();
+ break;
+ }
+ debug("TankOnTank", "diagnostics:\n" + manager.getDiagnostics() );
}
// @Override
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java
index 0d34d20..9947d87 100644
--- a/core/src/ch/asynk/tankontank/game/Ctrl.java
+++ b/core/src/ch/asynk/tankontank/game/Ctrl.java
@@ -304,7 +304,7 @@ public class Ctrl implements Disposable
public void endGame()
{
- game.switchToOptions();
+ game.switchToMenu();
}
public void endPlayerTurn(boolean abort)
diff --git a/core/src/ch/asynk/tankontank/screens/LoadScreen.java b/core/src/ch/asynk/tankontank/screens/LoadScreen.java
deleted file mode 100644
index 1b4b401..0000000
--- a/core/src/ch/asynk/tankontank/screens/LoadScreen.java
+++ /dev/null
@@ -1,145 +0,0 @@
-package ch.asynk.tankontank.screens;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.Screen;
-import com.badlogic.gdx.graphics.GL20;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.Camera;
-import com.badlogic.gdx.graphics.OrthographicCamera;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.math.Interpolation;
-import com.badlogic.gdx.utils.viewport.FitViewport;
-
-import ch.asynk.tankontank.TankOnTank;
-import ch.asynk.tankontank.loading.LoadingBar;
-
-public class LoadScreen implements Screen
-{
- private final TankOnTank game;
-
- private float percent;
- private float delay = 0.0f;
- private float[] xPath = { 68, 164, 260, 356, 452, 404, 356, 452, 548, 596, 692};
- private float[] yPath = { 148,148, 148, 148, 148, 231, 314, 314, 314, 397, 397};
-
- private boolean ready;
- private boolean assetsLoaded;
- private Texture bg;
- private Texture unit;
- private float dx;
- private float dy;
-
- private final Camera camera;
- private final SpriteBatch batch;
- private final FitViewport viewport;
-
- public LoadScreen(final TankOnTank game)
- {
- this.game = game;
- this.batch = new SpriteBatch();
-
- float width = Gdx.graphics.getWidth();
- float height = Gdx.graphics.getHeight();
- this.camera = new OrthographicCamera(width, height);
- this.viewport = new FitViewport(width, height, camera);
- this.ready = false;
- this.assetsLoaded = false;
- this.dx = ((width - 800) / 2f);
- this.dy = ((height - 600) / 4f);
- }
-
- @Override
- public void render(float delta)
- {
- if (game.manager.update()) {
- delay += delta;
- if (delay >= 0.6f)
- assetsLoadingCompleted();
- }
-
- if (!ready) return;
-
- percent = Interpolation.linear.apply(percent, game.manager.getProgress(), 0.1f);
- int idx = (int) (percent * 10);
- float fraction = ((percent * 100 ) % 10 / 10);
- float x = (xPath[idx] + ((xPath[idx + 1] - xPath[idx]) * fraction));
- float y = (yPath[idx] + ((yPath[idx + 1] - yPath[idx]) * fraction));
-
- camera.update();
-
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- batch.setProjectionMatrix(camera.combined);
- batch.begin();
- batch.draw(bg, dx, dy);
- batch.draw(unit, (x + dx), (y + dy));
- batch.end();
- }
-
- @Override
- public void show()
- {
- viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
- load();
- game.loadAssets();
- }
-
- @Override
- public void resize(int width, int height)
- {
- viewport.update(width, height, true);
- }
-
- @Override
- public void dispose()
- {
- unload();
- }
-
- @Override
- public void hide()
- {
- unload();
- }
-
- @Override
- public void pause()
- {
- unload();
- }
-
- @Override
- public void resume()
- {
- load();
- }
-
- private void load()
- {
- game.manager.load("data/unit.png", Texture.class);
- game.manager.load("data/loading.png", Texture.class);
- game.manager.finishLoading();
- bg = game.manager.get("data/loading.png", Texture.class);
- unit = game.manager.get("data/unit.png", Texture.class);
- ready = true;
- }
-
- private void unload()
- {
- if (!ready) return;
- bg.dispose();
- unit.dispose();
- game.manager.unload("data/loading.png");
- game.manager.unload("data/unit.png");
- ready = false;
- }
-
- private void assetsLoadingCompleted()
- {
- if (assetsLoaded) return;
- assetsLoaded = true;
- TankOnTank.debug("LoadScreen", "assets ready : " + (Gdx.app.getJavaHeap()/1024.0f) + "KB");
- game.switchToOptions();
- dispose();
- }
-}
diff --git a/core/src/ch/asynk/tankontank/screens/MenuBgCamera.java b/core/src/ch/asynk/tankontank/screens/MenuBgCamera.java
new file mode 100644
index 0000000..200e5ed
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/screens/MenuBgCamera.java
@@ -0,0 +1,46 @@
+package ch.asynk.tankontank.screens;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.math.Rectangle;
+
+public class MenuBgCamera extends OrthographicCamera
+{
+ private static final float ZEROF = 0.01f;
+
+ private float virtualAspect;
+ private final Rectangle virtual;
+ private final Rectangle screen;
+
+ public MenuBgCamera(int cx, int cy, int width, int height)
+ {
+ super(width, height);
+ this.virtual = new Rectangle();
+ this.virtual.set(cx, cy, width, height);
+ this.virtualAspect = (virtual.width / virtual.height);
+ this.screen = new Rectangle();
+ this.screen.set(0, 0, 0, 0);
+ this.position.set(virtual.x, virtual.y, 0f);
+ }
+
+ public void updateViewport(int screenWidth, int screenHeight)
+ {
+ float aspect = (screenWidth / (float) screenHeight);
+ float diff = (virtualAspect - aspect);
+
+ if (diff < -ZEROF) {
+ viewportWidth = (virtual.height * aspect);
+ viewportHeight = virtual.height;
+ } else if (diff > ZEROF) {
+ viewportWidth = virtual.width;
+ viewportHeight = (virtual.width / aspect);
+ }
+
+ screen.width= screenWidth;
+ screen.height= screenHeight;
+
+ Gdx.gl.glViewport((int)screen.x, (int)screen.y, (int)screen.width, (int)screen.height);
+
+ update(true);
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/screens/MenuScreen.java b/core/src/ch/asynk/tankontank/screens/MenuScreen.java
new file mode 100644
index 0000000..5bfa488
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/screens/MenuScreen.java
@@ -0,0 +1,268 @@
+package ch.asynk.tankontank.screens;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Screen;
+import com.badlogic.gdx.InputAdapter;
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.math.Interpolation;
+import com.badlogic.gdx.utils.viewport.ScreenViewport;
+
+import ch.asynk.tankontank.TankOnTank;
+import ch.asynk.tankontank.ui.Position;
+import ch.asynk.tankontank.menu.MainMenu;
+import ch.asynk.tankontank.menu.OptionsMenu;
+import ch.asynk.tankontank.menu.ScenariosMenu;
+import ch.asynk.tankontank.menu.TutorialsMenu;
+
+public class MenuScreen implements Screen
+{
+ private final TankOnTank game;
+
+ private final int OFFSET = 20;
+ private final int V_WIDTH = 1600;
+ private final int V_HEIGHT = 1125;
+ private final int V_CENTER_X = 1000;
+ private final int V_CENTER_Y = 890;
+
+ private float percent;
+ private float delay = 0.0f;
+ private float dx;
+ private float dy;
+ private int[] xPath = { 369, 558, 747, 936, 1125, 1030, 936, 1125, 1314, 1408, 1597};
+ private int[] yPath = { 565, 565, 565, 565, 565, 729, 892, 892, 892, 1056, 1056};
+ private int n = xPath.length;
+
+ private boolean ready;
+ private boolean gameAssetsLoading;
+ private Texture bg;
+
+ private Sprite unit;
+ private Sprite move;
+ private Sprite from;
+ private Sprite to;
+ private Sprite geFlag;
+ private Sprite usFlag;
+ private Sprite lnl;
+ private Sprite logo;
+
+ private MainMenu mainMenu;
+ private OptionsMenu optionsMenu;
+ private ScenariosMenu scenariosMenu;
+ private TutorialsMenu tutorialsMenu;
+
+ private final MenuBgCamera bgCamera;
+ private final ScreenViewport screenViewport;
+ private final SpriteBatch batch;
+ private Vector3 touch = new Vector3();
+
+ public MenuScreen(final TankOnTank game)
+ {
+ this.game = game;
+ this.batch = new SpriteBatch();
+
+ float width = Gdx.graphics.getWidth();
+ float height = Gdx.graphics.getHeight();
+
+ this.bgCamera = new MenuBgCamera(V_CENTER_X, V_CENTER_Y, V_WIDTH, V_HEIGHT);
+ this.screenViewport = new ScreenViewport();
+
+ this.gameAssetsLoading = false;
+
+ this.bg = game.manager.get("data/map_a.png", Texture.class);
+
+ this.unit = new Sprite(game.menuAtlas.findRegion("unit"));
+ this.move = new Sprite(game.menuAtlas.findRegion("move"));
+ this.from = new Sprite(game.menuAtlas.findRegion("from"));
+ this.to = new Sprite(game.menuAtlas.findRegion("to"));
+ this.usFlag = new Sprite(game.menuAtlas.findRegion("us-flag"));
+ this.geFlag = new Sprite(game.menuAtlas.findRegion("ge-flag"));
+ this.lnl = new Sprite(game.menuAtlas.findRegion("lnl"));
+ this.logo = new Sprite(game.menuAtlas.findRegion("logo"));
+
+ this.mainMenu = new MainMenu(game.fontB, game.uiAtlas);
+ this.optionsMenu = new OptionsMenu(game, game.fontB, game.uiAtlas);
+ this.scenariosMenu = new ScenariosMenu(game, game.fontB, game.uiAtlas);
+ this.tutorialsMenu = new TutorialsMenu(game, game.fontB, game.uiAtlas);
+
+ Gdx.input.setInputProcessor(new InputAdapter() {
+ @Override
+ public boolean touchDown(int x, int y, int pointer, int button)
+ {
+ touch.set(x, y, 0f);
+ screenViewport.getCamera().unproject(touch);
+ return hit(touch.x, touch.y);
+ }
+ });
+ }
+
+ private boolean hit(float x, float y)
+ {
+ if (mainMenu.hit(x, y)) {
+ mainMenu.visible = false;
+ showNextMenu();
+ return true;
+ } else if (optionsMenu.hit(x, y)) {
+ mainMenu.visible = true;
+ optionsMenu.visible = false;
+ return true;
+ } else if (scenariosMenu.hit(x, y)) {
+ mainMenu.visible = true;
+ scenariosMenu.visible = false;
+ if (game.config.battle != null)
+ startLoading();
+ return true;
+ } else if (tutorialsMenu.hit(x, y)) {
+ mainMenu.visible = true;
+ tutorialsMenu.visible = false;
+ return true;
+ }
+
+ return false;
+ }
+
+ private void showNextMenu()
+ {
+ MainMenu.Menu menu = mainMenu.getMenu();
+
+ if (menu == MainMenu.Menu.OPTIONS)
+ optionsMenu.visible = true;
+ else if (menu == MainMenu.Menu.SCENARIOS)
+ scenariosMenu.visible = true;
+ else if (menu == MainMenu.Menu.TUTORIALS)
+ tutorialsMenu.visible = true;
+ }
+
+ private void startLoading()
+ {
+ mainMenu.visible = false;
+ game.loadGameAssets();
+ gameAssetsLoading = true;
+ }
+
+ private void gameAssetsLoadingCompleted()
+ {
+ TankOnTank.debug("LoadScreen", "assets ready : " + (Gdx.app.getJavaHeap()/1024.0f) + "KB");
+ game.switchToGame();
+ dispose();
+ }
+
+ @Override
+ public void render(float delta)
+ {
+ float x = xPath[0];
+ float y = yPath[0];
+ if (gameAssetsLoading) {
+ if (game.manager.update()) {
+ delay += delta;
+ if (delay >= 0.6f)
+ gameAssetsLoadingCompleted();
+ }
+
+ percent = Interpolation.linear.apply(percent, game.manager.getProgress(), 0.1f);
+ int idx = (int) (percent * 10);
+ float fraction = ((percent * 100 ) % 10 / 10);
+ x = (xPath[idx] + ((xPath[idx + 1] - xPath[idx]) * fraction));
+ y = (yPath[idx] + ((yPath[idx + 1] - yPath[idx]) * fraction));
+ }
+
+ Gdx.gl.glClearColor(0, 0, 0, 1);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ batch.setProjectionMatrix(bgCamera.combined);
+ batch.begin();
+ batch.draw(bg, 0, 0);
+ from.draw(batch);
+ to.draw(batch);
+ usFlag.draw(batch);
+ geFlag.draw(batch);
+ for (int i = 1; i < (n - 1); i++)
+ drawCentered(batch, move, xPath[i], yPath[i]);
+ drawCentered(batch, unit, (int) (x + dx), (int) (y + dy));
+ batch.end();
+
+ batch.setProjectionMatrix(screenViewport.getCamera().combined);
+ batch.begin();
+ batch.draw(logo, OFFSET, (screenViewport.getScreenHeight() - logo.getRegionHeight() - OFFSET));
+ batch.draw(lnl, (screenViewport.getScreenWidth() - lnl.getRegionWidth() - (2 * OFFSET)), (2 * OFFSET));
+ mainMenu.draw(batch);
+ optionsMenu.draw(batch);
+ scenariosMenu.draw(batch);
+ tutorialsMenu.draw(batch);
+ batch.end();
+ }
+
+ private void drawCentered(SpriteBatch batch, TextureRegion region, int x, int y)
+ {
+ batch.draw(region, (x - (region.getRegionWidth() / 2f)), (y - (region.getRegionHeight() / 2f)));
+ }
+
+ private void setCenteredPosition(Sprite sprite, int x, int y)
+ {
+ sprite.setPosition((x - (sprite.getWidth() / 2f)), (y - (sprite.getHeight() / 2f)));
+ }
+
+ private void update(int width, int height)
+ {
+ bgCamera.updateViewport(width, height);
+ screenViewport.update(width, height, true);
+ Position.update(width, height);
+
+ setCenteredPosition(from, xPath[0], yPath[0]);
+ setCenteredPosition(to, xPath[n - 1], yPath[n - 1]);
+ setCenteredPosition(usFlag, xPath[0], yPath[0]);
+ setCenteredPosition(geFlag, xPath[n - 1], yPath[n - 1]);
+
+ mainMenu.setPosition();
+ optionsMenu.setPosition();
+ scenariosMenu.setPosition();
+ tutorialsMenu.setPosition();
+ }
+
+ @Override
+ public void resize(int width, int height)
+ {
+ update(width, height);
+ }
+
+ @Override
+ public void dispose()
+ {
+ bg.dispose();
+ mainMenu.dispose();
+ optionsMenu.dispose();
+ scenariosMenu.dispose();
+ tutorialsMenu.dispose();
+ }
+
+ @Override
+ public void show()
+ {
+ int width = (int) Gdx.graphics.getWidth();
+ int height = (int) Gdx.graphics.getHeight();
+ update(width, height);
+ }
+
+ @Override
+ public void hide()
+ {
+ // TankOnTank.debug("MenuScreen", "hide()");
+ }
+
+ @Override
+ public void pause()
+ {
+ // TankOnTank.debug("MenuScreen", "pause()");
+ }
+
+ @Override
+ public void resume()
+ {
+ // TankOnTank.debug("MenuScreen", "resume()");
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/screens/OptionsScreen.java b/core/src/ch/asynk/tankontank/screens/OptionsScreen.java
deleted file mode 100644
index 371cb64..0000000
--- a/core/src/ch/asynk/tankontank/screens/OptionsScreen.java
+++ /dev/null
@@ -1,214 +0,0 @@
-package ch.asynk.tankontank.screens;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.Screen;
-import com.badlogic.gdx.graphics.GL20;
-import com.badlogic.gdx.scenes.scene2d.Actor;
-import com.badlogic.gdx.scenes.scene2d.Stage;
-import com.badlogic.gdx.utils.viewport.FitViewport;
-import com.badlogic.gdx.scenes.scene2d.ui.Skin;
-import com.badlogic.gdx.scenes.scene2d.ui.Label;
-import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
-import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
-import com.badlogic.gdx.scenes.scene2d.ui.List;
-import com.badlogic.gdx.scenes.scene2d.ui.Slider;
-import com.badlogic.gdx.scenes.scene2d.InputEvent;
-import com.badlogic.gdx.scenes.scene2d.InputListener;
-import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
-
-import ch.asynk.tankontank.TankOnTank;
-import ch.asynk.tankontank.game.Battle;
-
-class MyList extends List<Battle>
-{
- public MyList(Skin skin, Battle... items)
- {
- super(skin);
- setItems(items);
- layout();
- setSize(getPrefWidth(), getPrefHeight());
- }
-}
-
-public class OptionsScreen implements Screen
-{
- private final TankOnTank game;
-
- private Stage stage;
- private Label title1;
- private TextButton okButton;
- private CheckBox showMovesCk;
- private CheckBox showTargetsCk;
- private CheckBox showMoveAssistsCk;
- private CheckBox canCancelCk;
- private CheckBox mustValidateCk;
- private CheckBox showEnemyPossibilitiesCk;
- private CheckBox regularPawnsCk;
- private CheckBox debugCk;
- private Label fxLabel;
- private Label fxValue;
- private Slider fxVolume;
- private Label title2;
- private List<Battle> scenarios;
-
- public OptionsScreen(final TankOnTank game)
- {
- this.game = game;
- }
-
- @Override
- public void render(float delta)
- {
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-
- stage.act();
- stage.draw();
- }
-
- private void apply()
- {
- game.config.showMoves = showMovesCk.isChecked();
- game.config.showTargets = showTargetsCk.isChecked();
- game.config.showMoveAssists = showMoveAssistsCk.isChecked();
- game.config.canCancel = canCancelCk.isChecked();
- game.config.mustValidate = mustValidateCk.isChecked();
- game.config.showEnemyPossibilities = showEnemyPossibilitiesCk.isChecked();
- game.config.regularPawns = regularPawnsCk.isChecked();
- game.config.debug = debugCk.isChecked();
- game.config.fxVolume = fxVolume.getValue();
- game.config.battle = scenarios.getSelected();
- }
-
- @Override
- public void show()
- {
- TankOnTank.debug("OptionsScreen", "show()");
-
- stage = new Stage(new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
- Gdx.input.setInputProcessor(stage);
-
- Skin skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
-
- title1 = new Label("Options", skin);
- okButton = new TextButton("OK", skin);
- showMovesCk = new CheckBox("Show Moves", skin);
- showTargetsCk = new CheckBox("Show Targets", skin);
- showMoveAssistsCk = new CheckBox("Show Moves Assists", skin);
- canCancelCk = new CheckBox("Can Cancel", skin);
- mustValidateCk = new CheckBox("Must Validate", skin);
- showEnemyPossibilitiesCk = new CheckBox("Show Enemy Possibilities", skin);
- regularPawnsCk = new CheckBox("Use Reqular Pawns", skin);
- debugCk = new CheckBox("Debug", skin);
- fxLabel = new Label("FX volume", skin);
- fxValue = new Label(String.format("%.1f", game.config.fxVolume), skin);
- fxVolume = new Slider(0f, 1f, 0.1f, false, skin) ;
- title2 = new Label("Scenarios", skin);
- scenarios = new MyList(skin, game.factory.battles);
-
- showMovesCk.setChecked(game.config.showMoves);
- showTargetsCk.setChecked(game.config.showTargets);
- showMoveAssistsCk.setChecked(game.config.showMoveAssists);
- canCancelCk.setChecked(game.config.canCancel);
- mustValidateCk.setChecked(game.config.mustValidate);
- showEnemyPossibilitiesCk.setChecked(game.config.showEnemyPossibilities);
- regularPawnsCk.setChecked(game.config.regularPawns);
- debugCk.setChecked(game.config.debug);
- fxVolume.setValue(game.config.fxVolume);
-
- okButton.addListener(new InputListener() {
- public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
- return true;
- }
- public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
- apply();
- game.switchToGame();
- }
- });
-
- fxVolume.addListener(new ChangeListener() {
- public void changed (ChangeEvent event, Actor actor) {
- fxValue.setText(String.format("%.1f", fxVolume.getValue()));
- }
- });
-
- stage.addActor(title1);
- stage.addActor(showMovesCk);
- stage.addActor(showTargetsCk);
- stage.addActor(showMoveAssistsCk);
- stage.addActor(canCancelCk);
- stage.addActor(mustValidateCk);
- stage.addActor(showEnemyPossibilitiesCk);
- stage.addActor(regularPawnsCk);
- stage.addActor(debugCk);
- stage.addActor(fxLabel);
- stage.addActor(fxValue);
- stage.addActor(fxVolume);
- stage.addActor(okButton);
- stage.addActor(title2);
- stage.addActor(scenarios);
- }
-
- @Override
- public void resize(int width, int height)
- {
- // TankOnTank.debug("OptionsScreen", "resize (" + width + "," + height + ")");
-
- stage.getViewport().update(width, height, true);
-
- float x = ((width / 2) - 100f);
- float y = (height - 100f);
- title1.setPosition((x - 20f), y);
- y -= 20f;
- showMovesCk.setPosition(x, y);
- y -= 20f;
- showTargetsCk.setPosition(x, y);
- y -= 20f;
- showMoveAssistsCk.setPosition(x, y);
- y -= 20f;
- canCancelCk.setPosition(x, y);
- y -= 20f;
- mustValidateCk.setPosition(x, y);
- y -= 20f;
- showEnemyPossibilitiesCk.setPosition(x, y);
- y -= 20f;
- regularPawnsCk.setPosition(x, y);
- y -= 20f;
- debugCk.setPosition(x, y);
- y -= 20f;
- fxLabel.setPosition(x, y);
- fxVolume.setPosition((x + fxLabel.getWidth() + 10), y);
- fxValue.setPosition((fxVolume.getX() + fxVolume.getWidth() + 10), y);
- y -= 40f;
- title2.setPosition((x - 20f), y);
- y -= scenarios.getHeight();
- scenarios.setPosition(x, y);
- y -= 20f;
- x += 200f;
- okButton.setPosition(x, y);
- }
-
- @Override
- public void dispose()
- {
- // TankOnTank.debug("LoadScreen", "dispose()");
- stage.dispose();
- }
-
- @Override
- public void hide()
- {
- // TankOnTank.debug("LoadScreen", "hide()");
- }
-
- @Override
- public void pause()
- {
- // TankOnTank.debug("LoadScreen", "pause()");
- }
-
- @Override
- public void resume()
- {
- // TankOnTank.debug("LoadScreen", "resume()");
- }
-}