diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-07 16:56:42 +0100 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-07 16:56:42 +0100 | 
| commit | ef1f39fbcd65a8a972e11f232f8691cd207a0754 (patch) | |
| tree | 515f43bb73f3d404f2cbc4bd0b0bf536d86bdb75 | |
| parent | 4b0e1e5ef67c4ea37e9e282e4e35e128f2d915b2 (diff) | |
| download | RustAndDust-ef1f39fbcd65a8a972e11f232f8691cd207a0754.zip RustAndDust-ef1f39fbcd65a8a972e11f232f8691cd207a0754.tar.gz | |
add game/hud/Dialog
| -rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/Dialog.java | 78 | 
1 files changed, 78 insertions, 0 deletions
| diff --git a/core/src/ch/asynk/tankontank/game/hud/Dialog.java b/core/src/ch/asynk/tankontank/game/hud/Dialog.java new file mode 100644 index 0000000..006c18a --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/hud/Dialog.java @@ -0,0 +1,78 @@ +package ch.asynk.tankontank.game.hud; + +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 ch.asynk.tankontank.engine.gfx.Image; + +public class Dialog extends Bg +{ +    public boolean visible; +    public boolean ok; +    public int padding; +    private Text text; +    private Image okBtn; +    private Image cancelBtn; + +    public Dialog(BitmapFont font, TextureRegion region, TextureAtlas atlas) +    { +        super(region); +        this.text = new Text(font, "hello"); +        this.okBtn = new Image(atlas.findRegion("ok")); +        this.cancelBtn = new Image(atlas.findRegion("cancel")); +        this.visible = false; +        this.padding = 10; +    } + +    public void show(String msg, Position position) +    { +        text.write(msg); +        TextBounds b = text.getBounds(); + +        float height = (b.height + (3 * padding) + okBtn.getHeight()); +        float width = (b.width + (2 * padding)); +        float w2 = ((3 * padding) + okBtn.getWidth() + cancelBtn.getWidth()); +        if (w2 > width) +            width = w2; +        float x = position.getX(width); +        float y = position.getY(height); +        set(x, y, width, height); +        okBtn.setPosition((x + width - okBtn.getWidth() - padding), (y + padding)); +        cancelBtn.setPosition((okBtn.getX() - cancelBtn.getWidth() - padding), okBtn.getY()); +        text.setPosition((x + padding), (y + okBtn.getHeight() + padding)); +        visible = true; +        ok = false; +    } + +    public boolean hit(float x, float y) +    { +        if (okBtn.hit(x, y)) { +            ok = true; +            return true; +        } else if (cancelBtn.hit(x, y)) { +            ok = false; +            return true; +        } +        return false; +    } + +    @Override +    public void dispose() +    { +        super.dispose(); +        // font.dispose(); +    } + +    @Override +    public void draw(Batch batch) +    { +        if (!visible) return; +        super.draw(batch); +        text.draw(batch); +        okBtn.draw(batch); +        cancelBtn.draw(batch); +    } +} | 
