From 521b33232bba647b205e6f3b09af38b0b3153389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 1 Nov 2014 18:29:33 +0100 Subject: Msg: add pushWrite(...) wait for the previous messages to be disblayed --- core/src/ch/asynk/tankontank/game/hud/Msg.java | 37 ++++++++++++++++++++++++-- 1 file 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 stack; public Msg(BitmapFont font, TextureRegion region) { super(region); + this.visible = false; this.font = font; + this.stack = new ArrayDeque(); + } + + 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 -- cgit v1.1-2-g2b99