summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-12-17 16:10:01 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-12-17 16:10:01 +0100
commit83b0bae55041d0fff8a21c73ac94613de68742ac (patch)
tree396d0fe3293e9a1e784c98275411133ea53c999a /core
parentc994a0f9d51a1bbb2bff20ebcb4b4a630f310ce6 (diff)
downloadRustAndDust-83b0bae55041d0fff8a21c73ac94613de68742ac.zip
RustAndDust-83b0bae55041d0fff8a21c73ac94613de68742ac.tar.gz
add /LabelStack
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/LabelStack.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/LabelStack.java b/core/src/ch/asynk/tankontank/game/hud/LabelStack.java
new file mode 100644
index 0000000..cbdcacf
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/hud/LabelStack.java
@@ -0,0 +1,72 @@
+package ch.asynk.tankontank.game.hud;
+
+import java.util.ArrayDeque;
+
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+
+import ch.asynk.tankontank.engine.gfx.Animation;
+
+public class LabelStack extends Label implements Animation
+{
+ class MsgInfo
+ {
+ String text;
+ float duration;
+ Position position;
+ MsgInfo(String text, float duration, Position position)
+ {
+ this.text = text;
+ this.duration = duration;
+ this.position = position;
+ }
+ }
+
+ private float duration;
+ private float elapsed;
+ private ArrayDeque<MsgInfo> stack;
+
+ public LabelStack(BitmapFont font, float padding)
+ {
+ super(font, padding);
+ this.visible = false;
+ this.stack = new ArrayDeque<MsgInfo>();
+ }
+
+ public void pushWrite(String text, float duration, Position position)
+ {
+ if (visible)
+ stack.push(new MsgInfo(text, duration, position));
+ else
+ write(text, duration, position);
+ }
+
+ public void write(String text, float duration, Position position)
+ {
+ this.position = position;
+ write(text, duration);
+ }
+
+ public void write(String text, float duration)
+ {
+ this.duration = duration;
+ this.visible = true;
+ this.elapsed = 0f;
+ write(text);
+ }
+
+ @Override
+ public boolean animate(float delta)
+ {
+ if (!visible) return true;
+ elapsed += delta;
+ if (elapsed >= duration) {
+ visible = false;
+ if (stack.size() > 0) {
+ MsgInfo info = stack.pop();
+ write(info.text, info.duration, info.position);
+ }
+ }
+ return false;
+ }
+}