-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.pde
106 lines (90 loc) · 3.05 KB
/
GUI.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
GTextField txfSeed;
GButton btnGenerateRandom;
GButton btnGenerateSeed;
GButton btnSeasonWinter;
GButton btnSeasonSpring;
GButton btnSeasonSummer;
GButton btnSeasonFall;
GLabel lblSize;
GCustomSlider sdrSize;
final color defaultSeasonButtonColor = color(63, 127, 191);
final color selectedSeasonButtonColor = color(0, 255, 0);
void makeGui() {
txfSeed = new GTextField(this, 0, 0, 256, 24);
txfSeed.setText("Seed.");
btnGenerateRandom = new GButton(this, 0, 24, 128, 24, "Generate Random");
btnGenerateSeed = new GButton(this, 128, 24, 128, 24, "Generate w/ Seed");
btnSeasonWinter = new GButton(this, 0, 56, 64, 24, "Winter");
btnSeasonSpring = new GButton(this, 64, 56, 64, 24, "Spring");
btnSeasonSummer = new GButton(this, 128, 56, 64, 24, "Summer");
btnSeasonFall = new GButton(this, 192, 56, 64, 24, "Fall");
btnSeasonWinter.setVisible(false);
btnSeasonSpring.setVisible(false);
btnSeasonSummer.setVisible(false);
btnSeasonFall.setVisible(false);
clearSeasonButtonColors();
lblSize = new GLabel(this, width - 256, 0, 128, 16, "Terrain Size:");
lblSize.setTextAlign(GAlign.LEFT, null);
sdrSize = new GCustomSlider(this, width - 256, 16, 256, 48, null);
sdrSize.setShowDecor(false, false, true, true);
sdrSize.setLimits(24, 8, 128);
}
void handleButtonEvents(GButton button, GEvent event) {
if (button == btnGenerateRandom && event == GEvent.CLICKED) {
generateRandom();
}
if (button == btnGenerateSeed && event == GEvent.CLICKED) {
int seed = int(txfSeed.getText());
generateWithSeed(seed);
}
if (button == btnSeasonWinter && event == GEvent.CLICKED) {
switchSeason(SEASON_WINTER);
}
if (button == btnSeasonSpring && event == GEvent.CLICKED) {
switchSeason(SEASON_SPRING);
}
if (button == btnSeasonSummer && event == GEvent.CLICKED) {
switchSeason(SEASON_SUMMER);
}
if (button == btnSeasonFall && event == GEvent.CLICKED) {
switchSeason(SEASON_FALL);
}
}
int guiGetTerrainSize() {
return sdrSize.getValueI();
}
void guiSetSeason(int season) {
clearSeasonButtonColors();
btnSeasonWinter.setVisible(true);
btnSeasonSpring.setVisible(true);
btnSeasonSummer.setVisible(true);
btnSeasonFall.setVisible(true);
switch(season) {
case SEASON_WINTER:
btnSeasonWinter.setLocalColor(4, selectedSeasonButtonColor);
break;
case SEASON_SPRING:
btnSeasonSpring.setLocalColor(4, selectedSeasonButtonColor);
break;
case SEASON_SUMMER:
btnSeasonSummer.setLocalColor(4, selectedSeasonButtonColor);
break;
case SEASON_FALL:
btnSeasonFall.setLocalColor(4, selectedSeasonButtonColor);
break;
}
}
void clearSeasonButtonColors() {
btnSeasonWinter.setLocalColor(4, defaultSeasonButtonColor);
btnSeasonSpring.setLocalColor(4, defaultSeasonButtonColor);
btnSeasonSummer.setLocalColor(4, defaultSeasonButtonColor);
btnSeasonFall.setLocalColor(4, defaultSeasonButtonColor);
}
void guiSetSeed(long seed) {
println("Seed: " + seed);
txfSeed.setText(String.format("%d", seed));
}
void keyPressed() {
if(key == ' ')
generateRandom();
}