-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.cs
204 lines (178 loc) · 6.78 KB
/
UI.cs
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
using UnityEngine;
using UnityEngine.UI;
public class UI : MonoBehaviour {
public Text generateButton;
public Text playButton;
public Text colorsDescription;
public Text growth;
public Text speed;
public Text step;
public InputField endowmentMaxField;
public InputField endowmentMinField;
public InputField metabolismMaxField;
public InputField metabolismMinField;
public InputField numberField;
public InputField visionMaxField;
public InputField visionMinField;
private void Update () {
growth.text = Simulation.Parameters.SUGAR_GROWTH_RATE.ToString();
speed.text = State.STEPS_PER_SECOND.ToString();
step.text = "Step: " + Simulation.CURRENT_STEP.ToString();
if ( State.DONE ) {
playButton.transform.parent.GetComponent<Button>().interactable = false;
playButton.text = "Done";
}
}
public void ColorsDefaultToggled (bool value) {
if ( value ) {
State.COLORING_OPTION = State.ColoringOptions.DEFAULT;
colorsDescription.text = "all agents are colored red";
Simulation.Render();
}
}
public void ColorsMetabolismToggled (bool value) {
if ( value ) {
State.COLORING_OPTION = State.ColoringOptions.BY_METABOLISM;
colorsDescription.text = "low is blue, medium is purple, high is red";
Simulation.Render();
}
}
public void ColorsSexToggled (bool value) {
if ( value ) {
State.COLORING_OPTION = State.ColoringOptions.BY_SEX;
colorsDescription.text = "males are red, females are blue";
Simulation.Render();
}
}
public void ColorsVisionToggled (bool value) {
if ( value ) {
State.COLORING_OPTION = State.ColoringOptions.BY_VISION;
colorsDescription.text = "low is red, medium is purple, high is blue";
Simulation.Render();
}
}
public void EndowmentMaxUnfocused (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Max(Simulation.Parameters.Endowment.MIN, int.Parse(value));
Simulation.Parameters.Endowment.MAX = num;
endowmentMaxField.text = num.ToString();
} else {
int num = Simulation.Parameters.Endowment.MIN;
Simulation.Parameters.Endowment.MAX = num;
endowmentMaxField.text = num.ToString();
}
}
public void EndowmentMinUnfocused (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Clamp(int.Parse(value), 0, Simulation.Parameters.Endowment.MAX);
Simulation.Parameters.Endowment.MIN = num;
endowmentMinField.text = num.ToString();
} else {
Simulation.Parameters.Endowment.MIN = 0;
endowmentMinField.text = "0";
}
}
public void FasterButtonClicked () {
State.STEPS_PER_SECOND = Mathf.Clamp(++State.STEPS_PER_SECOND, 1, 30);
}
public void GenerateButtonClicked () {
generateButton.text = "Generate";
playButton.transform.parent.GetComponent<Button>().interactable = true;
playButton.text = "Play";
State.PAUSED = true;
State.DONE = false;
Simulation.Init();
Simulation.Render();
}
public void LessButtonClicked () {
Simulation.Parameters.SUGAR_GROWTH_RATE = Mathf.Clamp(--Simulation.Parameters.SUGAR_GROWTH_RATE, 1, 4);
}
public void MetabolismMaxUnfocused (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Max(Simulation.Parameters.Metabolism.MIN, int.Parse(value));
Simulation.Parameters.Metabolism.MAX = num;
metabolismMaxField.text = num.ToString();
} else {
int num = Simulation.Parameters.Metabolism.MIN;
Simulation.Parameters.Metabolism.MAX = num;
metabolismMaxField.text = num.ToString();
}
}
public void MetabolismMinUnfocused (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Clamp(int.Parse(value), 0, Simulation.Parameters.Metabolism.MAX);
Simulation.Parameters.Metabolism.MIN = num;
metabolismMinField.text = num.ToString();
} else {
Simulation.Parameters.Metabolism.MIN = 0;
metabolismMinField.text = "0";
}
}
public void MoreButtonClicked () {
Simulation.Parameters.SUGAR_GROWTH_RATE = Mathf.Clamp(++Simulation.Parameters.SUGAR_GROWTH_RATE, 1, 4);
}
public void MovementClassicToggled (bool value) {
if ( value ) {
Simulation.Parameters.MOVEMENT_STRATEGY = Simulation.MovementStrategies.CLASSIC;
}
}
public void MovementCustomToggled (bool value) {
if ( value ) {
Simulation.Parameters.MOVEMENT_STRATEGY = Simulation.MovementStrategies.CUSTOM;
}
}
public void NumberFieldChanged (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Min(int.Parse(value), 1000);
numberField.text = num.ToString();
}
}
public void NumberFieldUnfocused (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Clamp(int.Parse(value), 0, 1000);
Simulation.Parameters.INITIAL_NUMBER_OF_AGENTS = num;
numberField.text = num.ToString();
} else {
Simulation.Parameters.INITIAL_NUMBER_OF_AGENTS = 0;
numberField.text = "0";
}
}
public void PlayButtonClicked () {
generateButton.text = "Reset";
if ( State.PAUSED ) {
State.PAUSED = false;
playButton.text = "Pause";
State.DELTA_TIME = 0;
Simulation.Step();
Simulation.Render();
} else {
State.PAUSED = true;
playButton.text = "Play";
}
}
public void SlowerButtonClicked () {
State.STEPS_PER_SECOND = Mathf.Clamp(--State.STEPS_PER_SECOND, 1, 30);
}
public void VisionMaxUnfocused (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Clamp(int.Parse(value), Simulation.Parameters.Vision.MIN, 50);
Simulation.Parameters.Vision.MAX = num;
visionMaxField.text = num.ToString();
} else {
int num = Simulation.Parameters.Vision.MIN;
Simulation.Parameters.Vision.MAX = num;
visionMaxField.text = num.ToString();
}
}
public void VisionMinUnfocused (string value) {
if ( value.Length > 0 ) {
int num = Mathf.Clamp(int.Parse(value), 0, Simulation.Parameters.Vision.MAX);
Simulation.Parameters.Vision.MIN = num;
visionMinField.text = num.ToString();
} else {
Simulation.Parameters.Vision.MIN = 0;
visionMinField.text = "0";
}
}
}