summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/zproject/GameHud.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-09-13 16:12:03 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-09-13 16:12:03 +0200
commitfa8345b7c6c7c22620117f34ef9fbd63f1004b41 (patch)
tree9e69ebc092f194c261cc73203957c3e48783dd54 /core/src/ch/asynk/zproject/GameHud.java
parent43147c8440ca5bc0b81e01d14f487811f18d093b (diff)
downloadgdx-boardgame-fa8345b7c6c7c22620117f34ef9fbd63f1004b41.zip
gdx-boardgame-fa8345b7c6c7c22620117f34ef9fbd63f1004b41.tar.gz
Game : add a State, drive board and hud with it
Diffstat (limited to 'core/src/ch/asynk/zproject/GameHud.java')
-rw-r--r--core/src/ch/asynk/zproject/GameHud.java53
1 files changed, 49 insertions, 4 deletions
diff --git a/core/src/ch/asynk/zproject/GameHud.java b/core/src/ch/asynk/zproject/GameHud.java
index 631a53c..38b2551 100644
--- a/core/src/ch/asynk/zproject/GameHud.java
+++ b/core/src/ch/asynk/zproject/GameHud.java
@@ -1,5 +1,7 @@
package ch.asynk.zproject;
+import java.util.function.Supplier;
+
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@@ -16,9 +18,13 @@ public class GameHud implements Disposable, Touchable
private final Root root;
private final Button hello;
private final Button next;
+ private GameScreen.State state;
+ private final Supplier<GameScreen.State> nextState;
- public GameHud(final Assets assets)
+ public GameHud(final Assets assets, GameScreen.State state, Supplier<GameScreen.State> nextState)
{
+ this.state = state;
+ this.nextState = nextState;
this.corner = new Sprite(assets.getTexture(assets.CORNER));
this.root = new Root(2);
@@ -45,6 +51,8 @@ public class GameHud implements Disposable, Touchable
{
if (root.touch(x, y)) {
ZProject.debug("GameHud", String.format("touchDown : %f %f", x, y));
+ if (root.touched() == this.next)
+ onNext();
return true;
}
return false;
@@ -55,13 +63,50 @@ public class GameHud implements Disposable, Touchable
this.root.resize(width, height);
}
+ public void onNext()
+ {
+ this.state = nextState.get();
+ switch (this.state) {
+ case UI:
+ updateNext(50, Alignment.MIDDLE_CENTER);
+ this.root.add(this.hello);
+ break;
+ case HEX_V:
+ updateNext(0, Alignment.BOTTOM_RIGHT);
+ this.root.remove(this.hello);
+ break;
+ case HEX_H:
+ break;
+ }
+ }
+
+ private void updateNext(int p, Alignment a)
+ {
+ this.next.setPosition(p, p);
+ this.next.setAlignment(a);
+ this.next.update();
+ }
+
public void draw(Batch batch)
{
- drawButtons(batch);
- drawCorners(batch);
+ switch (this.state) {
+ case UI:
+ drawButtons(batch);
+ drawCorners(batch);
+ break;
+ case HEX_V:
+ case HEX_H:
+ drawRoot(batch);
+ break;
+ }
+ }
+
+ private void drawRoot(Batch batch)
+ {
+ root.draw(batch);
}
- public void drawCorners(Batch batch)
+ private void drawCorners(Batch batch)
{
float right = root.getX() + root.getWidth() - corner.getWidth();
float top = root.getY() + root.getHeight() - corner.getHeight();