diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-02 11:51:56 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-02 11:51:56 +0200 |
commit | 589938042a1a77babf3f23482e03275949ea789a (patch) | |
tree | f87df3c848a778c35b6a0852e8aadf571080a381 /test/src/ch/asynk | |
parent | 9e6b127d1aad4dc9890b525b852ece2a3f9a2038 (diff) | |
download | gdx-boardgame-589938042a1a77babf3f23482e03275949ea789a.zip gdx-boardgame-589938042a1a77babf3f23482e03275949ea789a.tar.gz |
test : extract AbstractScreen from Board,Menu,UiScreen
Diffstat (limited to 'test/src/ch/asynk')
-rw-r--r-- | test/src/ch/asynk/gdx/tabletop/test/AbstractScreen.java | 168 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/tabletop/test/BoardScreen.java | 172 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/tabletop/test/MenuScreen.java | 162 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/tabletop/test/UiScreen.java | 156 |
4 files changed, 263 insertions, 395 deletions
diff --git a/test/src/ch/asynk/gdx/tabletop/test/AbstractScreen.java b/test/src/ch/asynk/gdx/tabletop/test/AbstractScreen.java new file mode 100644 index 0000000..0c81bfb --- /dev/null +++ b/test/src/ch/asynk/gdx/tabletop/test/AbstractScreen.java @@ -0,0 +1,168 @@ +package ch.asynk.gdx.tabletop.test; + +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.Camera; +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.gdx.tabletop.ui.Root; + +public abstract class AbstractScreen implements Screen +{ + protected final float WORLD_RATIO = 0.5f; + 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; + + protected final Vector2 dragPos = new Vector2(); + protected final Vector3 boardTouch = new Vector3(); + protected final Vector3 hudTouch = new Vector3(); + + protected final String dom; + protected final GdxBoardTest app; + protected final SpriteBatch batch; + protected final Texture bg; + protected final Root root; + protected Camera camera; + protected boolean inputBlocked; + protected float inputDelay; + protected boolean paused; + + protected abstract void feed(); + public AbstractScreen(final GdxBoardTest app, final String dom) + { + this.app = app; + this.dom = dom; + this.batch = new SpriteBatch(); + this.bg = app.assets.getTexture(app.assets.MAP_00); + this.root = new Root(1); + this.root.setPadding(15); + feed(); + Gdx.input.setInputProcessor(getMultiplexer()); + this.inputBlocked = false; + this.inputDelay = 0f; + this.paused = false; + } + + protected abstract void draw(SpriteBatch batch); + @Override public void render(float delta) + { + if (paused) return; + + Gdx.gl.glClearColor(1, 1, 1, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + camera.update(); + batch.setProjectionMatrix(camera.combined); + batch.begin(); + draw(batch); + batch.end(); + } + + @Override public void resize(int width, int height) + { + GdxBoardTest.debug(dom, String.format("resize (%d,%d)",width, height)); + if (width >= height) { + camera.viewportWidth = bg.getWidth(); + camera.viewportHeight = bg.getHeight() / (float)width * (float)height; + } else { + camera.viewportHeight = bg.getHeight(); + camera.viewportWidth = bg.getWidth() / (float)height * (float)width; + } + camera.viewportWidth *= WORLD_RATIO; + camera.viewportHeight *= WORLD_RATIO; + camera.update(); + root.resize( + camera.position.x - (camera.viewportWidth / 2f), + camera.position.y - (camera.viewportHeight / 2f), + camera.viewportWidth, + camera.viewportHeight + ); + } + + @Override public void dispose() + { + GdxBoardTest.debug(dom, "dispose()"); + batch.dispose(); + } + + @Override public void show() + { + GdxBoardTest.debug(dom, "show()"); + paused = false; + } + + @Override public void hide() + { + GdxBoardTest.debug(dom, "hide()"); + paused = true; + } + + @Override public void pause() + { + GdxBoardTest.debug(dom, "pause() "); + paused = true; + } + + @Override public void resume() + { + GdxBoardTest.debug(dom, "resume() "); + resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + paused = false; + } + + protected abstract void onTouch(int x, int y); + protected abstract void onZoom(float dz); + protected abstract void onDragged(int dx, int dy); + private InputMultiplexer getMultiplexer() + { + final InputMultiplexer multiplexer = new InputMultiplexer(); + multiplexer.addProcessor(new InputAdapter() { + @Override public boolean scrolled(int amount) + { + onZoom(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); + onTouch(x, 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); + onDragged(dx, dy); + return true; + } + }); + multiplexer.addProcessor(new GestureDetector(new GestureAdapter() { + @Override public boolean zoom(float initialDistance, float distance) + { + if (initialDistance > distance) + onZoom(ZOOM_GESTURE_FACTOR); + else + onZoom(-ZOOM_GESTURE_FACTOR); + inputBlocked = true; + inputDelay = INPUT_DELAY; + return true; + } + })); + + return multiplexer; + } +} diff --git a/test/src/ch/asynk/gdx/tabletop/test/BoardScreen.java b/test/src/ch/asynk/gdx/tabletop/test/BoardScreen.java index 3ef9dea..d52670c 100644 --- a/test/src/ch/asynk/gdx/tabletop/test/BoardScreen.java +++ b/test/src/ch/asynk/gdx/tabletop/test/BoardScreen.java @@ -1,29 +1,18 @@ package ch.asynk.gdx.tabletop.test; 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.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.gdx.tabletop.Camera; import ch.asynk.gdx.tabletop.Board; import ch.asynk.gdx.tabletop.board.BoardFactory; import ch.asynk.gdx.tabletop.ui.Button; -public class BoardScreen implements Screen +public class BoardScreen extends AbstractScreen { - private static final String DOM = "BoardScreen"; - 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; @@ -123,20 +112,6 @@ public class BoardScreen implements Screen } } - private final GdxBoardTest app; - private final MyBoard board; - private final Camera camera; - private final SpriteBatch batch; - private final Button btn; - - 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 enum State { HEX_V, HEX_H, SQUARE, TRI_H, TRI_V, DONE; @@ -160,24 +135,28 @@ public class BoardScreen implements Screen } private State state; + private Camera cam; + private MyBoard board; + private Button btn; + public BoardScreen(final GdxBoardTest app) { - this.app = app; + super(app, ""); + } + + @Override protected void feed() + { this.board = new MyBoard(app.assets); - this.batch = new SpriteBatch(); - this.camera = new Camera(10, board.w, board.h, 1.0f, 0.3f, false); + this.camera = this.cam = new Camera(10, board.w, board.h, 1.0f, 0.3f, false); this.btn = new Button( app.assets.getFont(app.assets.FONT_25), app.assets.getNinePatch(app.assets.PATCH, 23, 23, 23 ,23), 15); this.btn.write("next"); - Gdx.input.setInputProcessor(getMultiplexer(this)); setState(State.HEX_V); - this.inputBlocked = false; - this.inputDelay = 0f; - this.paused = false; } + @Override public void draw(SpriteBatch batch) { } @Override public void render(float delta) { if (paused) return; @@ -191,14 +170,14 @@ public class BoardScreen implements Screen Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - camera.applyMapViewport(); - batch.setProjectionMatrix(camera.combined); + cam.applyMapViewport(); + batch.setProjectionMatrix(cam.combined); batch.begin(); board.draw(batch); batch.end(); - camera.applyHudViewport(); - batch.setProjectionMatrix(camera.getHudMatrix()); + cam.applyHudViewport(); + batch.setProjectionMatrix(cam.getHudMatrix()); batch.begin(); btn.draw(batch); batch.end(); @@ -207,125 +186,46 @@ public class BoardScreen implements Screen @Override public void resize(int width, int height) { GdxBoardTest.debug("BoardScrean", String.format("resize (%d,%d)",width, height)); - camera.updateViewport(width, height); + cam.updateViewport(width, height); } - @Override public void dispose() + @Override protected void onDragged(int dx, int dy) { - GdxBoardTest.debug("BoardScrean", "dispose()"); - batch.dispose(); + cam.translate(dx, dy); } - @Override public void show() + @Override protected void onTouch(int x, int y) { - GdxBoardTest.debug("BoardScrean", "show()"); - paused = false; - } - - @Override public void hide() - { - GdxBoardTest.debug("BoardScrean", "hide()"); - paused = true; - } - - @Override public void pause() - { - GdxBoardTest.debug("pause() "); - paused = true; - } - - @Override public void resume() - { - GdxBoardTest.debug("resume() "); - resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - paused = false; + cam.unproject(x, y, boardTouch); + cam.unprojectHud(x, y, hudTouch); + if (btn.touch(hudTouch.x, hudTouch.y)) { + setState(state.next()); + } else { + board.touch(boardTouch.x, boardTouch.y); + } } - private void zoom(float dz) + @Override protected void onZoom(float dz) { - camera.zoom(dz); + cam.zoom(dz); resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } - private void nextState() - { - setState(this.state.next()); - } - private void setState(State state) { switch (state) { - case HEX_V: - board.setHEX_V(); - break; - case HEX_H: - board.setHEX_H(); - break; - case SQUARE: - board.setSQUARE(); - break; - case TRI_H: - board.setTRI_H(); - break; - case TRI_V: - board.setTRI_V(); - break; + case HEX_V: board.setHEX_V(); break; + case HEX_H: board.setHEX_H(); break; + case SQUARE: board.setSQUARE(); break; + case TRI_H: board.setTRI_H(); break; + case TRI_V: board.setTRI_V(); break; case DONE: this.app.switchToMenu(); return; } board.reset(); - this.camera.setDimension(board.w, board.h); - zoom(1); + cam.setDimension(board.w, board.h); + onZoom(1); this.state = state; } - - private InputMultiplexer getMultiplexer(final BoardScreen screen) - { - final InputMultiplexer multiplexer = new InputMultiplexer(); - multiplexer.addProcessor(new InputAdapter() { - @Override public boolean scrolled(int amount) - { - 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 (btn.touch(hudTouch.x, hudTouch.y)) { - nextState(); - } else { - 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/test/src/ch/asynk/gdx/tabletop/test/MenuScreen.java b/test/src/ch/asynk/gdx/tabletop/test/MenuScreen.java index 892182a..bf94e75 100644 --- a/test/src/ch/asynk/gdx/tabletop/test/MenuScreen.java +++ b/test/src/ch/asynk/gdx/tabletop/test/MenuScreen.java @@ -1,48 +1,27 @@ package ch.asynk.gdx.tabletop.test; -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.g2d.Sprite; import com.badlogic.gdx.graphics.OrthographicCamera; -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.math.Vector3; import ch.asynk.gdx.tabletop.ui.Alignment; import ch.asynk.gdx.tabletop.ui.Menu; -import ch.asynk.gdx.tabletop.ui.Root; -public class MenuScreen implements Screen +public class MenuScreen extends AbstractScreen { - private static final String DOM = "MenuScreen"; - - private final GdxBoardTest app; - private final OrthographicCamera cam; - private final SpriteBatch batch; - private final Texture bg; - private final Sprite corner; - private final Root root; - private final Menu menu; - private boolean paused; - - private final float WORLD_RATIO = 0.5f; - private final int PADDING = 15; - - private final Vector3 touch = new Vector3(); + private Sprite corner; + private Menu menu; public MenuScreen(final GdxBoardTest app) { - this.app = app; - this.batch = new SpriteBatch(); + super(app, "MenuScreen"); + } + + @Override protected void feed() + { final Assets assets = app.assets; - this.bg = assets.getTexture(assets.MAP_00); this.corner = new Sprite(assets.getTexture(assets.CORNER)); - this.root = new Root(1); this.menu = new Menu( assets.getFont(assets.FONT_25), assets.getNinePatch(assets.PATCH, 23, 23, 23 ,23), @@ -54,127 +33,54 @@ public class MenuScreen implements Screen this.menu.setLabelsOffset(10); this.root.add(this.menu); - this.cam = new OrthographicCamera(bg.getWidth() * WORLD_RATIO, bg.getHeight() * WORLD_RATIO); - this.cam.position.set(bg.getWidth() / 2f, bg.getHeight() / 2f, 0); - this.cam.update(); - - Gdx.input.setInputProcessor(getMultiplexer(this)); - this.paused = false; + this.camera = new OrthographicCamera(bg.getWidth() * WORLD_RATIO, bg.getHeight() * WORLD_RATIO); + this.camera.position.set(bg.getWidth() / 2f, bg.getHeight() / 2f, 0); + this.camera.update(); } - @Override public void render(float delta) + @Override protected void draw(SpriteBatch batch) { - if (paused) return; - - Gdx.gl.glClearColor(1, 1, 1, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - - cam.update(); - batch.setProjectionMatrix(cam.combined); - batch.begin(); batch.draw(bg, 0, 0); drawCorners(batch); root.draw(batch); - batch.end(); } private void drawCorners(SpriteBatch batch) { - float right = root.getX() + root.getWidth() - corner.getWidth(); - float top = root.getY() + root.getHeight() - corner.getHeight(); + float right = root.getInnerX() + root.getInnerWidth() - corner.getWidth(); + float top = root.getInnerY() + root.getInnerHeight() - corner.getHeight(); corner.setRotation(0); - corner.setPosition(root.getX(), top); + corner.setPosition(root.getInnerX(), top); corner.draw(batch); corner.setRotation(90); - corner.setPosition(root.getX(), root.getY()); + corner.setPosition(root.getInnerX(), root.getInnerY()); corner.draw(batch); corner.setRotation(180); - corner.setPosition(right, root.getY()); + corner.setPosition(right, root.getInnerY()); corner.draw(batch); corner.setPosition(right, top); corner.setRotation(270); corner.draw(batch); } - @Override public void resize(int width, int height) - { - GdxBoardTest.debug(DOM, String.format("resize (%d,%d)",width, height)); - if (width >= height) { - cam.viewportWidth = bg.getWidth(); - cam.viewportHeight = bg.getHeight() / (float)width * (float)height; - } else { - cam.viewportHeight = bg.getHeight(); - cam.viewportWidth = bg.getWidth() / (float)height * (float)width; - } - cam.viewportWidth *= WORLD_RATIO; - cam.viewportHeight *= WORLD_RATIO; - cam.update(); - root.resize( - cam.position.x - (cam.viewportWidth / 2f) + PADDING, - cam.position.y - (cam.viewportHeight / 2f) + PADDING, - cam.viewportWidth - 2 * PADDING, - cam.viewportHeight - 2 * PADDING - ); - } - - @Override public void dispose() - { - GdxBoardTest.debug(DOM, "dispose()"); - batch.dispose(); - } - - @Override public void show() - { - GdxBoardTest.debug(DOM, "show()"); - paused = false; - } - - @Override public void hide() + @Override protected void onZoom(float dz) { } + @Override protected void onDragged(int dx, int dy) { } + @Override protected void onTouch(int x, int y) { - GdxBoardTest.debug(DOM, "hide()"); - paused = true; - } - - @Override public void pause() - { - GdxBoardTest.debug(DOM, "pause() "); - paused = true; - } - - @Override public void resume() - { - GdxBoardTest.debug(DOM, "resume() "); - resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - paused = false; - } - - private InputMultiplexer getMultiplexer(final MenuScreen screen) - { - final InputMultiplexer multiplexer = new InputMultiplexer(); - multiplexer.addProcessor(new InputAdapter() { - @Override public boolean touchDown(int x, int y, int pointer, int button) - { - if (button == Input.Buttons.LEFT) { - touch.set(x, y, 0); - cam.unproject(touch); - if (root.touch(touch.x, touch.y)) { - switch(menu.touched()) { - case 0: - app.switchToUi(); - break; - case 1: - app.switchToBoard(); - break; - case 2: - app.switchToExit(); - break; - } - } - } - return true; + hudTouch.set(x, y, 0); + camera.unproject(hudTouch); + if (root.touch(hudTouch.x, hudTouch.y)) { + switch(menu.touched()) { + case 0: + app.switchToUi(); + break; + case 1: + app.switchToBoard(); + break; + case 2: + app.switchToExit(); + break; } - }); - - return multiplexer; + } } } diff --git a/test/src/ch/asynk/gdx/tabletop/test/UiScreen.java b/test/src/ch/asynk/gdx/tabletop/test/UiScreen.java index 87eb220..261d461 100644 --- a/test/src/ch/asynk/gdx/tabletop/test/UiScreen.java +++ b/test/src/ch/asynk/gdx/tabletop/test/UiScreen.java @@ -1,39 +1,21 @@ package ch.asynk.gdx.tabletop.test; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.Screen; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.NinePatch; -import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.OrthographicCamera; -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.math.Vector3; import ch.asynk.gdx.tabletop.ui.Alignment; import ch.asynk.gdx.tabletop.ui.Button; -import ch.asynk.gdx.tabletop.ui.Root; -public class UiScreen implements Screen +public class UiScreen extends AbstractScreen { - private static final String DOM = "UiScreen"; + private Button hello; - private final GdxBoardTest app; - private final OrthographicCamera cam; - private final SpriteBatch batch; - private final Texture bg; - private final Root root; - private final Button hello; - private boolean paused; - - private final float WORLD_RATIO = 0.5f; - private final float PADDING = 15f; - - private final Vector3 touch = new Vector3(); + public UiScreen(final GdxBoardTest app) + { + super(app, "UiScreen"); + } public enum State { @@ -50,44 +32,31 @@ public class UiScreen implements Screen } private State state; - public UiScreen(final GdxBoardTest app) + @Override protected void feed() { - this.app = app; - this.batch = new SpriteBatch(); - this.bg = app.assets.getTexture(app.assets.MAP_00); - final NinePatch patch = app.assets.getNinePatch(app.assets.PATCH, 23, 23, 23 ,23); final BitmapFont font = app.assets.getFont(app.assets.FONT_25); - this.root = new Root(1); this.hello = new Button(font, patch, 10, 15); this.hello.write("Hello"); this.root.add(this.hello); - this.cam = new OrthographicCamera(bg.getWidth() * WORLD_RATIO, bg.getHeight() * WORLD_RATIO); - this.cam.position.set(bg.getWidth() / 2f, bg.getHeight() / 2f, 0); - this.cam.update(); - - Gdx.input.setInputProcessor(getMultiplexer()); - this.paused = false; + this.camera = new OrthographicCamera(bg.getWidth() * WORLD_RATIO, bg.getHeight() * WORLD_RATIO); + this.camera.position.set(bg.getWidth() / 2f, bg.getHeight() / 2f, 0); + this.camera.update(); setState(State.POSITIONS); } - @Override public void render(float delta) + private void setState(State state) { - if (paused) return; - - Gdx.gl.glClearColor(1, 1, 1, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - - cam.update(); - batch.setProjectionMatrix(cam.combined); - batch.begin(); - draw(batch); - batch.end(); + switch (state) { + case DONE: + app.switchToMenu(); + } + this.state = state; } - private void draw(Batch batch) + @Override protected void draw(SpriteBatch batch) { batch.draw(bg, 0, 0); switch (state) { @@ -97,7 +66,7 @@ public class UiScreen implements Screen } } - private void drawButtons(Batch batch) + private void drawButtons(SpriteBatch batch) { hello.write("hello"); hello.setAlignment(Alignment.TOP_LEFT); @@ -114,96 +83,21 @@ public class UiScreen implements Screen drawHello(batch, Alignment.MIDDLE_CENTER, Alignment.MIDDLE_CENTER); } - private void drawHello(Batch batch, Alignment alignment1, Alignment alignment2) + private void drawHello(SpriteBatch batch, Alignment alignment1, Alignment alignment2) { hello.setAlignment(alignment1); hello.setLabelAlignment(alignment2); hello.draw(batch); } - @Override public void resize(int width, int height) - { - GdxBoardTest.debug(DOM, String.format("resize (%d,%d)",width, height)); - if (width >= height) { - cam.viewportWidth = bg.getWidth(); - cam.viewportHeight = bg.getHeight() / (float)width * (float)height; - } else { - cam.viewportHeight = bg.getHeight(); - cam.viewportWidth = bg.getWidth() / (float)height * (float)width; - } - cam.viewportWidth *= WORLD_RATIO; - cam.viewportHeight *= WORLD_RATIO; - cam.update(); - root.resize( - cam.position.x - (cam.viewportWidth / 2f) + PADDING, - cam.position.y - (cam.viewportHeight / 2f) + PADDING, - cam.viewportWidth - 2 * PADDING, - cam.viewportHeight - 2 * PADDING - ); - } - - @Override public void dispose() - { - GdxBoardTest.debug(DOM, "dispose()"); - batch.dispose(); - } - - @Override public void show() + @Override protected void onZoom(float dz) { } + @Override protected void onDragged(int dx, int dy) { } + @Override protected void onTouch(int x, int y) { - GdxBoardTest.debug(DOM, "show()"); - paused = false; - } - - @Override public void hide() - { - GdxBoardTest.debug(DOM, "hide()"); - paused = true; - } - - @Override public void pause() - { - GdxBoardTest.debug(DOM, "pause() "); - paused = true; - } - - @Override public void resume() - { - GdxBoardTest.debug(DOM, "resume() "); - resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - paused = false; - } - - private void touch() - { - if (root.touch(touch.x, touch.y)) { + hudTouch.set(x, y, 0); + camera.unproject(hudTouch); + if (root.touch(hudTouch.x, hudTouch.y)) { setState(state.next()); } } - - private InputMultiplexer getMultiplexer() - { - final InputMultiplexer multiplexer = new InputMultiplexer(); - multiplexer.addProcessor(new InputAdapter() { - @Override public boolean touchDown(int x, int y, int pointer, int button) - { - if (button == Input.Buttons.LEFT) { - touch.set(x, y, 0); - cam.unproject(touch); - touch(); - } - return true; - } - }); - - return multiplexer; - } - - private void setState(State state) - { - switch (state) { - case DONE: - app.switchToMenu(); - } - this.state = state; - } } |