summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/screens
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/screens
parente66f9f2a61d3dab4545e996046486de0d44e2901 (diff)
downloadRustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.zip
RustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.tar.gz
welcome RustAndDust
Diffstat (limited to 'core/src/ch/asynk/rustanddust/screens')
-rw-r--r--core/src/ch/asynk/rustanddust/screens/GameCamera.java212
-rw-r--r--core/src/ch/asynk/rustanddust/screens/GameScreen.java221
-rw-r--r--core/src/ch/asynk/rustanddust/screens/MenuCamera.java112
-rw-r--r--core/src/ch/asynk/rustanddust/screens/MenuScreen.java258
4 files changed, 803 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/screens/GameCamera.java b/core/src/ch/asynk/rustanddust/screens/GameCamera.java
new file mode 100644
index 0000000..0dbcb50
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/screens/GameCamera.java
@@ -0,0 +1,212 @@
+package ch.asynk.rustanddust.screens;
+
+import com.badlogic.gdx.Gdx;
+
+import com.badlogic.gdx.graphics.OrthographicCamera;
+
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Matrix4;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.math.MathUtils;
+
+public class GameCamera extends OrthographicCamera
+{
+ private static final float ZEROF = 0.01f;
+
+ private int screenWidth;
+ private int screenHeight;
+ private float zoomOut;
+ private float zoomIn;
+ private float viewportAspect;
+ private float widthFactor;
+ private float heightFactor;
+ private Rectangle virtual;
+ private Rectangle window;
+ private Rectangle hud;
+ private Matrix4 hudMatrix;
+ private Matrix4 hudInvProjMatrix;
+ private int hudCorrection;
+ private int hudLeft;
+ private int hudBottom;
+ private boolean fixedHud;
+
+ public GameCamera(float virtualWidth, float virtualHeight, float zoomOut, float zoomIn, int hudCorrection, boolean fixedHud)
+ {
+ super(virtualWidth, virtualHeight);
+ this.zoomOut = zoomOut;
+ this.zoomIn = zoomIn;
+ this.viewportAspect = (viewportWidth / viewportHeight);
+ this.virtual = new Rectangle();
+ this.virtual.set(0, 0, virtualWidth, virtualHeight);
+ this.window = new Rectangle();
+ this.hud = new Rectangle();
+ this.hudMatrix = new Matrix4();
+ this.hudInvProjMatrix = new Matrix4();
+ this.hudCorrection = hudCorrection;
+ this.fixedHud = fixedHud;
+ }
+
+ public void updateViewport(int screenWidth, int screenHeight)
+ {
+ this.screenWidth = screenWidth;
+ this.screenHeight = screenHeight;
+
+ float aspect = (screenWidth / (float) screenHeight);
+ float diff = (viewportAspect - aspect);
+
+ if (diff < -ZEROF) {
+ // wider than tall
+ window.width = java.lang.Math.min((screenHeight * viewportAspect / zoom), screenWidth);
+ window.height = screenHeight;
+ window.x = ((screenWidth - window.width) / 2f);
+ window.y = 0f;
+ viewportWidth = (viewportHeight * (window.width / window.height));
+ hud.y = hudCorrection;
+ hud.x = (hud.y * viewportWidth / viewportHeight);
+ } else if (diff > ZEROF) {
+ // taller than wide
+ // FIXME fix hud vertical position
+ window.width = screenWidth;
+ window.height = java.lang.Math.min((screenWidth * viewportAspect / zoom), screenHeight);
+ window.x = 0f;
+ window.y = ((screenHeight - window.height) / 2f);
+ viewportHeight = (viewportWidth * (window.height / window.width));
+ hud.x = hudCorrection;
+ hud.y = (hud.x * viewportHeight / viewportWidth);
+ }
+
+ if (fixedHud) {
+ hud.x = 0;
+ hud.y = 0;
+ hud.width = screenWidth;
+ hud.height = screenHeight;
+ } else {
+ hud.width = (window.width - (2 * hud.x));
+ hud.height = (window.height - (2 * hud.y));
+ }
+
+ widthFactor = (viewportWidth / screenWidth);
+ heightFactor = (viewportHeight / screenHeight);
+
+ clampPosition();
+ update(true);
+ hudMatrix.setToOrtho2D(hud.x, hud.y, hud.width, hud.height);
+ hudInvProjMatrix.set(hudMatrix);
+ Matrix4.inv(hudInvProjMatrix.val);
+ }
+
+ public void applyMapViewport()
+ {
+ Gdx.gl.glViewport((int)window.x, (int)window.y, (int)window.width, (int)window.height);
+ }
+
+ public void applyHudViewport()
+ {
+ if (fixedHud)
+ Gdx.gl.glViewport(0, 0, screenWidth, screenHeight);
+ }
+
+ public Matrix4 getHudMatrix()
+ {
+ return hudMatrix;
+ }
+
+ public int getScreenWidth()
+ {
+ return screenWidth;
+ }
+
+ public int getScreenHeight()
+ {
+ return screenHeight;
+ }
+
+ public int getHudLeft()
+ {
+ return (int) hud.x;
+ }
+
+ public int getHudBottom()
+ {
+ return (int) hud.y;
+ }
+
+ public int getHudWidth()
+ {
+ return (int) hud.width;
+ }
+
+ public int getHudHeight()
+ {
+ return (int) hud.height;
+ }
+
+ public void centerOnWorld()
+ {
+ position.set((viewportWidth / 2f), (viewportHeight / 2f), 0f);
+ }
+
+ public void zoom(float dz)
+ {
+ zoom += dz;
+ clampZoom();
+ updateViewport(screenWidth, screenHeight);
+ }
+
+ public void translate(float dx, float dy)
+ {
+ float deltaX = (dx * zoom * widthFactor);
+ float deltaY = (dy * zoom * heightFactor);
+ translate(deltaX, -deltaY, 0);
+ clampPosition();
+ update(true);
+ }
+
+ public void clampZoom()
+ {
+ zoom = MathUtils.clamp(zoom, zoomIn, zoomOut);
+ }
+
+ public void clampPosition()
+ {
+ float cx = (viewportWidth * zoom);
+ float cy = (viewportHeight * zoom);
+
+ if ((virtual.width - cx) > ZEROF) {
+ cx /= 2f;
+ position.x = MathUtils.clamp(position.x, cx, (virtual.width - cx));
+ } else
+ position.x = (virtual.width / 2f);
+
+ if ((virtual.height - cy) > ZEROF) {
+ cy /= 2f;
+ position.y = MathUtils.clamp(position.y, cy, (virtual.height - cy));
+ } else
+ position.y = (virtual.height / 2f);
+ }
+
+ public void debug()
+ {
+ System.err.println(String.format(" VIEWPORT: %dx%d * %.2f -> %dx%d", (int)viewportWidth, (int)viewportHeight,
+ zoom, (int)(viewportWidth * zoom), (int)(viewportHeight * zoom)));
+ System.err.println(String.format(" WINDOW: %d;%d %dx%d", (int)window.x, (int)window.y, (int)window.width, (int)window.height));
+ System.err.println("MATRIX:" + combined.toString());
+ }
+
+ public void unproject(int x, int y, Vector3 v)
+ {
+ unproject(v.set(x, y, 0), window.x, window.y, window.width, window.height);
+ }
+
+ public void unprojectHud(float x, float y, Vector3 v)
+ {
+ Rectangle r = (fixedHud ? hud : window);
+ x = x - r.x;
+ y = Gdx.graphics.getHeight() - y - 1;
+ y = y - r.y;
+ v.x = (2 * x) / r.width - 1;
+ v.y = (2 * y) / r.height - 1;
+ v.z = 2 * v.z - 1;
+ v.prj(hudInvProjMatrix);
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/screens/GameScreen.java b/core/src/ch/asynk/rustanddust/screens/GameScreen.java
new file mode 100644
index 0000000..c369989
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/screens/GameScreen.java
@@ -0,0 +1,221 @@
+package ch.asynk.rustanddust.screens;
+
+import com.badlogic.gdx.Gdx;
+
+import com.badlogic.gdx.Screen;
+import com.badlogic.gdx.Input;
+import com.badlogic.gdx.InputAdapter;
+import com.badlogic.gdx.InputMultiplexer;
+import com.badlogic.gdx.input.GestureDetector;
+import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
+
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+
+import com.badlogic.gdx.math.Vector2;
+
+import ch.asynk.rustanddust.RustAndDust;
+
+import ch.asynk.rustanddust.game.Ctrl;
+
+public class GameScreen implements Screen
+{
+ private static boolean DEBUG = false;
+
+ private static final boolean FIXED_HUD = true;
+ private static final float INPUT_DELAY = 0.1f;
+ private static final float ZOOM_IN_MAX = 0.3f;
+ private static final float ZOOM_OUT_MAX = 1f;
+ private static final float ZOOM_GESTURE_FACTOR = .01f;
+ private static final float ZOOM_SCROLL_FACTOR = .1f;
+ private static final int DRAGGED_Z_INDEX = 10;
+ private static final int DRAG_THRESHOLD = 6;
+
+ private final GameCamera cam;
+
+ private final SpriteBatch batch;
+ private ShapeRenderer debugShapes = null;
+
+ private final RustAndDust game;
+ private Ctrl ctrl;
+
+ private int dragged;
+ private boolean blocked;
+ private float inputDelay = 0f;
+ private Vector2 dragPos = new Vector2();
+
+ public GameScreen(final RustAndDust game)
+ {
+ DEBUG = game.config.debug;
+
+ this.game = game;
+ this.dragged = 0;
+ this.blocked = false;
+
+ this.batch = new SpriteBatch();
+ this.ctrl = new Ctrl(game, game.config.battle);
+ this.cam = new GameCamera(ctrl.map.getWidth(), ctrl.map.getHeight(), ZOOM_OUT_MAX, ZOOM_IN_MAX, game.hudCorrection, FIXED_HUD);
+
+ if (DEBUG) this.debugShapes = new ShapeRenderer();
+
+ Gdx.input.setInputProcessor(getMultiplexer());
+ }
+
+
+ private InputMultiplexer getMultiplexer()
+ {
+ final InputMultiplexer multiplexer = new InputMultiplexer();
+ multiplexer.addProcessor(new GestureDetector(new GestureAdapter() {
+ @Override
+ public boolean zoom(float initialDistance, float distance)
+ {
+ if (initialDistance > distance)
+ cam.zoom(ZOOM_GESTURE_FACTOR);
+ else
+ cam.zoom(-ZOOM_GESTURE_FACTOR);
+ ctrl.hud.resize(cam.getHudLeft(), cam.getHudBottom(), cam.getHudWidth(), cam.getHudHeight());
+ blocked = true;
+ inputDelay = INPUT_DELAY;
+ return true;
+ }
+ }));
+ multiplexer.addProcessor(new InputAdapter() {
+ @Override
+ public boolean touchDragged(int x, int y, int pointer)
+ {
+ dragged += 1;
+ cam.translate((dragPos.x - x), (dragPos.y - y));
+ dragPos.set(x, y);
+ return true;
+ }
+ @Override
+ public boolean touchDown(int x, int y, int pointer, int button)
+ {
+ if (blocked) return true;
+ if (button == Input.Buttons.LEFT) {
+ dragPos.set(x, y);
+ cam.unproject(x, y, ctrl.mapTouch);
+ cam.unprojectHud(x, y, ctrl.hudTouch);
+ ctrl.touchDown();
+ }
+ return true;
+ }
+ @Override
+ public boolean touchUp(int x, int y, int pointer, int button)
+ {
+ if (blocked) return true;
+ if (dragged > DRAG_THRESHOLD) {
+ dragged = 0;
+ return true;
+ }
+ dragged = 0;
+ if (button == Input.Buttons.LEFT) {
+ cam.unproject(x, y, ctrl.mapTouch);
+ cam.unprojectHud(x, y, ctrl.hudTouch);
+ ctrl.touchUp();
+ }
+ return true;
+ }
+ @Override
+ public boolean scrolled(int amount)
+ {
+ cam.zoom(amount * ZOOM_SCROLL_FACTOR);
+ ctrl.hud.resize(cam.getHudLeft(), cam.getHudBottom(), cam.getHudWidth(), cam.getHudHeight());
+ return true;
+ }
+ });
+
+ return multiplexer;
+ }
+
+ @Override
+ public void render(float delta)
+ {
+ if (inputDelay > 0f) {
+ inputDelay -= delta;
+ if (inputDelay <= 0f)
+ blocked = false;
+ }
+
+ ctrl.hud.animate(delta);
+ ctrl.map.animate(delta);
+
+ Gdx.gl.glClearColor(0, 0, 0, 1);
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ // cam.update();
+ cam.applyMapViewport();
+ batch.setProjectionMatrix(cam.combined);
+ batch.begin();
+ ctrl.map.draw(batch);
+ batch.end();
+
+
+ if (DEBUG) {
+ Gdx.gl.glEnable(GL20.GL_BLEND);
+ debugShapes.setAutoShapeType(true);
+ debugShapes.setProjectionMatrix(cam.combined);
+ debugShapes.begin();
+ ctrl.map.drawDebug(debugShapes);
+ debugShapes.end();
+ }
+
+ cam.applyHudViewport();
+ batch.setProjectionMatrix(cam.getHudMatrix());
+ batch.begin();
+ ctrl.hud.draw(batch, DEBUG);
+ batch.end();
+
+ if (DEBUG) {
+ Gdx.gl.glEnable(GL20.GL_BLEND);
+ debugShapes.setAutoShapeType(true);
+ debugShapes.setProjectionMatrix(cam.getHudMatrix());
+ debugShapes.begin();
+ debugShapes.rect(cam.getHudLeft(), cam.getHudBottom(), cam.getHudWidth(), cam.getHudHeight());
+ ctrl.hud.drawDebug(debugShapes);
+ debugShapes.end();
+ }
+ }
+
+ @Override
+ public void resize(int width, int height)
+ {
+ // RustAndDust.debug("GameScreen", "resize (" + width + "," + height + ")");
+ cam.updateViewport(width, height);
+ ctrl.hud.resize(cam.getHudLeft(), cam.getHudBottom(), cam.getHudWidth(), cam.getHudHeight());
+ }
+
+ @Override
+ public void dispose()
+ {
+ // RustAndDust.debug("GameScreen", "dispose()");
+ batch.dispose();
+ ctrl.dispose();
+ if (DEBUG) debugShapes.dispose();
+ }
+
+ @Override
+ public void show()
+ {
+ // RustAndDust.debug("GameScreen", "show()");
+ }
+
+ @Override
+ public void hide()
+ {
+ // RustAndDust.debug("GameScreen", "hide()");
+ }
+
+ @Override
+ public void pause()
+ {
+ // RustAndDust.debug("GameScreen", "pause()");
+ }
+
+ @Override
+ public void resume()
+ {
+ // RustAndDust.debug("GameScreen", "resume()");
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/screens/MenuCamera.java b/core/src/ch/asynk/rustanddust/screens/MenuCamera.java
new file mode 100644
index 0000000..be8341a
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/screens/MenuCamera.java
@@ -0,0 +1,112 @@
+package ch.asynk.rustanddust.screens;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.OrthographicCamera;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.math.Matrix4;
+import com.badlogic.gdx.math.Rectangle;
+
+public class MenuCamera extends OrthographicCamera
+{
+ private static final float ZEROF = 0.01f;
+
+ private float virtualAspect;
+ private final Rectangle virtual;
+ private final Rectangle window;
+ private int hudLeft;
+ private int hudBottom;
+ private int hudCorrection;
+
+ private Matrix4 uiMatrix;
+ private Matrix4 uiInvProjMatrix;
+
+ public MenuCamera(int cx, int cy, int width, int height, int hudCorrection)
+ {
+ super(width, height);
+ this.virtual = new Rectangle();
+ this.virtual.set(cx, cy, width, height);
+ this.virtualAspect = (virtual.width / virtual.height);
+ this.window = new Rectangle();
+ this.window.set(0, 0, 0, 0);
+ this.position.set(virtual.x, virtual.y, 0f);
+ this.hudLeft = 0;
+ this.hudBottom = 0;
+ this.hudCorrection = hudCorrection;
+
+ this.uiMatrix = new Matrix4();
+ this.uiInvProjMatrix = new Matrix4();
+ }
+
+ 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);
+ }
+
+ window.width = screenWidth;
+ window.height = screenHeight;
+ hudLeft = hudCorrection;
+ hudBottom = (int) (hudLeft / aspect);
+
+ Gdx.gl.glViewport((int)window.x, (int)window.y, (int)window.width, (int)window.height);
+
+ update(true);
+
+ uiMatrix.setToOrtho2D(getHudLeft(), getHudBottom(), getHudWidth(), getHudHeight());
+ uiInvProjMatrix.set(uiMatrix);
+ Matrix4.inv(uiInvProjMatrix.val);
+ }
+
+ public float getScreenWidth()
+ {
+ return window.width;
+ }
+
+ public float getScreenHeight()
+ {
+ return window.height;
+ }
+
+ public int getHudLeft()
+ {
+ return hudLeft;
+ }
+
+ public int getHudBottom()
+ {
+ return hudBottom;
+ }
+
+ public int getHudWidth()
+ {
+ return (int) window.width - (2 * getHudLeft());
+ }
+
+ public int getHudHeight()
+ {
+ return (int) window.height - (2 * getHudBottom());
+ }
+
+ public void uiUnproject(float x, float y, Vector3 v)
+ {
+ x = x - window.x;
+ y = Gdx.graphics.getHeight() - y - 1;
+ y = y - window.y;
+ v.x = (2 * x) / window.width - 1;
+ v.y = (2 * y) / window.height - 1;
+ v.z = 2 * v.z - 1;
+ v.prj(uiInvProjMatrix);
+ }
+
+ public Matrix4 uiCombined()
+ {
+ return uiMatrix;
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/screens/MenuScreen.java b/core/src/ch/asynk/rustanddust/screens/MenuScreen.java
new file mode 100644
index 0000000..0ca8a63
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/screens/MenuScreen.java
@@ -0,0 +1,258 @@
+package ch.asynk.rustanddust.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 ch.asynk.rustanddust.RustAndDust;
+import ch.asynk.rustanddust.ui.Position;
+import ch.asynk.rustanddust.menu.MainMenu;
+import ch.asynk.rustanddust.menu.OptionsMenu;
+import ch.asynk.rustanddust.menu.ScenariosMenu;
+import ch.asynk.rustanddust.menu.TutorialsMenu;
+
+public class MenuScreen implements Screen
+{
+ private final RustAndDust 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 MainMenu mainMenu;
+ private OptionsMenu optionsMenu;
+ private ScenariosMenu scenariosMenu;
+ private TutorialsMenu tutorialsMenu;
+
+ private final MenuCamera camera;
+ private final SpriteBatch batch;
+ private Vector3 touch = new Vector3();
+
+ public MenuScreen(final RustAndDust game)
+ {
+ this.game = game;
+ this.batch = new SpriteBatch();
+
+ float width = Gdx.graphics.getWidth();
+ float height = Gdx.graphics.getHeight();
+
+ this.camera = new MenuCamera(V_CENTER_X, V_CENTER_Y, V_WIDTH, V_HEIGHT, game.hudCorrection);
+
+ 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.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);
+
+ this.game.config.battle = null;
+
+ Gdx.input.setInputProcessor(new InputAdapter() {
+ @Override
+ public boolean touchDown(int x, int y, int pointer, int button)
+ {
+ camera.uiUnproject(x, y, 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 (scenariosMenu.launch)
+ startLoading();
+ return true;
+ } else if (tutorialsMenu.hit(x, y)) {
+ mainMenu.visible = true;
+ tutorialsMenu.visible = false;
+ return true;
+ }
+
+ return false;
+ }
+
+ private void showNextMenu()
+ {
+ MainMenu.Items item = mainMenu.getMenu();
+
+ if (item == MainMenu.Items.OPTIONS)
+ optionsMenu.visible = true;
+ else if (item == MainMenu.Items.SCENARIOS)
+ scenariosMenu.visible = true;
+ else if (item == MainMenu.Items.TUTORIALS)
+ tutorialsMenu.visible = true;
+ }
+
+ private void startLoading()
+ {
+ mainMenu.visible = false;
+ game.loadGameAssets();
+ gameAssetsLoading = true;
+ }
+
+ private void gameAssetsLoadingCompleted()
+ {
+ RustAndDust.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(camera.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(camera.uiCombined());
+ batch.begin();
+ 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)
+ {
+ camera.updateViewport(width, height);
+ Position.update(camera.getHudLeft(), camera.getHudBottom(), camera.getHudWidth(), camera.getHudHeight());
+
+ 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()
+ {
+ 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()
+ {
+ // RustAndDust.debug("MenuScreen", "hide()");
+ }
+
+ @Override
+ public void pause()
+ {
+ // RustAndDust.debug("MenuScreen", "pause()");
+ }
+
+ @Override
+ public void resume()
+ {
+ // RustAndDust.debug("MenuScreen", "resume()");
+ }
+}