-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotherscreens.pde
executable file
·444 lines (309 loc) · 11.8 KB
/
otherscreens.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
public class Updater extends Screen {
String updateName = "";
String headerText = "An update is available!";
String displayMessage = "This update contains the following additions, changes, and/or fixes:\n";
String footerMessage = "Downloading and installing will run in the background as "+engine.getAppName()+" runs, so please leave Timeway running until the update completes. Don't worry, none of your personal data will be modified.";
String patchNotes = "";
boolean startedMusic = false;
JSONObject updateInfo;
public Updater(TWEngine engine, JSONObject updateInfo) {
super(engine);
this.updateInfo = updateInfo;
//sound.streamMusicWithFade(engine.APPPATH+UPDATE_MUSIC);
myUpperBarWeight = 70;
try {
updateName = updateInfo.getString("update-name");
if (!updateInfo.getString("display-header", "[default]").equals("[default]"))
headerText = updateInfo.getString("display-header");
if (!updateInfo.getString("display-message", "[default]").equals("[default]"))
displayMessage = updateInfo.getString("display-message");
if (!updateInfo.getString("message-footer", "[default]").equals("[default]"))
footerMessage = updateInfo.getString("message-footer");
else if (!updateInfo.getString("display-footer", "[default]").equals("[default]")) // Oops
footerMessage = updateInfo.getString("display-footer");
patchNotes = updateInfo.getString("patch-notes", "");
}
catch (RuntimeException e) {
console.warn("Something went wrong with getting update info.");
e.printStackTrace();
}
}
public void upperBar() {
super.upperBar();
textFont(engine.DEFAULT_FONT);
textSize(50);
textAlign(CENTER, TOP);
fill(0);
text("Update", WIDTH/2, 10);
}
public boolean button(String display, float x, float y) {
x = x+10;
float wi = (WIDTH/2)-40; // idk why 40
float hi = 50;
return ui.basicButton(display, x, y, wi, hi);
}
public void content() {
float x, y;
textFont(engine.DEFAULT_FONT);
textSize(50);
textAlign(LEFT, TOP);
fill(255);
x = 10;
y = myUpperBarWeight+50;
text(headerText, x, y);
textSize(30);
fill(255, 255, 200);
x = 10;
y = myUpperBarWeight+100;
text(updateName, x, y);
textSize(30);
fill(255);
x = 10;
y = myUpperBarWeight+150;
text(displayMessage, x, y, WIDTH-x*2, 100);
textSize(20);
fill(255);
x = 10;
y = myUpperBarWeight+250;
float footerY = 150;
text(patchNotes, x, y, WIDTH-x*2, HEIGHT-myLowerBarWeight-y-footerY);
textSize(20);
fill(200);
x = 10;
y = HEIGHT-myLowerBarWeight-footerY;
text(footerMessage, x, y, WIDTH-x*2, footerY);
if (button("Later", 0, HEIGHT-myLowerBarWeight-60)) {
previousScreen();
}
if (button("Update", WIDTH/2, HEIGHT-myLowerBarWeight-60)) {
String downloadURL = "";
String downloadLocation = file.getMyDir()+"timeway-update-download.zip";
if (isWindows()) {
downloadURL = updateInfo.getString("windows-download", "");
}
else if (isLinux()) {
downloadURL = updateInfo.getString("linux-download", "");
}
else if (isMacOS()) {
downloadURL = updateInfo.getString("macos-download", "");
}
engine.beginUpdate(downloadURL, downloadLocation);
previousScreen();
}
}
}
public class Benchmark extends Screen {
public SpriteSystemPlaceholder gui;
public Benchmark(TWEngine e) {
super(e);
textFont(engine.DEFAULT_FONT);
gui = new SpriteSystemPlaceholder(engine, engine.APPPATH+engine.PATH_SPRITES_ATTRIB()+"gui/benchmark/");
ui.useSpriteSystem(gui);
myUpperBarColor = color(100);
gui.interactable = false;
}
public void upperBar() {
super.upperBar();
if (ui.button("back", "back_arrow_128", "")) {
previousScreen();
}
gui.updateSpriteSystem();
}
public void content() {
// We expect the benchmark to have completed
textAlign(LEFT, TOP);
textSize(40);
text("Benchmark results", 10, myUpperBarWeight+10);
float x = 10;
float y = myUpperBarWeight+50;
int i = 0;
float c = 0;
noStroke();
textSize(20);
colorMode(HSB, 255);
for (String res : engine.benchmarkResults) {
fill(c, 255, 128);
c += 40.;
c %= 255.;
rect(x, y, ((int)engine.benchmarkArray[i])/2, 20);
fill(255);
text(res, x, y-3);
i++;
y += 25;
}
colorMode(RGB, 255);
}
}
public class Explorer extends Screen {
//private String currentDir = DEFAULT_DIR;
//DisplayableFile backButtonDisplayable = null;
SpriteSystemPlaceholder gui;
private int numTimewayEntries;
public float scrollBottom = 0.0;
public Explorer(TWEngine engine) {
super(engine);
file.openDirInNewThread(engine.DEFAULT_DIR);
gui = new SpriteSystemPlaceholder(engine, engine.APPPATH+engine.PATH_SPRITES_ATTRIB()+"gui/explorer/");
gui.repositionSpritesToScale();
gui.interactable = false;
//myLowerBarColor = color(120);
//myUpperBarColor = color(120);
myBackgroundColor = color(0);
}
// Sorry for code duplication!
public Explorer(TWEngine engine, String dir) {
super(engine);
file.openDirInNewThread(dir);
gui = new SpriteSystemPlaceholder(engine, engine.APPPATH+engine.PATH_SPRITES_ATTRIB()+"gui/explorer/");
gui.repositionSpritesToScale();
gui.interactable = false;
//myLowerBarColor = color(120);
//myUpperBarColor = color(120);
myBackgroundColor = color(0);
//engine.openDir(dir);
}
// This method shall render all the files in the current dir
private void renderDir() {
final float TEXT_SIZE = 50;
final float BOTTOM_SCROLL_EXTEND = 300; // The scroll doesn't go all the way down to the bottom for whatever reason.
// So let's add a little more room to scroll down to the bottom.
app.textFont(engine.DEFAULT_FONT, 50);
app.textSize(TEXT_SIZE);
for (int i = 0; i < file.currentFiles.length; i++) {
float textHeight = app.textAscent() + app.textDescent();
float x = 50;
float wi = TEXT_SIZE + 20;
float y = 150 + i*TEXT_SIZE+input.scrollOffset;
// Sorry not sorry
try {
if (file.currentFiles[i] != null) {
if (engine.mouseX() > x && engine.mouseX() < x + app.textWidth(file.currentFiles[i].filename) + wi && engine.mouseY() > y && engine.mouseY() < textHeight + y) {
// if mouse is overing over text, change the color of the text
app.fill(100, 0, 255);
app.tint(100, 0, 255);
// if mouse is hovering over text and left click is pressed, go to this directory/open the file
if (input.primaryOnce) {
if (file.currentFiles[i].isDirectory())
input.scrollOffset = 0.;
file.open(file.currentFiles[i]);
}
} else {
app.noTint();
app.fill(255);
}
if (file.currentFiles[i].icon != null)
display.img(file.currentFiles[i].icon, 50, y, TEXT_SIZE, TEXT_SIZE);
app.textAlign(LEFT, TOP);
app.text(file.currentFiles[i].filename, x + wi, y);
app.noTint();
}
}
catch (ArrayIndexOutOfBoundsException e) {
}
catch (NullPointerException ex) {
}
}
scrollBottom = max(0, (file.currentFiles.length*TEXT_SIZE-HEIGHT+BOTTOM_SCROLL_EXTEND));
}
// THIS IS COPIED from the editor tab.
// TODO: make this use one script from the engine or something.
// For the time being let's just have it copy+pasted here.
private boolean button(String name, String texture, String displayText) {
// This doesn't change at all.
// I just wanna keep it in case it comes in useful later on.
boolean guiClickable = true;
// Don't want our messy code to spam the console lol.
gui.suppressSpriteWarning = true;
boolean hover = false;
// Full brightness when not hovering
app.tint(255);
app.fill(255);
// To click:
// - Must not be in a minimenu
// - Must not be in gui move sprite / edit mode.
// - also the guiClickable thing.
if (gui.buttonHover(name) && guiClickable && !gui.interactable) {
// Slight gray to indicate hover
app.tint(210);
app.fill(210);
hover = true;
}
// Display the button, will be affected by the hover color.
gui.button(name, texture, displayText);
app.noTint();
// Don't have "the boy who called wolf", situation, turn back on warnings
// for genuine troubleshooting.
gui.suppressSpriteWarning = false;
// Only when the button is actually clicked.
return hover && input.primaryOnce;
}
private void renderGui() {
//************NEW ENTRY************
if (button("new_entry", "new_entry_128", "New entry")) {
// TODO: placeholder
String newName = file.currentDir+engine.appendZeros(numTimewayEntries, 5)+"."+engine.ENTRY_EXTENSION;
requestScreen(new Editor(engine, newName));
}
//************NEW FOLDER************
if (button("new_folder", "new_folder_128", "New folder")) {
Runnable r = new Runnable() {
public void run() {
if (input.keyboardMessage.length() <= 1) {
console.log("Please enter a valid folder name!");
return;
}
String foldername = file.currentDir+input.keyboardMessage;
new File(foldername).mkdirs();
refreshDir();
}
};
engine.beginInputPrompt("Folder name:", r);
}
//***********CLOSE BUTTON***********
if (button("cross", "cross", "")) {
exit();
}
//***********PIXeL REALM BUTTON***********
if (button("world", "world_128", "Pixel Realm")) {
requestScreen(new PixelRealmWithUI(engine, file.currentDir));
}
gui.updateSpriteSystem();
}
// Just use the default background
public void backg() {
app.fill(myBackgroundColor);
app.noStroke();
app.rect(0, 0, WIDTH, HEIGHT);
}
public void upperBar() {
display.shader("fabric", "color", 0.5,0.5,0.5,1., "intensity", 0.1);
super.upperBar();
app.resetShader();
renderGui();
}
public void lowerBar() {
display.shader("fabric", "color", 0.5,0.5,0.5,1., "intensity", 0.1);
super.lowerBar();
display.defaultShader();
}
public void refreshDir() {
file.openDirInNewThread(file.currentDir);
}
// Let's render our stuff.
public void content() {
// TODO: Should have a function with this to remove code bloat?
app.fill(255);
app.textFont(engine.DEFAULT_FONT, 50);
app.textSize(70);
app.textAlign(LEFT, TOP);
app.text("Explorer", 50, 80);
if (file.loading) {
ui.loadingIcon(WIDTH/2, HEIGHT/2);
}
else {
input.processScroll(0., scrollBottom+1.0);
renderDir();
}
engine.displayInputPrompt();
}
}