forked from Werebearguy/AssortedCrazyThings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssUISystem.cs
466 lines (416 loc) · 12.5 KB
/
AssUISystem.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 AssortedCrazyThings.Base;
using AssortedCrazyThings.Items;
using AssortedCrazyThings.Items.PetAccessories;
using AssortedCrazyThings.UI;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.Audio;
using Terraria.Graphics;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.UI;
namespace AssortedCrazyThings
{
[Content(ConfigurationSystem.AllFlags, needsAllToFilter: true)]
public class AssUISystem : AssSystem
{
/// <summary>
/// Zoom level, (for UIs). 0f == fully zoomed out, 1f == fully zoomed in
/// </summary>
public static Vector2 ZoomFactor;
//UI stuff
internal static UserInterface CircleUIInterface;
internal static CircleUI CircleUI;
internal static UserInterface HoverNPCUIInterface;
internal static HoverNPCUI HoverNPCUI;
internal static UserInterface HarvesterEdgeUIInterface;
internal static UserInterface EnhancedHunterUIInterface;
internal static EnhancedHunterUI EnhancedHunterUI;
internal static UserInterface PetVanityUIInterface;
internal static PetVanityUI PetVanityUI;
public override void PostSetupContent()
{
if (!Main.dedServ && Main.netMode != NetmodeID.Server)
{
CircleUI = new CircleUI();
CircleUI.Activate();
CircleUIInterface = new UserInterface();
CircleUIInterface.SetState(CircleUI);
HoverNPCUI = new HoverNPCUI();
HoverNPCUI.Activate();
HoverNPCUIInterface = new UserInterface();
HoverNPCUIInterface.SetState(HoverNPCUI);
if (ContentConfig.Instance.Bosses)
{
EnhancedHunterUI = new EnhancedHunterUI();
EnhancedHunterUI.Activate();
EnhancedHunterUIInterface = new UserInterface();
EnhancedHunterUIInterface.SetState(EnhancedHunterUI);
}
if (ContentConfig.Instance.CuteSlimes)
{
PetVanityUI = new PetVanityUI();
PetVanityUI.Activate();
PetVanityUIInterface = new UserInterface();
PetVanityUIInterface.SetState(PetVanityUI);
}
}
}
public override void Unload()
{
if (!Main.dedServ && Main.netMode != NetmodeID.Server)
{
CircleUIInterface = null;
CircleUI = null;
HoverNPCUIInterface = null;
HoverNPCUI = null;
HarvesterEdgeUIInterface = null;
EnhancedHunterUIInterface = null;
EnhancedHunterUI = null;
PetVanityUIInterface = null;
PetVanityUI = null;
EnhancedHunterUI.arrowTexture = null;
PetVanityUI.redCrossTexture = null;
CircleUI.UIConf = null;
CircleUIHandler.TriggerListLeft.Clear();
CircleUIHandler.TriggerListRight.Clear();
}
}
/// <summary>
/// Creates golden dust particles at the projectiles location with that type and LocalPlayer as owner. (Used for pets)
/// </summary>
private void PoofVisual(int projType)
{
int projIndex = -1;
//find first occurence of a player owned projectile
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (Main.projectile[i].active)
{
if (Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == projType)
{
projIndex = i;
break;
}
}
}
if (projIndex != -1)
{
Dust dust;
for (int i = 0; i < 14; i++)
{
dust = Dust.NewDustDirect(Main.projectile[projIndex].position, Main.projectile[projIndex].width, Main.projectile[projIndex].height, 204, Main.projectile[projIndex].velocity.X, Main.projectile[projIndex].velocity.Y, 0, new Color(255, 255, 255), 0.8f);
dust.noGravity = true;
dust.noLight = true;
}
}
}
/// <summary>
/// Called when CircleUI starts
/// </summary>
private void CircleUIStart(int triggerType, bool triggerLeft = true, bool fromDresser = false)
{
AssPlayer mPlayer = Main.LocalPlayer.GetModPlayer<AssPlayer>();
PetPlayer pPlayer = Main.LocalPlayer.GetModPlayer<PetPlayer>();
//combine both lists of the players (split for organization and player load shenanigans)
List<CircleUIHandler> l = mPlayer.CircleUIList;
l.AddRange(pPlayer.CircleUIList);
bool found = false;
for (int i = 0; i < l.Count; i++)
{
if (l[i].Condition())
{
if (l[i].TriggerItem == triggerType)
{
if (l[i].TriggerLeft == triggerLeft)
{
CircleUI.UIConf = l[i].UIConf();
CircleUI.currentSelected = l[i].OnUIStart();
found = true;
break;
}
}
}
}
//extra things that happen
if (!found)
{
if (triggerType == ModContent.ItemType<VanitySelector>())
{
AssUtils.UIText("No alt costumes found for" + (triggerLeft ? "" : " light") + " pet", CombatText.DamagedFriendly);
return;
}
}
//Spawn UI
CircleUI.Start(triggerType, triggerLeft, fromDresser);
}
/// <summary>
/// Called when CircleUI ends
/// </summary>
private void CircleUIEnd(bool triggerLeft = true)
{
AssPlayer mPlayer = Main.LocalPlayer.GetModPlayer<AssPlayer>();
if (CircleUI.returned != CircleUI.NONE && CircleUI.returned != CircleUI.currentSelected)
{
//if something returned AND if the returned thing isn't the same as the current one
try
{
SoundEngine.PlaySound(SoundID.Item4.WithVolume(0.6f), Main.LocalPlayer.position);
}
catch
{
//No idea why but this threw errors one time
}
List<CircleUIHandler> l = mPlayer.CircleUIList;
for (int i = 0; i < l.Count; i++)
{
if (l[i].Condition())
{
if (l[i].TriggerItem == CircleUI.triggerItemType)
{
if (l[i].TriggerLeft == triggerLeft)
{
l[i].OnUIEnd();
break;
}
}
}
}
//extra things that happen
if (CircleUI.triggerItemType == ModContent.ItemType<VanitySelector>())
{
PoofVisual(CircleUI.UIConf.AdditionalInfo);
AssUtils.UIText("Selected: " + CircleUI.UIConf.Tooltips[CircleUI.returned], CombatText.HealLife);
}
}
CircleUI.returned = CircleUI.NONE;
CircleUI.visible = false;
}
/// <summary>
/// Called in UpdateUI
/// </summary>
private void UpdateCircleUI()
{
Player player = Main.LocalPlayer;
AssPlayer mPlayer = player.GetModPlayer<AssPlayer>();
int triggerType = player.HeldItem.type;
bool openWithDresser = mPlayer.mouseoveredDresser;
if (openWithDresser)
{
triggerType = ModContent.ItemType<VanitySelector>();
}
bool? left = null;
if (mPlayer.LeftClickPressed && (CircleUIHandler.TriggerListLeft.Contains(triggerType) || openWithDresser))
{
left = true;
}
else if (mPlayer.RightClickPressed && (CircleUIHandler.TriggerListRight.Contains(triggerType) || openWithDresser))
{
left = false;
}
if (left != null && AllowedToOpenUI()) CircleUIStart(triggerType, (bool)left, openWithDresser);
if (CircleUI.visible)
{
left = null;
if (mPlayer.LeftClickReleased)
{
left = true;
}
else if (mPlayer.RightClickReleased)
{
left = false;
}
if (left != null && left == CircleUI.openedWithLeft) CircleUIEnd((bool)left);
if (CircleUI.triggerItemType != triggerType && !CircleUI.triggeredFromDresser) //cancel the UI when you switch items
{
CircleUI.returned = CircleUI.NONE;
CircleUI.visible = false;
}
}
}
/// <summary>
/// Called in UpdateUI
/// </summary>
private void UpdatePetVanityUI()
{
Player player = Main.LocalPlayer;
AssPlayer mPlayer = player.GetModPlayer<AssPlayer>();
PetPlayer pPlayer = player.GetModPlayer<PetPlayer>();
int itemType = player.HeldItem.type;
if (mPlayer.LeftClickPressed && AllowedToOpenUI() && PetAccessory.TryGetAccessoryFromItem(itemType, out PetAccessory petAccessory))
{
if (petAccessory.HasAlts && pPlayer.HasValidSlimePet(out SlimePet slimePet) &&
!slimePet.IsSlotTypeBlacklisted[(int)petAccessory.Slot])
{
//Spawn UI
PetVanityUI.Start(petAccessory);
}
}
if (!PetVanityUI.visible)
{
return;
}
if (mPlayer.LeftClickReleased)
{
if (PetVanityUI.returned > PetVanityUI.NONE)
{
//if something returned AND if the returned thing isn't the same as the current one
try
{
SoundEngine.PlaySound(SoundID.Item1, player.position);
}
catch
{
//No idea why but this threw errors one time
}
//UIText("Selected: " + PetVanityUI.petAccessory.AltTextureSuffixes[PetVanityUI.returned], CombatText.HealLife);
PetVanityUI.petAccessory.AltTextureIndex = (byte)PetVanityUI.returned;
pPlayer.ToggleAccessory(PetVanityUI.petAccessory);
}
else if (PetVanityUI.hasEquipped && PetVanityUI.returned == PetVanityUI.NONE)
{
//hovered over the middle and had something equipped: take accessory away
pPlayer.DelAccessory(PetVanityUI.petAccessory);
}
//else if (returned == PetVanityUI.IGNORE) {nothing happens}
PetVanityUI.returned = PetVanityUI.NONE;
PetVanityUI.visible = false;
}
if (PetVanityUI.petAccessory.Type != itemType) //cancel the UI when you switch items
{
PetVanityUI.returned = PetVanityUI.NONE;
PetVanityUI.visible = false;
}
}
private void UpdateHoverNPCUI(GameTime gameTime)
{
HoverNPCUI.Update(gameTime);
}
private void UpdateEnhancedHunterUI(GameTime gameTime)
{
if (Main.LocalPlayer.GetModPlayer<AssPlayer>().enhancedHunterBuff)
{
EnhancedHunterUI.visible = true;
}
else
{
EnhancedHunterUI.visible = false;
}
EnhancedHunterUI?.Update(gameTime);
}
public override void UpdateUI(GameTime gameTime)
{
UpdateCircleUI();
UpdateHoverNPCUI(gameTime);
UpdateEnhancedHunterUI(gameTime);
UpdatePetVanityUI();
}
/// <summary>
/// Checks if LocalPlayer can open a UI
/// </summary>
private bool AllowedToOpenUI()
{
return Main.hasFocus &&
!Main.gamePaused &&
!Main.LocalPlayer.dead &&
!Main.LocalPlayer.mouseInterface &&
!Main.drawingPlayerChat &&
!Main.editSign &&
!Main.editChest &&
!Main.blockInput &&
!Main.mapFullscreen &&
!Main.HoveringOverAnNPC &&
Main.LocalPlayer.cursorItemIconID != -1 &&
Main.LocalPlayer.talkNPC == -1 &&
Main.LocalPlayer.itemTime == 0 && Main.LocalPlayer.itemAnimation == 0 &&
!(Main.LocalPlayer.frozen || Main.LocalPlayer.webbed || Main.LocalPlayer.stoned);
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int inventoryIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Hotbar"));
if (inventoryIndex != -1)
{
if (CircleUI.visible)
{
//remove the item icon when using the item while held outside the inventory
int mouseItemIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Item / NPC Head"));
if (mouseItemIndex != -1) layers.RemoveAt(mouseItemIndex);
layers.Insert(++inventoryIndex, new LegacyGameInterfaceLayer
(
"ACT: Appearance Select",
delegate
{
CircleUIInterface.Draw(Main.spriteBatch, new GameTime());
return true;
},
InterfaceScaleType.UI)
);
}
if (PetVanityUI.visible && PetVanityUIInterface != null)
{
//remove the item icon when using the item while held outside the inventory
int mouseItemIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Item / NPC Head"));
if (mouseItemIndex != -1) layers.RemoveAt(mouseItemIndex);
layers.Insert(++inventoryIndex, new LegacyGameInterfaceLayer
(
"ACT: Pet Vanity Select",
delegate
{
PetVanityUIInterface.Draw(Main.spriteBatch, new GameTime());
return true;
},
InterfaceScaleType.UI)
);
}
}
int mouseOverIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Over"));
if (mouseOverIndex != -1)
{
layers.Insert(++mouseOverIndex, new LegacyGameInterfaceLayer
(
"ACT: NPC Mouse Over",
delegate
{
HoverNPCUIInterface.Draw(Main.spriteBatch, new GameTime());
return true;
},
InterfaceScaleType.UI)
);
if (EnhancedHunterUIInterface != null)
{
if (EnhancedHunterUI.visible)
{
layers.Insert(++mouseOverIndex, new LegacyGameInterfaceLayer
(
"ACT: Enhanced Hunter",
delegate
{
EnhancedHunterUIInterface.Draw(Main.spriteBatch, new GameTime());
return true;
},
InterfaceScaleType.UI)
);
}
}
if (HarvesterEdgeUIInterface != null)
{
layers.Insert(++mouseOverIndex, new LegacyGameInterfaceLayer
(
"ACT: Harvester Edge",
delegate
{
HarvesterEdgeUIInterface.Draw(Main.spriteBatch, new GameTime());
return true;
},
InterfaceScaleType.UI)
);
}
}
}
public override void ModifyTransformMatrix(ref SpriteViewMatrix Transform)
{
ZoomFactor = Transform.Zoom - (Vector2.UnitX + Vector2.UnitY);
}
}
}