diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/OkCancel.java (renamed from core/src/ch/asynk/tankontank/game/hud/Dialog.java) | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Dialog.java b/core/src/ch/asynk/tankontank/game/hud/OkCancel.java index ee9c62c..45fb572 100644 --- a/core/src/ch/asynk/tankontank/game/hud/Dialog.java +++ b/core/src/ch/asynk/tankontank/game/hud/OkCancel.java @@ -4,36 +4,34 @@ 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.g2d.TextureRegion; -import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.tankontank.engine.gfx.Image; -public class Dialog extends Bg +public class OkCancel extends Bg { - public boolean visible; public boolean ok; - public int padding; - private Label label; - private Image okBtn; - private Image cancelBtn; + public float padding; + protected Label label; + protected Image okBtn; + protected Image cancelBtn; - public Dialog(BitmapFont font, TextureRegion region, TextureAtlas atlas) + public OkCancel(BitmapFont font, TextureRegion region, TextureAtlas atlas, float padding) { super(region); - this.label = new Label(font, "hello"); + this.label = new Label(font); this.okBtn = new Image(atlas.findRegion("ok")); this.cancelBtn = new Image(atlas.findRegion("cancel")); this.visible = false; - this.padding = 10; + this.padding = padding; } public void show(String msg, Position position) { label.write(msg); - TextBounds b = label.getBounds(); - float height = (b.height + (3 * padding) + okBtn.getHeight()); - float width = (b.width + (2 * padding)); + float height = (label.getHeight() + (4 * padding) + okBtn.getHeight()); + float width = (label.getWidth() + (2 * padding)); float w2 = ((3 * padding) + okBtn.getWidth() + cancelBtn.getWidth()); if (w2 > width) width = w2; @@ -42,7 +40,7 @@ public class Dialog extends Bg set(x, y, width, height); okBtn.setPosition((x + width - okBtn.getWidth() - padding), (y + padding)); cancelBtn.setPosition((okBtn.getX() - cancelBtn.getWidth() - padding), okBtn.getY()); - label.setPosition((x + padding), (y + okBtn.getHeight() + padding)); + label.setPosition((x + padding), (y + okBtn.getHeight() + (2 * padding))); visible = true; ok = false; } @@ -77,4 +75,14 @@ public class Dialog extends Bg okBtn.draw(batch); cancelBtn.draw(batch); } + + @Override + public void drawDebug(ShapeRenderer shapes) + { + if (!visible) return; + super.drawDebug(shapes); + label.drawDebug(shapes); + okBtn.drawDebug(shapes); + cancelBtn.drawDebug(shapes); + } } |