-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIManager.cs
466 lines (404 loc) · 15 KB
/
UIManager.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
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Text;
using UnityEditor;
public class UIManager : MonoBehaviour
{
public Slider playerHealthBar;
public Text playerHealthText;
public Text playerLevelText;
public Slider playerExpBar;
public Image playerAvatar;
public Slider playerMPBar;
public Text playerMPText;
public GameObject hudObject;
public HealthManager playerHealthManager;
public MPManager playerMPManager;
public CharacterStats playerStats;
private WeaponManager weaponManager;
private ItemsManager itemsManager;
private ArmorManager armorManager;
private AccesoryManager accesoryManager;
private PlayerController thePlayer;
private MoneyManager moneyManager;
private void Start()
{
weaponManager = FindObjectOfType<WeaponManager>();
itemsManager = FindObjectOfType<ItemsManager>();
armorManager = FindObjectOfType<ArmorManager>();
accesoryManager = FindObjectOfType<AccesoryManager>();
thePlayer = FindObjectOfType<PlayerController>();
moneyManager = FindObjectOfType<MoneyManager>();
inventoryPanel.SetActive(false);
menuPanel.SetActive(false);
menuStats.SetActive(false);
descriptionMenu.SetActive(false);
}
public Image mpFillBar;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.I))
{
if(thePlayer.isTalking || thePlayer.isDead || thePlayer.inTransition || !thePlayer.canMove)
{
return;
}
ToggleInventory();
}
playerHealthBar.maxValue = playerHealthManager.maxHealth;
playerHealthBar.value = playerHealthManager.Health;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("HP: ").Append(playerHealthManager.Health).Append("/").Append(playerHealthManager.maxHealth);
playerHealthText.text = stringBuilder.ToString();
if (playerMPManager.mpCharge || playerMPManager.MagicPoints <=0)
{
mpFillBar.color = Color.magenta;
playerMPBar.maxValue = playerMPManager.mpChargerTime;
playerMPBar.value = playerMPManager.timeCounter;
StringBuilder stringBuilder3 = new StringBuilder();
stringBuilder3.Append("Charging: ").Append((int)playerMPManager.timeCounter).Append("/").Append(playerMPManager.mpChargerTime);
playerMPText.text = stringBuilder3.ToString();
}
else
{
mpFillBar.color = Color.blue;
playerMPBar.maxValue = playerMPManager.maxMP;
playerMPBar.value = playerMPManager.MagicPoints;
StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.Append("MP: ").Append(playerMPManager.MagicPoints).Append("/").Append(playerMPManager.maxMP);
playerMPText.text = stringBuilder2.ToString();
}
}
public GameObject inventoryPanel, menuPanel, menuStats, descriptionMenu;
public Button inventoryButton;
//DescriptionBox Info
public Text descriptionText;
public Text strTextDesc;
public Text defTextDesc;
public Text matTextDesc;
public Text mdfTextDesc;
public Text spdTextDesc;
public Text lckTextDesc;
public Text accTextDesc;
public Text baseDamageDesc;
public void ToggleInventory()
{
if (thePlayer.isTalking || thePlayer.isDead || thePlayer.inTransition || !thePlayer.canMove)
{
return;
}
thePlayer.inInventory = !thePlayer.inInventory;
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.UI_START_MENU_SELECT);
ChangeDescriptionText();
inventoryPanel.SetActive(!inventoryPanel.activeInHierarchy);
menuPanel.SetActive(!menuPanel.activeInHierarchy);
menuStats.SetActive(!menuStats.activeInHierarchy);
descriptionMenu.SetActive(!descriptionMenu.activeInHierarchy);
if (inventoryPanel.activeInHierarchy)
{
Time.timeScale = 0;
foreach (Transform t in inventoryPanel.transform)
{
Destroy(t.gameObject);
}
FillInventory();
MenuStatsFill();
}
else { Time.timeScale = 1; }
}
public void FillInventory()
{
List<GameObject> weapons =weaponManager.GetAllWeapons();
int i = 0;
foreach(GameObject w in weapons)
{
AddItemToInventory(w, InventoryButton.ItemType.WEAPON, i, "");
i++;
}
List<GameObject> keyItems = itemsManager.GetQuestItems();
i= 0;
foreach(GameObject item in keyItems)
{
AddItemToInventory(item, InventoryButton.ItemType.SPECIAL_ITEMS, i, "");
i++;
}
List<GameObject> armors = armorManager.GetAllArmors();
i = 0;
foreach (GameObject a in armors)
{
AddItemToInventory(a, InventoryButton.ItemType.ARMOR, i, "");
i++;
}
List<GameObject> accesories = accesoryManager.GetAllAccesories();
i = 0;
foreach (GameObject ac in accesories)
{
AddItemToInventory(ac, InventoryButton.ItemType.ACCESORY, i, "");
i++;
}
//Potions
if (itemsManager.currentPotions > 0)
{
//Obtiene del ItemManager el GameObject de la potion, para poder usar su sprite
GameObject potionObject = itemsManager.potionObject;
int potionsQuantity = itemsManager.currentPotions;
i = 0;
AddItemToInventory(potionObject, InventoryButton.ItemType.ITEM, i, "" + potionsQuantity);
}
//Ethers
if (itemsManager.currentEthers > 0)
{
//Obtiene del ItemManager el GameObject de la potion, para poder usar su sprite
GameObject etherObject = itemsManager.etherObject;
int ethersQuantity = itemsManager.currentEthers;
i = 1;
AddItemToInventory(etherObject, InventoryButton.ItemType.ITEM, i, "" + ethersQuantity);
}
//PDs
if (itemsManager.currentPhoenixDown > 0)
{
//Obtiene del ItemManager el GameObject de la potion, para poder usar su sprite
GameObject pdObject = itemsManager.phoenixDownObject;
int pdQuantity = itemsManager.currentPhoenixDown;
i = 2;
AddItemToInventory(pdObject, InventoryButton.ItemType.ITEM, i, "" + pdQuantity);
}
}
private void AddItemToInventory(GameObject item, InventoryButton.ItemType type, int pos, string valuetext)
{
Button tempB = Instantiate(inventoryButton, inventoryPanel.transform);
tempB.GetComponent<InventoryButton>().type = type;
tempB.GetComponent<InventoryButton>().itemIdx = pos;
tempB.GetComponent<InventoryButton>().itemText.text = valuetext;
tempB.onClick.AddListener(() => tempB.GetComponent<InventoryButton>().ActivateButton());
tempB.image.sprite = item.GetComponent<SpriteRenderer>().sprite;
}
public void ShowOnly(int type)
{
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.UI_MENU_SELECT);
foreach (Transform t in inventoryPanel.transform)
{
t.gameObject.SetActive((int)t.GetComponent<InventoryButton>().type == type);
}
}
public void ShowAll()
{
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.UI_MENU_SELECT);
foreach (Transform t in inventoryPanel.transform)
{
t.gameObject.SetActive(true);
}
}
public void ChangeAvatarImage(Sprite sprite)
{
playerAvatar.sprite = sprite;
}
public Text levelStatText;
public Text expStatText;
public Text exptoNextLevelText;
public Text strText;
public Text defText;
public Text matText;
public Text mdfText;
public Text spdText;
public Text lckText;
public Text accText;
public Text weaponEq;
public Text armorEq;
public Text accesoryEq;
public void WeaponEq()
{
weaponEq.text = "Weapon: " + weaponManager.GetWeaponAt(weaponManager.activeWeapon).weaponName;
}
public void ArmorEq()
{
armorEq.text = "Armor: " + armorManager.GetArmorAt(armorManager.activeArmor).armorName;
}
public void AccesoryEq()
{
accesoryEq.text = "Accesory: " + accesoryManager.GetAccesoryAt(accesoryManager.activeAccesory).accesoryName;
}
public void MenuStatsFill()
{
levelStatText.text = "Level: " + playerStats.level;
expStatText.text = "Exp: " + playerStats.exp;
exptoNextLevelText.text = "Exp to next level: " + playerStats.expToLevelUp[playerStats.level];
strText.text = "STR: " + playerStats.newstrengthLevels;
defText.text = "DEF: " + playerStats.newdefenseLevels;
matText.text = "MAT: " + playerStats.newmagicAttLevels;
mdfText.text = "MDF: " + playerStats.newmagicDefLevels;
spdText.text = "SPD: " + playerStats.newspeedLevels;
lckText.text = "LCK: " + playerStats.newluckLevels;
accText.text = "ACC: " + playerStats.newaccuracyLevels;
}
/// <summary>
/// HUD
/// </summary>
public void LevelChanged(int newlevel, int expToLevelUpLength, int maxValue, int minValue)
{
playerLevelText.text = "Level: " + newlevel; //UI LEvel text
if (newlevel >= expToLevelUpLength)
{
playerExpBar.enabled = false;
return;
}
playerExpBar.maxValue = maxValue;
playerExpBar.minValue = minValue;
}
public void ExpChanged(int exp)
{
playerExpBar.value = playerStats.exp;
}
/// <summary>
/// Inventory Description
/// </summary>
public void ChangeDescriptionText()
{
descriptionText.text = "";
strTextDesc.text = "";
defTextDesc.text = "";
matTextDesc.text = "";
mdfTextDesc.text = "";
spdTextDesc.text = "";
lckTextDesc.text = "";
accTextDesc.text = "";
baseDamageDesc.text = "";
}
public void ChangeDescriptionText(string description)
{
descriptionText.text = "Description: " + description;
}
public void ChangeDescriptionText(string desc, string strdesc, string defdesc, string matdesc, string mdfdesc,
string spddesc, string lckdesc, string accdesc, string damagedesc)
{
descriptionText.text = "Description: " + desc;
strTextDesc.text = "STR: " + strdesc;
defTextDesc.text = "DEF: " + defdesc;
matTextDesc.text = "MAT: " +matdesc;
mdfTextDesc.text = "MDF: " +mdfdesc;
spdTextDesc.text = "SPD: " +spddesc;
lckTextDesc.text = "LCK: " +lckdesc;
accTextDesc.text = "ACC: " +accdesc;
baseDamageDesc.text = "Damage: " +damagedesc;
}
/// <summary>
/// Skills Panel
/// </summary>
public GameObject skillPanel;
//public Button dashSkill;
//public Button fireSkill;
//public Button thunderSkill;
//public Button iceSkill;
public List<Button> skillList = new List<Button>();
public void ActivateSkill(string skillname)
{
foreach(Button skill in skillList)
{
if(skill.GetComponent<SkillButton>().type.ToString() == skillname)
{
skill.gameObject.SetActive(true);
skill.GetComponent<SkillButton>().inInventory = true;
}
}
}
public List<string> ReturnAllActiveSkills()
{
List<string> activeSkillList = new List<string>();
foreach (Button skill in skillList)
{
if (skill.GetComponent<SkillButton>().inInventory)
{
activeSkillList.Add(skill.GetComponent<SkillButton>().type.ToString());
}
}
return activeSkillList;
}
public void ResetAllSkills()
{
foreach (Button skill in skillList)
{
skill.gameObject.SetActive(false);
skill.GetComponent<SkillButton>().inInventory = false;
}
}
public void ActivateSkillPanel()
{
skillPanel.SetActive(true);
}
/// <summary>
/// GameOver
/// </summary>
public GameObject GameOverPanel;
public Button newStartButton;
public Button phoenixDownButton;
public Button ExitGameButton;
public void LaunchGameOver()
{
GameOverPanel.SetActive(true);
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.GAME_OVER);
FindObjectOfType<AudioManager>().audioCanBePlayed = false;
}
public void NewStart()
{
//ResetPlayer();
thePlayer.nextUuid = "StartGame";
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.UI_START_MENU_SELECT);
FindObjectOfType<SceneTransition>().Transition("MainScreen");
GameOverPanel.SetActive(false);
FindObjectOfType<AudioManager>().audioCanBePlayed = true;
}
public void ExitGame()
{
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.UI_START_MENU_SELECT);
Application.Quit();
}
public void PhoenixDown()
{
if (itemsManager.currentPhoenixDown <= 0)
{
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.UI_MENU_ERROR);
return;
}
SFXManager.SharedInstance.PlaySFX(SFXType.SoundType.UI_START_MENU_SELECT);
itemsManager.UsePD();
thePlayer.isDead = false;
thePlayer.DeactivateDeadAnimation();
thePlayer.isTalking = false;
thePlayer.canMove = true;
thePlayer.GetComponent<CircleCollider2D>().enabled = true;
GameOverPanel.SetActive(false);
FindObjectOfType<AudioManager>().audioCanBePlayed = true;
}
void ResetPlayer()
{
thePlayer.isDead = false;
thePlayer.DeactivateDeadAnimation();
thePlayer.isTalking = true;
thePlayer.canMove = false;
weaponManager.DeactivateWeapon(false);
thePlayer.nextUuid = "StartGame";
CharacterStats thePlayerStats = thePlayer.GetComponent<CharacterStats>();
thePlayerStats.level = 1;
thePlayerStats.exp = 0;
ExpChanged(thePlayerStats.exp);
thePlayerStats.InitialStats();
thePlayer.GetComponent<HealthManager>().UpdateMaxHealth(thePlayerStats.hpLevels[thePlayerStats.level]);
thePlayer.GetComponent<MPManager>().UpdateMaxMP(thePlayerStats.mpLevels[thePlayerStats.level]);
LevelChanged(thePlayerStats.level, thePlayerStats.expToLevelUp.Length,
thePlayerStats.expToLevelUp[thePlayerStats.level],
thePlayerStats.expToLevelUp[thePlayerStats.level - 1]);
moneyManager.ResetMoney();
itemsManager.currentEthers = 0;
itemsManager.currentPotions = 0;
itemsManager.currentPhoenixDown = 0;
itemsManager.RemoveQuestItems();
FindObjectOfType<QuestManager>().ResetAllQuests();
ResetAllSkills();
weaponManager.ResetAllWeapons();
armorManager.ResetAllArmors();
accesoryManager.ResetAllAccesories();
}
}