summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game/hud
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-10 15:29:14 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-10 15:29:14 +0200
commit4ce95587bd59b65e15859ee55fbd5b9d2cfaa238 (patch)
treeff90ce5e0353e528b4d420f09620320b551d205f /core/src/ch/asynk/tankontank/game/hud
parent7cfa09595c02666ca36db9d07a572d0519d75b5a (diff)
downloadRustAndDust-4ce95587bd59b65e15859ee55fbd5b9d2cfaa238.zip
RustAndDust-4ce95587bd59b65e15859ee55fbd5b9d2cfaa238.tar.gz
Hud: extract hud/Button, Button instances go public
Diffstat (limited to 'core/src/ch/asynk/tankontank/game/hud')
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/Button.java102
1 files changed, 102 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Button.java b/core/src/ch/asynk/tankontank/game/hud/Button.java
new file mode 100644
index 0000000..b42a9cf
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/hud/Button.java
@@ -0,0 +1,102 @@
+package ch.asynk.tankontank.game.hud;
+
+import com.badlogic.gdx.Gdx;
+
+import com.badlogic.gdx.utils.Disposable;
+
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.math.Rectangle;
+
+import ch.asynk.tankontank.engine.gfx.Image;
+
+public class Button implements Disposable
+{
+
+ public int idx;
+ public boolean visible;
+ private Image images [];
+ private Image image;
+ private Rectangle rect;
+
+ private static final int OFF = 0;
+ private static final int ON = 1;
+ private static final int DOWN = 2;
+
+ public Button(TextureAtlas atlas, String base)
+ {
+ this.idx = OFF;
+ this.visible = false;
+ this.images = new Image[3];
+ this.images[OFF] = new Image(atlas.findRegion(base + "-off"));
+ this.images[ON] = new Image(atlas.findRegion(base + "-on"));
+ this.images[DOWN] = new Image(atlas.findRegion(base + "-down"));
+
+ this.rect = new Rectangle(getX(), getY(), getWidth(), getHeight());
+ }
+
+ @Override
+ public void dispose()
+ {
+ for (Image image : images)
+ image.dispose();
+ }
+
+ public void hide()
+ {
+ idx = OFF;
+ visible = false;
+ }
+
+ public void setOff()
+ {
+ idx = OFF;
+ }
+
+ public void setOn()
+ {
+ idx = ON;
+ }
+
+ public void setDown()
+ {
+ idx = DOWN;
+ }
+
+ public boolean isOn()
+ {
+ return (idx == ON);
+ }
+
+ public boolean isOff()
+ {
+ return (idx == OFF);
+ }
+
+ public boolean isDisabled()
+ {
+ return (idx == DOWN);
+ }
+
+ public Image getImage()
+ {
+ return images[idx];
+ }
+
+ public void setPosition(float x, float y)
+ {
+ for (Image image : images)
+ image.setPosition(x, y);
+ rect.set(x, y, getWidth(), getHeight());
+ }
+
+ public boolean hit(float x, float y)
+ {
+ if (!visible) return false;
+ return rect.contains(x,y);
+ }
+
+ public float getX() { return images[0].getX(); }
+ public float getY() { return images[0].getY(); }
+ public float getWidth() { return images[0].getWidth(); }
+ public float getHeight() { return images[0].getHeight(); }
+}