diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-09 00:41:05 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-09 00:41:05 +0100 |
commit | 46b4ed747b7c6920a014acc931d99f0324be7db6 (patch) | |
tree | 0b7b93fdb9d03e66bf0ffec51cc1593a00501598 | |
parent | 311fdfb51e5d560377c449d31e7dc546da566a7f (diff) | |
download | RustAndDust-46b4ed747b7c6920a014acc931d99f0324be7db6.zip RustAndDust-46b4ed747b7c6920a014acc931d99f0324be7db6.tar.gz |
Msg: extends Label, has a Bg
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/Msg.java | 79 |
1 files changed, 24 insertions, 55 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Msg.java b/core/src/ch/asynk/tankontank/game/hud/Msg.java index 765a429..5675016 100644 --- a/core/src/ch/asynk/tankontank/game/hud/Msg.java +++ b/core/src/ch/asynk/tankontank/game/hud/Msg.java @@ -5,11 +5,9 @@ import java.util.ArrayDeque; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import ch.asynk.tankontank.TankOnTank; - -public class Msg extends Bg +public class Msg extends Label { class MsgInfo { @@ -24,21 +22,16 @@ public class Msg extends Bg } } - private BitmapFont font; - private String text; - private int padding; - private float x; - private float y; + private Bg bg; private float duration; private float elapsed; - private boolean visible; private ArrayDeque<MsgInfo> stack; - public Msg(BitmapFont font, TextureRegion region) + public Msg(BitmapFont font, TextureRegion region, float padding) { - super(region); + super(font, padding); this.visible = false; - this.font = font; + this.bg = new Bg(region); this.stack = new ArrayDeque<MsgInfo>(); } @@ -46,65 +39,34 @@ public class Msg extends Bg public void dispose() { super.dispose(); - font.dispose(); - } - - public float getX() - { - return x; - } - - public float getY() - { - return y; + bg.dispose(); } public void pushWrite(String text, float duration, Position position) { - if (visible) { + if (visible) stack.push(new MsgInfo(text, duration, position)); - return; - } else + else write(text, duration, position); } public void write(String text, float duration, Position position) { - TextBounds b = font.getBounds(text); - float w = b.width + (2 * padding); - float h = b.height + (2 * padding); - write(text, position.getX(w), position.getY(h), duration, 10); - } - - public void setTopLeft(float x, float y, int padding) - { - TextBounds b = font.getBounds("A"); - this.x = x; - this.y = (y - (2 * padding) - b.height); - this.padding = padding; - } - - public void write(String text, float duration) - { - this.text = text; this.duration = duration; this.visible = true; this.elapsed = 0f; - TextBounds b = font.getBounds(text); - set(x, y, (b.width + (padding * 2)), (b.height + (padding * 2))); + write(text); + setPosition(position.getX(getWidth()), position.getY(getHeight())); + bg.set(rect); } - public void write(String text, float x, float y, float duration, int padding) + public void write(String text, float duration) { - this.text = text; - this.x = x; - this.y = y; this.duration = duration; - this.padding = padding; this.visible = true; this.elapsed = 0f; - TextBounds b = font.getBounds(text); - set(x, y, (b.width + (padding * 2)), (b.height + (padding * 2))); + write(text); + bg.set(rect); } public void animate(float delta) @@ -115,7 +77,6 @@ public class Msg extends Bg visible = false; if (stack.size() > 0) { MsgInfo info = stack.pop(); - TankOnTank.debug(info.text); write(info.text, info.duration, info.position); } } @@ -125,7 +86,15 @@ public class Msg extends Bg public void draw(Batch batch) { if (!visible) return; + bg.draw(batch); super.draw(batch); - font.draw(batch, text, (x + padding), (rect.y + rect.height - padding)); + } + + @Override + public void drawDebug(ShapeRenderer shapes) + { + if (!visible) return; + super.drawDebug(shapes); + bg.drawDebug(shapes); } } |