diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/zproject/Board.java | 10 | ||||
-rw-r--r-- | core/src/ch/asynk/zproject/Hud.java | 121 | ||||
-rw-r--r-- | core/src/ch/asynk/zproject/screens/GameScreen.java | 20 |
3 files changed, 116 insertions, 35 deletions
diff --git a/core/src/ch/asynk/zproject/Board.java b/core/src/ch/asynk/zproject/Board.java index 22b7e74..b7e20b8 100644 --- a/core/src/ch/asynk/zproject/Board.java +++ b/core/src/ch/asynk/zproject/Board.java @@ -4,7 +4,9 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.utils.Disposable; -public class Board implements Disposable +import ch.asynk.zproject.engine.Touchable; + +public class Board implements Disposable, Touchable { private final Texture map; @@ -18,6 +20,12 @@ public class Board implements Disposable map.dispose(); } + @Override public boolean touch(float x, float y) + { + ZProject.debug("Board", String.format("touchDown : %f %f", x, y)); + return true; + } + public int getWidth() { return map.getWidth(); diff --git a/core/src/ch/asynk/zproject/Hud.java b/core/src/ch/asynk/zproject/Hud.java index d013d7b..fd74ade 100644 --- a/core/src/ch/asynk/zproject/Hud.java +++ b/core/src/ch/asynk/zproject/Hud.java @@ -1,59 +1,116 @@ package ch.asynk.zproject; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.math.Rectangle; + +import ch.asynk.zproject.engine.ui.Button; +import ch.asynk.zproject.engine.ui.Patch; +import ch.asynk.zproject.engine.ui.Alignment; +import ch.asynk.zproject.engine.ui.Root; +import ch.asynk.zproject.engine.Touchable; -public class Hud implements Disposable +public class Hud implements Disposable, Touchable { private final Rectangle rect; - private final Sprite hud; - private final GlyphLayout glyphLayout; - private final BitmapFont font20; - private final BitmapFont font25; + private final Sprite corner; + private final Root root; + private final Button hello; + private final Button next; public Hud(final Assets assets) { - this.rect = new Rectangle(0, 0, 0, 0); - this.hud = new Sprite(assets.getTexture(assets.CORNER)); - this.glyphLayout = new GlyphLayout(); - font20 = assets.getFont(assets.FONT_20); - font25 = assets.getFont(assets.FONT_25); + this.corner = new Sprite(assets.getTexture(assets.CORNER)); + this.rect = new Rectangle(0, 0, 0 ,0); + + this.root = new Root(2); + this.root.setPadding(30); + + this.hello = new Button(assets.getFont(assets.FONT_25), assets.getNinePatch(assets.PATCH, 23, 23, 23 ,23), 10, 15); + this.hello.write("Hello"); + this.root.add(this.hello); + + this.next = new Button(assets.getFont(assets.FONT_25), assets.getNinePatch(assets.PATCH, 23, 23, 23 ,23), 20, 0); + this.next.write("NEXT"); + this.next.setPosition(100, 100); + this.root.add(this.next); } @Override public void dispose() { - hud.getTexture().dispose(); + corner.getTexture().dispose(); + } + + @Override public boolean touch(float x, float y) + { + if (rect.contains(x, y)) { + if (root.touch(x, y)) { + ZProject.debug("Hud", String.format("touchDown : %f %f", x, y)); + return true; + } + } + return false; } public void resize(float width, float height) { rect.set(0, 0, width, height); + this.root.resize(width, height); } public void draw(Batch batch) { - float right = rect.x + rect.width - hud.getWidth(); - float top = rect.y + rect.height - hud.getHeight(); - hud.setRotation(0); - hud.setPosition(rect.x, top); - hud.draw(batch); - hud.setRotation(90); - hud.setPosition(rect.x, rect.y); - hud.draw(batch); - hud.setRotation(180); - hud.setPosition(right, rect.y); - hud.draw(batch); - hud.setPosition(right, top); - hud.setRotation(270); - hud.draw(batch); - glyphLayout.setText(font20, "Hello"); - font20.draw(batch, glyphLayout, 60, 30); - glyphLayout.setText(font25, "worlD"); - font25.draw(batch, glyphLayout, 120, 32); + drawButtons(batch); + drawCorners(batch); + } + + public void drawCorners(Batch batch) + { + float right = rect.x + rect.width - corner.getWidth(); + float top = rect.y + rect.height - corner.getHeight(); + corner.setRotation(0); + corner.setPosition(rect.x, top); + corner.draw(batch); + corner.setRotation(90); + corner.setPosition(rect.x, rect.y); + corner.draw(batch); + corner.setRotation(180); + corner.setPosition(right, rect.y); + corner.draw(batch); + corner.setPosition(right, top); + corner.setRotation(270); + corner.draw(batch); + } + + private void drawButtons(Batch batch) + { + hello.setAlignment(Alignment.TOP_LEFT); + hello.setLabelAlignment(Alignment.BOTTOM_CENTER); + hello.update(); + root.draw(batch); + drawHello(batch, Alignment.TOP_CENTER, Alignment.BOTTOM_RIGHT); + drawHello(batch, Alignment.TOP_RIGHT, Alignment.TOP_LEFT); + drawHello(batch, Alignment.MIDDLE_LEFT, Alignment.TOP_CENTER); + drawHello(batch, Alignment.MIDDLE_CENTER, Alignment.TOP_RIGHT); + drawHello(batch, Alignment.MIDDLE_RIGHT, Alignment.MIDDLE_LEFT); + drawHello(batch, Alignment.BOTTOM_LEFT, Alignment.MIDDLE_CENTER); + drawHello(batch, Alignment.BOTTOM_CENTER, Alignment.MIDDLE_RIGHT); + drawHello(batch, Alignment.BOTTOM_RIGHT, Alignment.BOTTOM_LEFT); + } + + private void drawHello(Batch batch, Alignment alignment1, Alignment alignment2) + { + hello.setAlignment(alignment1); + hello.setLabelAlignment(alignment2); + hello.update(); + hello.draw(batch); + } + + public void drawDebug(ShapeRenderer debugShapes) + { + root.drawDebug(debugShapes); } } diff --git a/core/src/ch/asynk/zproject/screens/GameScreen.java b/core/src/ch/asynk/zproject/screens/GameScreen.java index 606c7c3..0fe6318 100644 --- a/core/src/ch/asynk/zproject/screens/GameScreen.java +++ b/core/src/ch/asynk/zproject/screens/GameScreen.java @@ -4,6 +4,7 @@ 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; @@ -23,11 +24,14 @@ public class GameScreen implements Screen 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 Hud hud; private final Board board; private final GameCamera camera; private final SpriteBatch batch; + private ShapeRenderer debugShapes = null; private final Vector2 dragPos = new Vector2(); private final Vector3 boardTouch = new Vector3(); @@ -48,6 +52,7 @@ public class GameScreen implements Screen this.paused = false; this.inputDelay = 0f; this.inputBlocked = false; + if (DEBUG) this.debugShapes = new ShapeRenderer(); } @Override public void render(float delta) @@ -74,6 +79,16 @@ public class GameScreen implements Screen 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) @@ -88,6 +103,7 @@ public class GameScreen implements Screen { ZProject.debug("GameScreen", "dispose()"); batch.dispose(); + if (debugShapes != null) debugShapes.dispose(); hud.dispose(); board.dispose(); } @@ -137,8 +153,8 @@ public class GameScreen implements Screen dragPos.set(x, y); camera.unproject(x, y, boardTouch); camera.unprojectHud(x, y, hudTouch); - ZProject.debug("touchDown MAP : " + boardTouch); - ZProject.debug("touchDown HUD : " + hudTouch); + if(!hud.touch(hudTouch.x, hudTouch.y)) + board.touch(boardTouch.x, boardTouch.y); } return true; } |