-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.pde
393 lines (328 loc) · 16.7 KB
/
ui.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
int totalImages = 32 * 4 - 1;//Total Images
final int rowLength = 16;//How many tiles per row?
int tileRow = 0;//Which row of tiles are we looking at?
int tileN = 0;//Which tile is the cursor over?
boolean colorTiles = true;//Are we placing colored tiles
int fullTotalImages = ceil((float)(totalImages + 1) / rowLength) * rowLength - 1;//make sure all tile rows are full
final int UIBottom = UIscl * 3;//How many tiles tall is the UI?
final color RED = color(255,0,0);
final color GREEN = color(0,255,0);
final color BLUE = color(0,0,255);
final color YELLOW = color(255,255,0);
final color MAGENTA = color(255,0,255);
final color CYAN = color(0,255,255);
final color BLACK = color(0);
final color WHITE = color(255);
final color GREY = color(127);
final color screen_Amber = #FFCC00;
float backgroundRed = 255;//red
float backgroundGreen = 255;//green
float backgroundBlue = 255;//blue
//Controller RSlider, GSlider, BSlider;//sliders
Controller scrollSlider;//slider
Controller colorInputR, colorInputG, colorInputB;//number input
Controller colorWheel;//color wheel
boolean RGBInputVis = false;//are the rgb number inputs visible
final int _OPENING_ = -1;
final int _MAINMENU_ = 0;
final int _TILEMAPUI_ = 1;//UI defines?
final int _EDITORUI_ = 2;//UI defines?
final int _OPTIONSMENU_ = 3;//UI defines?
final int _TILENSTYLE_ = 4;
int currentUI = _OPENING_;
int previousUI = -1;
final int borderThickness = 4;//how thick is the canvas border
int lowerx = 2147483647, lowery = 2147483647;//store lowest xy of tiles
int upperx = -2147483648, uppery = -2147483648;//store highest xy of tiles
boolean drawLines = true;//do we draw the background lines?
void drawEditorBackground(){//Draw the background
int gUpper = 150;//middle-ish
int gLower = 90;//middle-ish
strokeWeight(1);//default
background(backgroundRed, backgroundGreen, backgroundBlue);//Draw the background in whatever the color is
if(backgroundRed > gLower && backgroundRed < gUpper && backgroundGreen > gLower && backgroundGreen < gUpper && backgroundBlue > gLower && backgroundBlue < gUpper){//if the color is gray-ish
stroke(0);//Make it black
}else{
stroke(255 - backgroundRed, 255 - backgroundGreen, 255 - backgroundBlue);//Invert line color
}
if(drawLines){//if the tile xy is not reset and we're should draw lines
for(int i = screenX1; i < screenX2 + 2; i++){//for however many horizontal squares there are
line(i * UIscl, screenY1 * UIscl, i * UIscl, (screenY2 + 2) * UIscl);//draw lines
}
for(int i = screenY1; i < screenY2 + 2; i++){//for however many vertical squares there are
line(screenX1 * UIscl, i * UIscl, (screenX2 + 2) * UIscl, i * UIscl);//draw lines
}
}
}//void draw() END
//---------------------------------------------------------------------------------------------------------------------------------------
void drawBorder(int x1_, int x2_, int y1_, int y2_, float thiccc_){//draw the red border
strokeWeight(thiccc_);//Thicker
stroke(255, 0, 0);//RED
line(x1_, y1_, x1_, y2_);//Draw Left line
line(x2_, y1_, x2_, y2_);//Draw Right line
line(x1_, y1_, x2_, y1_);//Draw Top Line
line(x1_, y2_, x2_, y2_);//Draw Bottom Line
}//void border() END
//---------------------------------------------------------------------------------------------------------------------------------------
void drawEditorUI(){
fill(BLACK);//black
noStroke();//no line around the ui background
rect(0, 0, width, UIBottom);//ui background
strokeWeight(1);//default
stroke(0);
fill(WHITE);//Set background color to white
rect(0, scl, scl*rowLength, scl);//Create rectangle behind tiles UI
for(int i = 0; i < rowLength && tileImages.length != 0; i++){//Go through all the tiles
if((rowLength*tileRow)+i <= fullTotalImages){//If tile exists
if((rowLength*tileRow)+i == tileN){//If displaying selected tile
fill(currentTileColor);//Set background color to the RGB value set by user
rect(scl*i, scl, scl, scl);//Display color behind the tile
}
if(tileImages[(rowLength*tileRow)+i] != null){
image(tileImages[(rowLength*tileRow)+i], scl*i, scl);//Draw tile
}
if((rowLength*tileRow)+i == tileN){
noFill();
rect(scl*i, scl, scl - 1, scl - 1);//Display border around selected tile
}
}
}//Went through all the tiles
//fill(RED);//red text
//stroke(0);//no outline
//textSize(24);//larger text size
//int tmp = 0;//how many tiles are there total
//for(int x = 0; x < mapTiles.size(); x++){//go through all columns
// for(int y = 0; y < mapTiles.get(x).size(); y++){//go through all rows
// tmp += mapTiles.get(x).get(y).size();//add the number of tiles in the space
// }
//}
//if(tmpTile != null){//if we're dragging a tile
// tmp += 1;//count it too
//}
//float tmpX1 = (scl * 16) + (scl / 8);
//float tmpX2 = scl * 25;
//float tmpX3 = (scl * 27) + (scl / 2);
//float tmpY1 = (scl / 1.25);
//float tmpY2 = (scl * 1.75);
//text("Tiles: " + tmp, tmpX1, tmpY1);//Tiles:(tmp)
//text("Drawn: " + drawnTiles, tmpX1, tmpY2);//Drawn:(drawnTiles)
//text("X:" + floor(-screenX/scl), tmpX2, tmpY1);//X:(screenX)
//text("Y:" + floor(-screenY/scl), tmpX2, tmpY2);//Y:(screenY)
//if(mouseY < UIBottom * scl){
// text("X:UI", tmpX3, tmpY1);//X:UI
// text("Y:UI", tmpX3, tmpY2);//Y:UI
//}else{
// text("X:" + mouseTileX, tmpX3, tmpY1);//X:(mouseTileX)
// text("Y:" + mouseTileY, tmpX3, tmpY2);//Y:(mouseTileY)
//}
//textSize(12);//Default text size
}//void draw() END
//---------------------------------------------------------------------------------------------------------------------------------------
void updateEditorUI(){
scrollAmount = (int)scrollSlider.getValue();//update scroll amount
int tmpVal = 150;
if(colorTiles){
editor_button_coloredToggle.setLocalColor(4, currentTileColor);
editor_button_coloredToggle.setLocalColor(2, color(tmpVal - red(currentTileColor), tmpVal - green(currentTileColor), blue(currentTileColor)));
}else{
editor_button_coloredToggle.setLocalColor(4, BLACK);
editor_button_coloredToggle.setLocalColor(2, WHITE);
}
//editor_slider_red.setLocalColor(5, color(red(currentTileColor), 0, 0));
//editor_slider_green.setLocalColor(5, color(0, green(currentTileColor), 0));
//editor_slider_blue.setLocalColor(5, color(0, 0, blue(currentTileColor)));
//color tmp;
//color tmp2;
//colorMode(HSB, 255);
//tmp = color(hue(currentTileColor), 255, 255);
//tmp2 = color(hue(currentTileColor), saturation(currentTileColor), 255);
//lerpColor(color(255), color(0,255,0), vision[i])
//colorMode(RGB, 255);
//editor_slider_hue.setLocalColor(5, tmp);
//editor_slider_saturation.setLocalColor(5, tmp2);
//editor_slider_brightness.setLocalColor(5, (int)brightness(currentTileColor));
//1 = ticks, 2 = text color, 3 = thumb/border, 4 = ticks, 5 = surface, 6 = background, 11 = thumb, 14 = thumb, 15 = thumb
}//void update() END
//---------------------------------------------------------------------------------------------------------------------------------------
void setupUI(){
UIControls.addSlider("scrollSlider").setVisible(false).setDecimalPrecision(0).setPosition(editor_button_coloredToggle.getX() + editor_button_coloredToggle.getWidth(), 0).setSliderMode(Slider.FLEXIBLE).setSize(UIscl * 2, UIscl).setRange(1, 10).setValue(5).setColorBackground(color(50)).setCaptionLabel("");//create Slider
scrollSlider = UIControls.getController("scrollSlider");//make it easier to use Slider
UIControls.addColorWheel("colorWheel").setVisible(false).setRGB(currentTileColor).setCaptionLabel("")//create ColorWheel
.onChange(new CallbackListener(){//when changed
public void controlEvent(CallbackEvent theEvent){
if(currentColorSlider == -1){
currentColorSlider = 99;
}
if(currentColorSlider == 99){
currentTileColor = UIControls.get(ColorWheel.class, "colorWheel").getRGB();
editor_slider_red.setValue(red(currentTileColor));
editor_slider_green.setValue(green(currentTileColor));
editor_slider_blue.setValue(blue(currentTileColor));
editor_slider_hue.setValue(hue(currentTileColor));
editor_slider_saturation.setValue(saturation(currentTileColor));
editor_slider_brightness.setValue(brightness(currentTileColor));
//updateSliderBackgrounds();
}
}
}
);
colorWheel = UIControls.getController("colorWheel");//make it easier to use ColorWheel
UIControls.addTextfield("colorInputR").setSize(UIscl, UIscl / 2).setVisible(false).setCaptionLabel("");//.setColorLabel(color(255, 0, 0));
UIControls.addTextfield("colorInputG").setSize(UIscl, UIscl / 2).setVisible(false).setCaptionLabel("");//.setColorLabel(color(0, 255, 0));
UIControls.addTextfield("colorInputB").setSize(UIscl, UIscl / 2).setVisible(false).setCaptionLabel("");//.setColorLabel(color(0, 0, 255));
colorInputR = UIControls.getController("colorInputR");//make it easier to use Textfield
colorInputG = UIControls.getController("colorInputG");//make it easier to use Textfield
colorInputB = UIControls.getController("colorInputB");//make it easier to use Textfield
//changeUI(_MAINMENU_);//go to tile map selection display
changeUI(_OPENING_);//go to tile map selection display
}//void setup() END
//---------------------------------------------------------------------------------------------------------------------------------------
void changeUI(int ui_){//change screen
slidersSetVis(false);
changeDisplayedMenuBar(button_menuBar_NONE);
altHeld = false;
ctrlHeld = false;
shiftHeld = false;
lastKey = -1;
previousUI = currentUI;
main_menu_button_panel.setVisible(false);
menu_bar_button_panel.setVisible(false);
tilemap_button_panel.setVisible(false);
editor_colorTools_panel.setVisible(false);
colorWheel.setVisible(false);
colorInputR.setVisible(false);//change visibility
colorInputG.setVisible(false);//change visibility
colorInputB.setVisible(false);//change visibility
editor_button_coloredToggle.setVisible(false);//change visibility
editor_button_changeTileMap.setVisible(false);//change visibility
if(ui_ == _OPENING_){//are we going to the tile map loading screen
//surface.setSize(800, 600);
currentUI = _OPENING_;
}else if(ui_ == _MAINMENU_){//are we going to the tile map loading screen
//surface.setSize(298 + (UIscl * 2), 384 + 58 + (UIscl * 2));// 406 + (scl * 2));//298 x 406
main_menu_button_panel.setVisible(true);
currentUI = _MAINMENU_;
}else if(ui_ == _TILEMAPUI_){//are we going to the tile map loading screen
//surface.setSize(960, 960);//458 x 254
tilemap_button_panel.setVisible(true);
currentUI = _TILEMAPUI_;
}else if(ui_ == _EDITORUI_){//are we going to the editor screen
//surface.setSize(960, 960);//458 x 254
slidersSetVis(true);
menu_bar_button_panel.setVisible(true);
editor_colorTools_panel.setVisible(true);
editor_colorTools_panel.setDragArea();
editor_colorTools_panel.setCollapsed(true);
editor_button_coloredToggle.setVisible(true);//change visibility
editor_button_changeTileMap.setVisible(true);//change visibility
currentUI = _EDITORUI_;
}else if(ui_ == _OPTIONSMENU_){//are we going to the editor screen
//surface.setSize(458 + (UIscl * 2), 254 + (UIscl * 2));//458 x 254 = 522 x 318
currentUI = _OPTIONSMENU_;
}else if(ui_ == _TILENSTYLE_){
//surface.setSize(width, height);
currentUI = _TILENSTYLE_;
}else{
println("ERROR: UI DOES NOT EXIST");
}
}//void changeVisibility(boolean visibility) END
//---------------------------------------------------------------------------------------------------------------------------------------
void slidersSetVis(boolean vis_){//set visibility for all items on the editors UI
scrollSlider.setVisible(vis_);
}
//---------------------------------------------------------------------------------------------------------------------------------------
void loadColors(mTile tile_){//Load RGB Sliders and RGB Inputs with value from tile
if(tile_ != null){
if(tile_.colored){//----------------------------------------------------------------------------do we want to check this?
currentTileColor = tile_.tileColor;
}
}
}//void loadColors(int tile) END
//---------------------------------------------------------------------------------------------------------------------------------------
void nextTileC(){//Move To Next Tile
updateTileRow();//Get the row to whatever tile were on
tileN++;//Increment the tile number
if(tileN > fullTotalImages){//Is the tile number greater than our total number of images?
tileN = 0;//Loop the tile number back to the first tile
tileRow = 0;//Loop the tile row back to the first row
}
if(tileN == rowLength*(tileRow+1)){//If the tile number is the last tile
tileRow++;//Increment the tile row
if (tileRow > fullTotalImages/rowLength){//Is the tile row greater than our total number of rows?
tileRow = 0;//Loop the tile row back to the first row
}
}
}//void nextTileC() END
//---------------------------------------------------------------------------------------------------------------------------------------
void prevTileC(){//Move To Previous Tile
updateTileRow();//Get the row to whatever tile were on
tileN--;//Decrement the tile number
if(tileN < 0){//Is the tile number less than zero?
tileN = fullTotalImages;//Loop the tile number back to the last tile
tileRow = floor(fullTotalImages/rowLength);//Loop the tile row back to the last row
}
if(tileN < rowLength*tileRow){//Is the tile number less than the lower end of the current row?
tileRow--;//Decrement the tile row
if(tileRow < 0){//Is the tile number less than zero?
tileRow = floor(fullTotalImages/rowLength);//Loop the tile row back to the last row
}
}
}//void prevTileC() END
//---------------------------------------------------------------------------------------------------------------------------------------
void updateTileRow(){//Get the row to whatever tile were on
while(floor(tileN/rowLength)*rowLength < rowLength*tileRow){//Is tileN lower than the row were on?
tileRow--;//Decrement tileRow
if(tileRow < 0){//Is the tile number less than zero?
tileRow = floor(fullTotalImages/rowLength);//Loop the tile row back to the last row
}
}
while(floor(tileN/rowLength)*rowLength > rowLength*tileRow){//Is tileN higher than the row were on?
tileRow++;//Increment tileRow
if(tileRow > fullTotalImages/rowLength){//Is the tile row greater than our total number of rows?
tileRow = 0;//Loop the tile row back to the first row
}
}
}//void updateTileRow() END
//---------------------------------------------------------------------------------------------------------------------------------------
void nextRowC(){//Next Row
if(tileN < rowLength * tileRow || tileN > rowLength * tileRow + rowLength){//Is tileN outside of our current row
//Do Nothing
}else{
tileN += rowLength;//Keep the selected tile number in the same relative position
if(tileN > fullTotalImages){//If the tile number is greater than our total number of tiles
tileN = tileN - (fullTotalImages + 1);//Loop the tile number back to first row in the same relative position
}
}
tileRow++;//Increment the row number
if(tileRow > fullTotalImages / rowLength){//If the row number is greater than our total number of rows
tileRow = 0;//Loop the row number back to the first
}
}//void nextRowC() END
//---------------------------------------------------------------------------------------------------------------------------------------
void prevRowC(){//Previous Row
if(tileN < rowLength * tileRow || tileN > rowLength * tileRow + rowLength){//Is tileN outside of our current row
//Do Nothing
}else{
tileN -= rowLength;//Keep the selected tile number in the same relative position
if(tileN < 0){//If the tile number is less than zero
tileN = (fullTotalImages + 1) - (0 - tileN);//Loop the tile number back to last row in the same relative position
}
}
tileRow--;//Decrement the row number
if(tileRow < 0){//If the row number is less than our zero
tileRow = floor(fullTotalImages / rowLength);//Loop the row number back to the last
}
}//void prevRowC() END
//---------------------------------------------------------------------------------------------------------------------------------------
String prevFPS = "";
String padFPS(){
String FPS = String.valueOf(frameRate);//grab the frame rate
if(FPS.length() > 4){//if the frame rate has more than 2 decimal places
FPS = FPS.substring(0, 5);//XX.XX truncate them
}else if(FPS.length() > 3){//if it has 1 decimal place
FPS = FPS.substring(0, 4) + "0";//XX.X0 pad it
}else{//if it has no decimal places
FPS = FPS.substring(0, 2) + ".00";//XX.00 pad it
}
return FPS;
}