summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/zproject/screens
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-09-13 12:13:26 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-09-13 12:13:26 +0200
commitfb31fdbca6537a9d23baeb038bd395b7f332c21c (patch)
treef662656e4a7d121a199a006d8a7ab06c4d451537 /core/src/ch/asynk/zproject/screens
parentb4fe20c457a33c78a52180d0ca07dd5ccda3789a (diff)
downloadgdx-boardgame-fb31fdbca6537a9d23baeb038bd395b7f332c21c.zip
gdx-boardgame-fb31fdbca6537a9d23baeb038bd395b7f332c21c.tar.gz
remove screens dir
Diffstat (limited to 'core/src/ch/asynk/zproject/screens')
-rw-r--r--core/src/ch/asynk/zproject/screens/GameScreen.java186
-rw-r--r--core/src/ch/asynk/zproject/screens/LoadingScreen.java168
2 files changed, 0 insertions, 354 deletions
diff --git a/core/src/ch/asynk/zproject/screens/GameScreen.java b/core/src/ch/asynk/zproject/screens/GameScreen.java
deleted file mode 100644
index a784acc..0000000
--- a/core/src/ch/asynk/zproject/screens/GameScreen.java
+++ /dev/null
@@ -1,186 +0,0 @@
-package ch.asynk.zproject.screens;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.Screen;
-import com.badlogic.gdx.graphics.GL20;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
-import com.badlogic.gdx.graphics.Texture;
-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.math.Vector2;
-import com.badlogic.gdx.math.Vector3;
-
-import ch.asynk.zproject.ZProject;
-import ch.asynk.zproject.GameHud;
-import ch.asynk.zproject.GameBoard;
-import ch.asynk.zproject.engine.Camera;
-
-public class GameScreen implements Screen
-{
- private static final float INPUT_DELAY = 0.1f; // filter out touches after gesture
- private static final float ZOOM_SCROLL_FACTOR = .1f;
- private static final float ZOOM_GESTURE_FACTOR = .01f;
-
- private static final boolean DEBUG = true;
-
- private final ZProject zproject;
- private final GameHud hud;
- private final GameBoard board;
- private final Camera camera;
- private final SpriteBatch batch;
- private ShapeRenderer debugShapes = null;
-
- private final Vector2 dragPos = new Vector2();
- private final Vector3 boardTouch = new Vector3();
- private final Vector3 hudTouch = new Vector3();
-
- private boolean paused;
- private float inputDelay;
- private boolean inputBlocked;
-
- public GameScreen(final ZProject zproject)
- {
- this.zproject = zproject;
- this.hud = new GameHud(zproject.assets);
- this.board = new GameBoard(zproject.assets);
- this.batch = new SpriteBatch();
- this.camera = new Camera(10, board.getWidth(), board.getHeight(), 1.0f, 0.3f, false);
- Gdx.input.setInputProcessor(getMultiplexer(this));
- this.paused = false;
- this.inputDelay = 0f;
- this.inputBlocked = false;
- if (DEBUG) this.debugShapes = new ShapeRenderer();
- }
-
- @Override public void render(float delta)
- {
- if (paused) return;
-
- if (inputBlocked) {
- inputDelay -= delta;
- if (inputDelay <= 0f)
- inputBlocked = false;
- }
-
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-
- camera.applyMapViewport();
- batch.setProjectionMatrix(camera.combined);
- batch.begin();
- board.draw(batch);
- batch.end();
-
- camera.applyHudViewport();
- batch.setProjectionMatrix(camera.getHudMatrix());
- batch.begin();
- hud.draw(batch);
- batch.end();
-
- if (DEBUG) {
- Gdx.gl.glEnable(GL20.GL_BLEND);
- debugShapes.setAutoShapeType(true);
- debugShapes.setProjectionMatrix(camera.getHudMatrix());
- debugShapes.begin();
- hud.drawDebug(debugShapes);
- debugShapes.end();
- }
-
- }
-
- @Override public void resize(int width, int height)
- {
- if (paused) return;
- ZProject.debug("GameScreen", String.format("resize (%d,%d)",width, height));
- camera.updateViewport(width, height);
- hud.resize(camera.getHud().width, camera.getHud().height);
- }
-
- @Override public void dispose()
- {
- ZProject.debug("GameScreen", "dispose()");
- batch.dispose();
- if (debugShapes != null) debugShapes.dispose();
- hud.dispose();
- board.dispose();
- }
-
- @Override public void show()
- {
- ZProject.debug("GameScreen", "show()");
- }
-
- @Override public void hide()
- {
- ZProject.debug("GameScreen", "hide()");
- }
-
- @Override public void pause()
- {
- ZProject.debug("pause() ");
- paused = true;
- }
-
- @Override public void resume()
- {
- ZProject.debug("resume() ");
- paused = false;
- resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- }
-
- private void zoom(float dz)
- {
- camera.zoom(dz);
- resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- }
-
- private InputMultiplexer getMultiplexer(final GameScreen screen)
- {
- final InputMultiplexer multiplexer = new InputMultiplexer();
- multiplexer.addProcessor(new InputAdapter() {
- @Override public boolean scrolled(int amount)
- {
- screen.zoom(amount * ZOOM_SCROLL_FACTOR);
- return true;
- }
- @Override public boolean touchDown(int x, int y, int pointer, int button)
- {
- if (inputBlocked) return true;
- if (button == Input.Buttons.LEFT) {
- dragPos.set(x, y);
- camera.unproject(x, y, boardTouch);
- camera.unprojectHud(x, y, hudTouch);
- if(!hud.touch(hudTouch.x, hudTouch.y))
- board.touch(boardTouch.x, boardTouch.y);
- }
- return true;
- }
- @Override public boolean touchDragged(int x, int y, int pointer)
- {
- int dx = (int) (dragPos.x - x);
- int dy = (int) (dragPos.y - y);
- dragPos.set(x, y);
- camera.translate(dx, dy);
- return true;
- }
- });
- multiplexer.addProcessor(new GestureDetector(new GestureAdapter() {
- @Override public boolean zoom(float initialDistance, float distance)
- {
- if (initialDistance > distance)
- screen.zoom(ZOOM_GESTURE_FACTOR);
- else
- screen.zoom(-ZOOM_GESTURE_FACTOR);
- inputBlocked = true;
- inputDelay = INPUT_DELAY;
- return true;
- }
- }));
-
- return multiplexer;
- }
-}
diff --git a/core/src/ch/asynk/zproject/screens/LoadingScreen.java b/core/src/ch/asynk/zproject/screens/LoadingScreen.java
deleted file mode 100644
index 598beb9..0000000
--- a/core/src/ch/asynk/zproject/screens/LoadingScreen.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package ch.asynk.zproject.screens;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.Screen;
-import com.badlogic.gdx.graphics.GL20;
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.graphics.OrthographicCamera;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
-
-import ch.asynk.zproject.ZProject;
-
-public class LoadingScreen implements Screen
-{
- private final ZProject zproject;
- private final SpriteBatch batch;
- private final Color c;
- private final OrthographicCamera camera;
-
- private final float BLINK_AFTER = 2f;
- private final float ALPHA_FACTOR = 1.5f;
-
- private boolean paused;
- private TextureAtlas atlas;
- private AtlasRegion bar;
- private AtlasRegion border;
- private AtlasRegion loading;
- private AtlasRegion loaded;
-
- private int x, y;
- private int count;
- private float percent;
- private float alpha;
- private boolean incr;
- private boolean isLoaded;
-
- public interface LoadAction {
- void call();
- }
- private LoadAction onLoaded;
-
- public LoadingScreen(final ZProject zproject, LoadAction startLoading, LoadAction onLoaded)
- {
- this.zproject = zproject;
- this.onLoaded = onLoaded;
- this.batch = new SpriteBatch();
- this.c = batch.getColor();
- this.camera = new OrthographicCamera();
- int w = Gdx.graphics.getWidth();
- int h = Gdx.graphics.getHeight();
- this.camera.setToOrtho(false, w, h);
- this.camera.update();
- this.paused = false;
- atlas = zproject.assets.getAtlas(zproject.assets.LOADING);
- bar = atlas.findRegion("bar");
- border = atlas.findRegion("border");
- loading = atlas.findRegion("loading");
- loaded = atlas.findRegion("loaded");
- computeCoords(w, h);
- percent = 0f;
- alpha = 1f;
- incr = false;
- isLoaded = false;
- startLoading.call();
- }
-
- private void computeCoords(int width, int height)
- {
- x = (width - border.getRegionWidth()) / 2;
- y = (height - border.getRegionHeight()) / 2;
- }
-
- @Override public void render(float delta)
- {
- if (paused) return;
-
- if (!isLoaded) {
- if (zproject.assets.update()) {
- ZProject.debug("LoadingScreen", "assets loaded");
- isLoaded = true;
- percent = 1f;
- } else {
- percent = zproject.assets.getProgress();
- }
- }
-
- if (!isLoaded && percent >= 1f) {
- count = 0;
- alpha = 1f;
- incr = false;
- }
-
- delta *= ALPHA_FACTOR;
- if (incr) {
- alpha += delta;
- if (alpha >= 1f ) {
- alpha = 1f;
- incr = false;
- if (isLoaded) count += 1;
- if (count >= BLINK_AFTER) {
- onLoaded.call();
- return;
- }
- }
- } else {
- alpha -= delta;
- if (alpha <= 0f ) {
- alpha = 0f;
- incr = true;
- }
- }
-
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-
- batch.setProjectionMatrix(camera.combined);
- batch.begin();
- batch.setColor(c.r, c.g, c.b, 1f);
- batch.draw(border, x, y);
- batch.draw(bar, x + 4, y + 4, percent * bar.getRegionWidth(), bar.getRegionHeight());
- batch.setColor(c.r, c.g, c.b, alpha);
- if (!isLoaded) {
- batch.draw(loading, x, y + border.getRegionHeight() + 3);
- } else {
- batch.draw(loaded, x + border.getRegionWidth() - loaded.getRegionWidth(), y - loaded.getRegionHeight() - 3);
- }
- batch.end();
- }
-
- @Override public void resize(int width, int height)
- {
- if (paused) return;
- ZProject.debug("LoadingScreen", String.format("resize (%d,%d)",width, height));
- this.camera.setToOrtho(false, width, height);
- this.camera.update();
- computeCoords(width, height);
- }
-
- @Override public void dispose()
- {
- ZProject.debug("LoadingScreen", "dispose()");
- batch.dispose();
- }
-
- @Override public void show()
- {
- ZProject.debug("LoadingScreen", "show()");
- }
-
- @Override public void hide()
- {
- ZProject.debug("LoadingScreen", "hide()");
- }
-
- @Override public void pause()
- {
- paused = true;
- ZProject.debug("pause() ");
- }
-
- @Override public void resume()
- {
- ZProject.debug("resume() ");
- resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- paused = false;
- }
-}