1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
package ch.asynk.rustanddust.game.hud;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import ch.asynk.rustanddust.engine.gfx.Animation;
import ch.asynk.rustanddust.engine.gfx.Drawable;
import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.game.Ctrl;
import ch.asynk.rustanddust.game.Army;
import ch.asynk.rustanddust.game.Player;
import ch.asynk.rustanddust.ui.Bg;
import ch.asynk.rustanddust.ui.LabelImage;
import ch.asynk.rustanddust.ui.Position;
public class PlayerInfo implements Disposable, Drawable, Animation
{
public static final int PADDING = 5;
private final Ctrl ctrl;
private Bg flag;
private Bg usFlag;
private Bg geFlag;
private LabelImage turns;
private LabelImage aps;
private LabelImage reinforcement;
public UnitDock unitDock;
private Position position;
public PlayerInfo(RustAndDust game)
{
this.ctrl = game.ctrl;
this.position = Position.MIDDLE_CENTER;
usFlag = new Bg(game.factory.getFlag(Army.US));
geFlag = new Bg(game.factory.getFlag(Army.GE));
turns = new LabelImage(game.factory.getHudRegion(game.factory.HUD_TURNS), game.font, 5f);
aps = new LabelImage(game.factory.getHudRegion(game.factory.HUD_APS), game.font, 5f);
reinforcement = new LabelImage(game.factory.getHudRegion(game.factory.REINFORCEMENT), game.font, 5f);
unitDock = new UnitDock(game, 10f);
turns.setPosition(Position.TOP_CENTER);
}
@Override
public void dispose()
{
turns.dispose();
aps.dispose();
reinforcement.dispose();
unitDock.dispose();
}
public void updatePosition()
{
float dx = (position.getX(usFlag.getWidth()) - usFlag.getX());
float dy = (position.getY(usFlag.getHeight()) - usFlag.getY());
usFlag.translate(dx, dy);
geFlag.translate(dx, dy);
aps.translate(dx, dy);
reinforcement.translate(dx, dy);
unitDock.translate(dx, dy);
turns.update();
}
public void setPosition(Position position)
{
if (this.position == position)
return;
this.position = position;
float width = (usFlag.getWidth() + aps.getWidth() + (2 * PADDING));
float height = (usFlag.getHeight() + reinforcement.getHeight() + (1 * PADDING));
float x = position.getX(width);
float y = position.getY(height);
if (position.isLeft()) {
reinforcement.setPosition(x, y);
y += (reinforcement.getHeight() + PADDING);
usFlag.setPosition(x, y);
geFlag.setPosition(x, y);
x += (usFlag.getWidth() + PADDING);
aps.setPosition(x, y);
} else {
x = (x + width);
reinforcement.setPosition((x - reinforcement.getWidth()), y);
y += (reinforcement.getHeight() + PADDING);
x -= usFlag.getWidth();
usFlag.setPosition(x, y);
geFlag.setPosition(x, y);
x -= (aps.getWidth() + PADDING);
aps.setPosition(x, y);
}
unitDock.setPosition(position, reinforcement.getY() - PADDING);
turns.update();
}
public void update(Player player, Position position)
{
unitDock.hide();
turns.write(String.format("%d", player.getTurn()));
aps.write(String.format("%d", player.getCurrentAp()));
int r = player.reinforcement();
if (r == 0) {
reinforcement.visible = false;
} else {
reinforcement.visible = true;
reinforcement.write(String.format("%d", r));
}
if (player.is(Army.GE))
flag = geFlag;
else
flag = usFlag;
setPosition(position);
}
public void blockEndOfTurn(boolean blocked)
{
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 hit(float x, float y)
{
if (turns.hit(x, y)) {
ctrl.hud.askEndOfTurn();
return true;
}
else if (reinforcement.hit(x, y)) {
ctrl.sendMsg(Ctrl.MsgType.UNIT_DOCK_TOGGLE);
return true;
}
else if (unitDock.hit(x, y)) {
ctrl.hud.notify(unitDock.selectedUnit.toString());
ctrl.sendMsg(Ctrl.MsgType.UNIT_DOCK_SELECT, unitDock.selectedUnit);
return true;
}
return false;
}
@Override
public boolean animate(float delta)
{
unitDock.animate(delta);
return false;
}
@Override
public void draw(Batch batch)
{
flag.draw(batch);
turns.draw(batch);
aps.draw(batch);
reinforcement.draw(batch);
unitDock.draw(batch);
}
@Override
public void drawDebug(ShapeRenderer debugShapes)
{
turns.drawDebug(debugShapes);
aps.drawDebug(debugShapes);
reinforcement.drawDebug(debugShapes);
unitDock.drawDebug(debugShapes);
debugShapes.rect(flag.getX(), flag.getY(), flag.getWidth(), flag.getHeight());
}
}
|