summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-10 17:43:20 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-10 17:43:20 +0100
commit016893d25d10ea0f69072c6f698554cc657fd80d (patch)
treea201ad3fc0ea28dd58f55e0eebaa64495f94c6d7 /core
parent48ef61ee3edfafd6878899e68a201a372691cf3f (diff)
downloadRustAndDust-016893d25d10ea0f69072c6f698554cc657fd80d.zip
RustAndDust-016893d25d10ea0f69072c6f698554cc657fd80d.tar.gz
UnitDock: support setPosition(Position, float)
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/UnitDock.java33
2 files changed, 20 insertions, 15 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index f441931..48ccafe 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -89,7 +89,7 @@ public class Hud implements Disposable
aps.setLabelPosition(Position.TOP_RIGHT);
reinforcement.setPosition(x, usFlag.getY() - reinforcement.getHeight() - 0);
reinforcement.setLabelPosition(Position.TOP_LEFT);
- unitDock.setTopLeft(OFFSET, reinforcement.getY() - 5);
+ unitDock.setPosition(Position.TOP_LEFT, reinforcement.getY() - 5);
}
@Override
diff --git a/core/src/ch/asynk/tankontank/game/hud/UnitDock.java b/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
index 4e75690..5bd2a6d 100644
--- a/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
+++ b/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
@@ -21,19 +21,20 @@ public class UnitDock extends Bg
private final Ctrl ctrl;
private float padding;
- public float x;
- public float y;
- public float to;
+ private float y;
+ private float to;
private float dx;
- public boolean show;
- public boolean done;
+ private float step;
+ private Position position;
+ private boolean show;
+ private boolean done;
public Pawn selectedPawn;
private Sprite selected;
private List<Pawn> pawns;
private Vector3 point;
private Matrix4 saved;
private Matrix4 transform;
- protected Rectangle scaledRect;
+ private Rectangle scaledRect;
public UnitDock(Ctrl ctrl, TextureRegion bg, TextureRegion selected, float padding)
{
@@ -49,10 +50,13 @@ public class UnitDock extends Bg
this.visible = false;
}
- public void setTopLeft(float x, float y)
+ public void setPosition(Position position, float y)
{
- this.x = x;
+ this.position = position;
this.y = y;
+ this.step = (position.isLeft() ? STEP : -STEP);
+ this.done = true;
+ this.visible = false;
}
@Override
@@ -70,7 +74,7 @@ public class UnitDock extends Bg
public void hide()
{
if (!visible) return;
- to = - (rect.width * SCALE);
+ to = rect.x;
show = false;
done = false;
}
@@ -89,11 +93,12 @@ public class UnitDock extends Bg
public void show()
{
+ float x = position.getX(rect.width * SCALE);
if (done) {
pawns = ctrl.player.getReinforcement();
rect.width = pawns.get(0).getWidth() + (2 * padding);
rect.height = ((pawns.get(0).getHeight() * pawns.size()) + ((pawns.size() + 1) * padding));
- rect.x = - (rect.width * SCALE);
+ rect.x = (position.isLeft() ? (0 - (rect.width * SCALE)) : (x + (rect.width * SCALE)));
rect.y = y - rect.height;
// position units here
float px = rect.x;
@@ -122,15 +127,15 @@ public class UnitDock extends Bg
float x = (rect.x + dx);
if (show) {
- if (x < to)
- dx += STEP;
+ if ((position.isLeft() && (x < to)) || (!position.isLeft() && x > to))
+ dx += step;
else {
dx = (to - rect.x);
done = true;
}
} else {
- if (x > to)
- dx -= STEP;
+ if ((position.isLeft() && (x > to)) || (!position.isLeft() && x < to))
+ dx -= step;
else {
dx = (to - rect.x);
done = true;