summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game/Hud.java
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.java
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.java')
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java109
1 files changed, 6 insertions, 103 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index 1639f3f..701f2d3 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -6,106 +6,14 @@ import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Rectangle;
import ch.asynk.tankontank.engine.gfx.Image;
+import ch.asynk.tankontank.game.hud.Button;
import ch.asynk.tankontank.TankOnTank;
-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(); }
-}
-
public class Hud implements Disposable
{
private static final float OFFSET = 15f;
@@ -117,11 +25,11 @@ public class Hud implements Disposable
private Image geFlag;
private Image flag;
- private Button moveBtn;
- private Button rotateBtn;
- private Button attackBtn;
- private Button checkBtn;
- private Button cancelBtn;
+ public Button moveBtn;
+ public Button rotateBtn;
+ public Button attackBtn;
+ public Button checkBtn;
+ public Button cancelBtn;
private Button btn;
@@ -227,11 +135,6 @@ public class Hud implements Disposable
cancelBtn.hide();
}
- public void setRotateOff()
- {
- rotateBtn.setOff();
- }
-
public boolean touchDown(float x, float y)
{
if (infoRect.contains(x,y)) return true;