diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank/ui/Msg.java')
-rw-r--r-- | core/src/ch/asynk/tankontank/ui/Msg.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/ui/Msg.java b/core/src/ch/asynk/tankontank/ui/Msg.java new file mode 100644 index 0000000..c2069b7 --- /dev/null +++ b/core/src/ch/asynk/tankontank/ui/Msg.java @@ -0,0 +1,79 @@ +package ch.asynk.tankontank.ui; + +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +public class Msg extends Patch +{ + private LabelStack label; + + public Msg(BitmapFont font, TextureAtlas atlas) + { + super(atlas.createPatch("typewriter")); + label = new LabelStack(font, 20f); + } + + @Override + public void dispose() + { + super.dispose(); + label.dispose(); + } + + public void updatePosition() + { + if (!visible) return; + float dx = (position.getX(rect.width) - rect.x); + float dy = (position.getY(rect.height) - rect.y); + translate(dx, dy); + label.translate(dx, dy); + } + + public void write(String text, float duration) + { + label.write(text, duration); + resize(); + } + + public void write(String text, float duration, Position position) + { + this.position = position; + label.write(text, duration, position); + resize(); + } + + public void pushWrite(String text, float duration, Position position) + { + this.position = position; + label.pushWrite(text, duration, position); + resize(); + } + + private void resize() + { + setPosition(label.getX(), label.getY(), label.getWidth(), label.getHeight()); + } + + public boolean animate(float delta) + { + return label.animate(delta); + } + + @Override + public void draw(Batch batch) + { + if (!label.visible) return; + super.draw(batch); + label.draw(batch); + } + + @Override + public void drawDebug(ShapeRenderer shapes) + { + if (!label.visible) return; + super.drawDebug(shapes); + label.drawDebug(shapes); + } +} |