summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r--core/src/ch/asynk/rustanddust/game/Ctrl.java7
-rw-r--r--core/src/ch/asynk/rustanddust/game/Hud.java5
-rw-r--r--core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java8
-rw-r--r--core/src/ch/asynk/rustanddust/game/hud/UnitDock.java18
-rw-r--r--core/src/ch/asynk/rustanddust/screens/GameScreen.java6
5 files changed, 42 insertions, 2 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Ctrl.java b/core/src/ch/asynk/rustanddust/game/Ctrl.java
index 3b93ad8..8e05dad 100644
--- a/core/src/ch/asynk/rustanddust/game/Ctrl.java
+++ b/core/src/ch/asynk/rustanddust/game/Ctrl.java
@@ -250,6 +250,13 @@ public class Ctrl implements Disposable
}
+ public boolean drag(int dx, int dy)
+ {
+ if (!blockHud && hud.drag(hudTouch.x, hudTouch.y, dx, dy))
+ return true;
+ return false;
+ }
+
public void touchDown()
{
if (!blockHud && hud.touchDown(hudTouch.x, hudTouch.y))
diff --git a/core/src/ch/asynk/rustanddust/game/Hud.java b/core/src/ch/asynk/rustanddust/game/Hud.java
index 8f9343c..661d4e9 100644
--- a/core/src/ch/asynk/rustanddust/game/Hud.java
+++ b/core/src/ch/asynk/rustanddust/game/Hud.java
@@ -150,6 +150,11 @@ public class Hud implements Disposable, Animation
else msg.write(s, duration, position);
}
+ public boolean drag(float x, float y, int dx, int dy)
+ {
+ return playerInfo.drag(x, y, dx, dy);
+ }
+
public boolean touchDown(float x, float y)
{
hit = null;
diff --git a/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java b/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java
index dd77c8e..ab8fe79 100644
--- a/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java
+++ b/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java
@@ -134,6 +134,14 @@ public class PlayerInfo implements Disposable, Drawable, Animation
turns.blocked = blocked;
}
+ public boolean drag(float x, float y, int dx, int dy)
+ {
+ if (!unitDock.hit(x, y))
+ return false;
+ unitDock.drag(dx, dy);
+ return true;
+ }
+
public boolean touchDown(float x, float y)
{
hit = null;
diff --git a/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java b/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java
index 4e708c4..10d604e 100644
--- a/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java
+++ b/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java
@@ -29,6 +29,7 @@ public class UnitDock extends Bg implements Animation
private float y;
private float to;
private float dx;
+ private float dy;
private float step;
private boolean show;
private boolean mvtDone;
@@ -55,6 +56,7 @@ public class UnitDock extends Bg implements Animation
this.selected = new Sprite(selected);
this.visible = false;
this.dx = 0f;
+ this.dy = 0f;
}
@Override
@@ -72,7 +74,7 @@ public class UnitDock extends Bg implements Animation
private void compute()
{
transform.idt();
- transform.translate((rect.x + dx), (rect.y + rect.height), 0).scale(SCALE, SCALE, 0).translate(-rect.x, - (rect.y + rect.height), 0);
+ transform.translate((rect.x + dx), (rect.y + dy + rect.height), 0).scale(SCALE, SCALE, 0).translate(-rect.x, - (rect.y + rect.height), 0);
point.set(rect.x, rect.y, 0).mul(transform);
scaledRect.x = point.x;
scaledRect.y = point.y;
@@ -107,6 +109,16 @@ public class UnitDock extends Bg implements Animation
return (visible && scaledRect.contains(x, y));
}
+ public void drag(int dx, int dy)
+ {
+ this.dy += dy;
+ if ((rect.y + this.dy + rect.height) < y)
+ this.dy = (y - rect.height - rect.y);
+ else if (scaledRect.y > SCISSORS_BOTTOM)
+ this.dy -= (scaledRect.y - SCISSORS_BOTTOM);
+ compute();
+ }
+
public Unit select(float x, float y)
{
int i = (int) ((scaledRect.y + scaledRect.height - y) / (scaledRect.height / units.size()));
@@ -129,6 +141,10 @@ public class UnitDock extends Bg implements Animation
{
if (!resize())
return;
+ if (dy != 0) {
+ dy = 0;
+ compute();
+ }
to = position.getX(rect.width * SCALE);
show = true;
diff --git a/core/src/ch/asynk/rustanddust/screens/GameScreen.java b/core/src/ch/asynk/rustanddust/screens/GameScreen.java
index c369989..a3f20f1 100644
--- a/core/src/ch/asynk/rustanddust/screens/GameScreen.java
+++ b/core/src/ch/asynk/rustanddust/screens/GameScreen.java
@@ -85,8 +85,12 @@ public class GameScreen implements Screen
public boolean touchDragged(int x, int y, int pointer)
{
dragged += 1;
- cam.translate((dragPos.x - x), (dragPos.y - y));
+ int dx = (int) (dragPos.x - x);
+ int dy = (int) (dragPos.y - y);
dragPos.set(x, y);
+ cam.unprojectHud(x, y, ctrl.hudTouch);
+ if (!ctrl.drag(-dx, dy))
+ cam.translate(dx, dy);
return true;
}
@Override