From 46b4ed747b7c6920a014acc931d99f0324be7db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 9 Nov 2014 00:41:05 +0100 Subject: Msg: extends Label, has a Bg --- core/src/ch/asynk/tankontank/game/hud/Msg.java | 79 ++++++++------------------ 1 file 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 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(); } @@ -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); } } -- cgit v1.1-2-g2b99