diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-01 18:29:33 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-01 18:29:33 +0100 |
commit | 521b33232bba647b205e6f3b09af38b0b3153389 (patch) | |
tree | 5a89ee7e14d4ce7c7746f4697fe70098010e4703 | |
parent | c4be9c25300236d6a67cf1f65236a011bfab90b3 (diff) | |
download | RustAndDust-521b33232bba647b205e6f3b09af38b0b3153389.zip RustAndDust-521b33232bba647b205e6f3b09af38b0b3153389.tar.gz |
Msg: add pushWrite(...) wait for the previous messages to be disblayed
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/Msg.java | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Msg.java b/core/src/ch/asynk/tankontank/game/hud/Msg.java index 885b395..0dcd3e7 100644 --- a/core/src/ch/asynk/tankontank/game/hud/Msg.java +++ b/core/src/ch/asynk/tankontank/game/hud/Msg.java @@ -1,5 +1,7 @@ package ch.asynk.tankontank.game.hud; +import java.util.ArrayDeque; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -8,6 +10,19 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds; public class Msg extends Bg { + 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 BitmapFont font; private String text; private int padding; @@ -16,11 +31,23 @@ public class Msg extends Bg private float duration; private float elapsed; private boolean visible; + private ArrayDeque<MsgInfo> stack; public Msg(BitmapFont font, TextureRegion region) { super(region); + this.visible = false; this.font = font; + this.stack = new ArrayDeque<MsgInfo>(); + } + + public void pushWrite(String text, float duration, Position position) + { + if (visible) { + stack.push(new MsgInfo(text, duration, position)); + return; + } else + write(text, duration, position); } public void write(String text, float duration, Position position) @@ -48,8 +75,14 @@ public class Msg extends Bg { if (!visible) return; elapsed += delta; - if (elapsed >= duration) - visible = false; + if (elapsed >= duration) { + visible = false; + if (stack.size() > 0) { + MsgInfo info = stack.pop(); + System.err.println(info); + write(info.text, info.duration, info.position); + } + } } @Override |