-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGUIView.pde
265 lines (206 loc) · 6.91 KB
/
GUIView.pde
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
class GUIView extends BasicView {
PGraphics canvas;
/******** GENERAL ********/
final PFont BIG_FONT;
final PFont SMALL_FONT;
final int BIG_FONT_SIZE = 48;
final int SMALL_FONT_SIZE = 24;
final int EDGE_PADDING = 52;
final int ICON_SIZE = 64;
/******** PLAYERS ********/
final color[] playerColors = {
color(218, 100, 247),
color(200, 255, 91)};
/******** WEAPONS ********/
final color LOADED_COLOR = color(0, 200, 0);
final color LOADING_COLOR = color(255, 50, 0);
final color UNAVAILABLE_COLOR = color(100,100,100);
final int WEAPON_ICON_SIZE = 64;
final int WEAPON_COUNT = 10;
PShape[] weaponIcons;
String[] console;
public GUIView(){
// init the canvas on which to draw
canvas = createGraphics(width, height);
BIG_FONT = loadFont("8-bitLimitRBRK-48.vlw");
SMALL_FONT = loadFont("AlphaBetaBRK-48.vlw");
// init the players
initPlayers();
// load svg icons of weapons
//loadWeaponIcons();
console = new String[3];
}
public void injectBattleSystem(BattleSystem _bs){
battleSystem = _bs;
}
public void display(){
canvas.beginDraw();
canvas.clear();
displayGUI();
canvas.pushMatrix();
canvas.translate(EDGE_PADDING*2, EDGE_PADDING * 4);
displayPlayer(battleSystem.getPlayer(0));
canvas.popMatrix();
canvas.pushMatrix();
canvas.translate(width-100, EDGE_PADDING * 4);
displayPlayer(battleSystem.getPlayer(1));
canvas.popMatrix();
canvas.endDraw();
}
public void displayGUI(){
title();
console();
if(battleSystem.getState() == SKILL_STATE) skillBar();
if(battleSystem.getState() == BATTLE_STATE) timer();
}
private void skillBar(){
int SKILL_BAR_WIDTH = 30;
int SKILL_BAR_HEIGHT = 300;
canvas.pushStyle();
canvas.pushMatrix();
canvas.translate(width/2,height/2);
canvas.noFill();
canvas.rectMode(CENTER);
canvas.strokeWeight(3);
canvas.stroke(100,0,0);
canvas.rect(0,0, SKILL_BAR_WIDTH, SKILL_BAR_HEIGHT);
canvas.noStroke();
canvas.fill(0,0,200);
canvas.rect(0,0, SKILL_BAR_WIDTH, SKILL_BAR_HEIGHT * battleSystem.getSkillFloat());
canvas.popMatrix();
canvas.popStyle();
}
private void title(){
canvas.stroke(255);
canvas.fill(255);
canvas.textAlign(CENTER);
canvas.textFont(BIG_FONT);
canvas.textSize(BIG_FONT_SIZE);
canvas.text("!-BattleSystem-!", width/2 , BIG_FONT_SIZE + EDGE_PADDING);
}
private void console(){
canvas.stroke(255);
canvas.fill(255);
canvas.textAlign(CENTER);
canvas.textFont(SMALL_FONT);
canvas.textSize(SMALL_FONT_SIZE);
canvas.text(battleSystem.getText(), width/2 , height - EDGE_PADDING);
}
private void timer(){
canvas.stroke(255);
canvas.fill(255);
canvas.textAlign(CENTER);
canvas.textFont(SMALL_FONT);
canvas.textSize(SMALL_FONT_SIZE);
canvas.text(battleSystem.timer, width/2 , height/2);
}
public void displayPlayer(BasicPlayer _player){
canvas.pushMatrix();
canvas.pushStyle();
canvas.textFont(SMALL_FONT);
canvas.textSize(SMALL_FONT_SIZE);
canvas.fill(255);
canvas.text(_player.getName(), 0,0);
// canvas.fill(_player.getColor());
canvas.translate(0,BIG_FONT_SIZE);
canvas.text(str(_player.getHitPoints())+" HP", 0,0);
canvas.translate(0,BIG_FONT_SIZE);
ArrayList<BasicWeapon> _weapons = _player.getWeapons();
for(BasicWeapon _w : _weapons){
displayWeapon(_w, _player.getSelectedWeapon() == _w);
canvas.translate(0, ICON_SIZE);
}
canvas.popStyle();
canvas.popMatrix();
}
public void displayWeapon(BasicWeapon _weapon, boolean _sel){
// drawLoading
canvas.noStroke();
if(!_weapon.isUseable()) canvas.fill(UNAVAILABLE_COLOR);
else if(!_weapon.isLoaded()) canvas.fill(LOADING_COLOR);
else canvas.fill(LOADED_COLOR);
canvas.rect(-ICON_SIZE/2, -ICON_SIZE/2, ICON_SIZE, (float)ICON_SIZE * _weapon.getLoadingProgress());
canvas.noFill();
canvas.strokeWeight(4);
canvas.stroke(_sel ? color(100,10, 50) : color(100,0, 50));
canvas.rect(-ICON_SIZE/2, -ICON_SIZE/2, ICON_SIZE, ICON_SIZE);
canvas.shape(_weapon.getIcon(), -ICON_SIZE/2, -ICON_SIZE/2);
canvas.textFont(SMALL_FONT);
canvas.textSize(SMALL_FONT_SIZE);
canvas.fill(255);
canvas.text("A "+_weapon.getAttackStrength(), 60, 0);
canvas.text("D "+_weapon.getDefenseStrength(), 60, 20);
}
////////////////////////////////////////////////////////////////////////////////////
///////
/////// GUI Utils
///////
////////////////////////////////////////////////////////////////////////////////////
private void progressBar(int _width, int _height, float _value){
pushStyle();
//rect(0,0);
}
public PGraphics getCanvas(){
return canvas;
}
////////////////////////////////////////////////////////////////////////////////////
///////
/////// Initialisations
///////
////////////////////////////////////////////////////////////////////////////////////
private void initPlayers(){
}
// private void loadWeaponIcons(){
// weaponIcons = new PShape[WEAPON_COUNT];
// weaponIcons[0] = loadShape("data/graphics/shoulderpad_icon.svg");
// weaponIcons[1] = loadShape("data/graphics/foxmask_icon.svg");
// weaponIcons[2] = loadShape("data/graphics/pendant_icon.svg");
// weaponIcons[3] = loadShape("data/graphics/claws_icon.svg");
// weaponIcons[4] = loadShape("data/graphics/ramhorns_icon.svg");
// weaponIcons[5] = loadShape("data/graphics/tail_icon.svg");
// weaponIcons[6] = loadShape("data/graphics/collar_icon.svg");
// weaponIcons[7] = loadShape("data/graphics/cap_icon.svg");
// weaponIcons[8] = loadShape("data/graphics/wings_icon.svg");
// weaponIcons[9] = loadShape("data/graphics/antlers_icon.svg");
// for(int i = 0; i < WEAPON_COUNT; i++){
// weaponIcons[i].disableStyle();
// }
// }
}
class WeaponView {
public WeaponView(){}
public void displayWeapon(BasicWeapon _bw){
}
}
// This class displays a weapon icon on screen with various information
class GUIWeaponView extends WeaponView{
final color LOADED_COLOR = color(0, 255, 0);
final color LOADING_COLOR = color(255, 255, 0);
final color UNAVAILABLE_COLOR = color(100,100,100);
final int ICON_SIZE = 64;
final int WEAPON_COUNT = 10;
PShape[] weaponIcons;
public GUIWeaponView(){
super();
loadIcons();
}
// takes a PGraphics
public void display(PGraphics _pg, PVector _loc, BasicWeapon _wp){
}
private void loadIcons(){
weaponIcons = new PShape[WEAPON_COUNT];
weaponIcons[0] = loadShape("/data/graphics/shoulderpad_icon.svg");
weaponIcons[1] = loadShape("/data/graphics/foxmask_icon.svg");
weaponIcons[2] = loadShape("/data/graphics/pendant_icon.svg");
weaponIcons[3] = loadShape("/data/graphics/claws_icon.svg");
weaponIcons[4] = loadShape("/data/graphics/ramhorns_icon.svg");
weaponIcons[5] = loadShape("/data/graphics/tail_icon.svg");
weaponIcons[6] = loadShape("/data/graphics/collar_icon.svg");
weaponIcons[7] = loadShape("/data/graphics/cap_icon.svg");
weaponIcons[8] = loadShape("/data/graphics/wings_icon.svg");
weaponIcons[9] = loadShape("/data/graphics/antlers_icon.svg");
for(int i = 0; i < WEAPON_COUNT; i++){
weaponIcons[i].disableStyle();
}
}
}