-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHUD.cs
More file actions
240 lines (216 loc) · 7.46 KB
/
HUD.cs
File metadata and controls
240 lines (216 loc) · 7.46 KB
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
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class HUD : MonoBehaviour {
// Objects
public RectTransform map;
// Days
public Text dayText;
public Text dayNight;
// Food and water
public RectTransform meatBar;
public RectTransform meatBarPath;
public Text meatText;
public RectTransform plantsBar;
public RectTransform plantsBarPath;
public Text plantsText;
public RectTransform waterBar;
public RectTransform waterBarPath;
public Text waterText;
private Color waterColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
private float barMax = 500.0f;
private Color ColorDefault = new Color(1.0f, 1.0f, 1.0f, 1.0f);
private Color ColorWarning = new Color(1.0f, 0.0f, 0.0f, 1.0f);
// Variables
private bool battle = true;
void Start () {
battle = Global.system.battle;
ShowHUD();
}
void Update () {
ShowMap();
}
// SHOW OR HIDE HUD DEPENDING ON SCENE (BATTLE OR NOT)
void ShowHUD() {
map.gameObject.SetActive(!battle);
}
// SHOW MAP OBJECTS IF NOT BATTLE SCENE
void ShowMap() {
if(!battle) {
CalculateResources();
}
}
// CALCULATE RESOURCES
void CalculateResources() {
// Time
string time = "";
string journey = "";
if(!Global.system.playerMove) {
// Days
int timePassed = Global.system.statistics.daysPassed;
int timeNeed = Global.system.map.timeNeed;
int timeSpend = timePassed + timeNeed;
time = timePassed.ToString() + " + " + timeNeed.ToString() + " = " + timeSpend.ToString();
// Journey
journey = "Journey ends in ";
int timeTiles = Global.system.map.pathPlanned.Count + Global.system.map.pathFinal.Count;
if(Global.system.isDay) {
if(timeTiles % 2 == 0) {
journey += "day";
}
else {
journey += "night";
}
}
else {
if(timeTiles % 2 == 0) {
journey += "night";
}
else {
journey += "day";
}
}
}
else {
time = Global.system.statistics.daysPassed.ToString();
if(Global.system.isDay) {
journey = "Day";
}
else {
journey = "Night";
}
}
dayText.text = time;
dayNight.text = journey;
// Meat
float meat = (float)Global.system.tamer.meat;
string meatUsage = "";
if(meat > 0) {
float meatMax = (float)Global.system.tamer.meatMax;
float meatPercentage = (meat / meatMax) * barMax;
meatBar.sizeDelta = new Vector2(meatPercentage, meatBar.sizeDelta.y);
// Meat: usage
Color meatColor = ColorDefault;
if(!Global.system.playerMove) {
float meatPath = (float)Global.system.map.meatNeed;
float meatPathMax = (float)Global.system.tamer.meat;
float meatPathPercentage = meatPath / meatPathMax;
if(meatPathPercentage > 1.0f) {
meatPathPercentage = 1.0f;
}
meatPathPercentage *= meatBar.sizeDelta.x;
meatBarPath.sizeDelta = new Vector2(meatPathPercentage, meatBar.sizeDelta.y);
meatBarPath.anchoredPosition = new Vector2(meatBar.anchoredPosition.x + meatBar.sizeDelta.x, meatBarPath.anchoredPosition.y);
int meatCalculated = Global.system.tamer.meat - Mathf.CeilToInt(Global.system.map.meatNeed);
meatUsage = Global.system.tamer.meat.ToString() + " - " + Global.system.map.meatNeed.ToString() + " = " + meatCalculated.ToString();
if(meatCalculated <= 0) {
meatColor = ColorWarning;
}
}
else {
meatBarPath.sizeDelta = new Vector2(0.0f, 0.0f);
meatUsage = Global.system.tamer.meat.ToString();
}
meatText.text = meatUsage;
meatText.color = meatColor;
}
else {
if(!Global.system.playerMove) {
int meatCalculated = Global.system.tamer.meat - Mathf.CeilToInt(Global.system.map.meatNeed);
meatUsage = Global.system.tamer.meat.ToString() + " - " + Global.system.map.meatNeed.ToString() + " = " + meatCalculated.ToString();
}
else {
meatUsage = Global.system.tamer.meat.ToString();
}
meatBar.sizeDelta = new Vector2(0.0f, 0.0f);
meatBarPath.sizeDelta = new Vector2(0.0f, 0.0f);
meatText.text = meatUsage;
meatText.color = ColorWarning;
}
// Plants
float plants = (float)Global.system.tamer.plants;
string plantsUsage = "";
if(plants > 0) {
float plantsMax = (float)Global.system.tamer.plantsMax;
float plantsPercentage = (plants / plantsMax) * barMax;
plantsBar.sizeDelta = new Vector2(plantsPercentage, plantsBar.sizeDelta.y);
// Plants: usage
Color plantsColor = ColorDefault;
if(!Global.system.playerMove) {
float plantsPath = (float)Global.system.map.plantsNeed;
float plantsPathMax = (float)Global.system.tamer.plants;
float plantsPathPercentage = plantsPath / plantsPathMax;
if(plantsPathPercentage > 1.0f) {
plantsPathPercentage = 1.0f;
}
plantsPathPercentage *= plantsBar.sizeDelta.x;
plantsBarPath.sizeDelta = new Vector2(plantsPathPercentage, plantsBar.sizeDelta.y);
plantsBarPath.anchoredPosition = new Vector2(plantsBar.anchoredPosition.x + plantsBar.sizeDelta.x, plantsBarPath.anchoredPosition.y);
int plantsCalculated = Global.system.tamer.plants - Mathf.CeilToInt(Global.system.map.plantsNeed);
plantsUsage = Global.system.tamer.plants.ToString() + " - " + Global.system.map.plantsNeed.ToString() + " = " + plantsCalculated.ToString();
if(plantsCalculated <= 0) {
plantsColor = ColorWarning;
}
}
else {
plantsBarPath.sizeDelta = new Vector2(0.0f, 0.0f);
plantsUsage = Global.system.tamer.plants.ToString();
}
plantsText.text = plantsUsage;
plantsText.color = plantsColor;
}
else {
if(!Global.system.playerMove) {
int plantsCalculated = Global.system.tamer.plants - Mathf.CeilToInt(Global.system.map.plantsNeed);
plantsUsage = Global.system.tamer.plants.ToString() + " - " + Global.system.map.plantsNeed.ToString() + " = " + plantsCalculated.ToString();
}
else {
plantsUsage = Global.system.tamer.plants.ToString();
}
plantsBar.sizeDelta = new Vector2(0.0f, 0.0f);
plantsBarPath.sizeDelta = new Vector2(0.0f, 0.0f);
plantsText.text = "0";
plantsText.color = ColorWarning;
}
// Water
float water = (float)Global.system.tamer.water;
if(water > 0) {
float waterMax = (float)Global.system.tamer.waterMax;
float waterPercentage = (water / waterMax);
waterPercentage *= barMax;
waterBar.sizeDelta = new Vector2(waterPercentage, waterBar.sizeDelta.y);
// Water: usage
string waterUsage = "";
Color waterColorCurrent = waterColor;
if(!Global.system.playerMove) {
float waterPath = (float)Global.system.map.waterNeed;
float waterPathMax = waterBar.sizeDelta.x;
float waterPathPercentage = waterPath / waterPathMax;
if(waterPathPercentage > 1.0f) {
waterPathPercentage = 1.0f;
}
waterPathPercentage *= waterPathMax;
waterBarPath.sizeDelta = new Vector2(waterPathPercentage, waterBar.sizeDelta.y);
waterBarPath.anchoredPosition = new Vector2(waterBar.anchoredPosition.x + waterBar.sizeDelta.x, waterBarPath.anchoredPosition.y);
int waterCalculated = Global.system.tamer.water - (int)Global.system.map.waterNeed;
if(waterCalculated < 0) { waterCalculated = 0; }
waterUsage = Global.system.tamer.water.ToString() + " - " + Global.system.map.waterNeed.ToString() + " = " + waterCalculated.ToString();
if(waterCalculated <= 0) {
waterColorCurrent = ColorWarning;
}
}
else {
waterBarPath.sizeDelta = new Vector2(0.0f, 0.0f);
waterUsage = Global.system.tamer.water.ToString();
}
waterText.text = waterUsage;
waterText.color = waterColorCurrent;
}
else {
waterBar.sizeDelta = new Vector2(0.0f, 0.0f);
waterBarPath.sizeDelta = new Vector2(0.0f, 0.0f);
waterText.text = "0";
waterText.color = ColorWarning;
}
}
}