forked from MadYeling/Fargowiltas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIManager.cs
106 lines (92 loc) · 3.83 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
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.UI;
using Fargowiltas.UI;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ModLoader;
using Terraria.ID;
using Fargowiltas;
using Terraria.Audio;
using ReLogic.Content;
namespace Fargowilta
{
public class UIManager
{
public UserInterface StatSheetUserInterface;
public UserInterface StatSheetTogglerUserInterface;
public StatSheetUI StatSheet;
public StatButton StatButton;
private GameTime _lastUpdateUIGameTime;
public Asset<Texture2D> StatsButtonTexture;
public Asset<Texture2D> StatsButton_MouseOverTexture;
public void LoadUI()
{
if (!Main.dedServ)
{
// Load textures
StatsButtonTexture = (ModContent.Request<Texture2D>("Fargowiltas/UI/Assets/StatsButton", AssetRequestMode.ImmediateLoad));
StatsButton_MouseOverTexture = (ModContent.Request<Texture2D>("Fargowiltas/UI/Assets/StatsButton_MouseOver", AssetRequestMode.ImmediateLoad));
// Initialize UserInterfaces
StatSheetUserInterface = new UserInterface();
StatSheetTogglerUserInterface = new UserInterface();
// Activate UIs
StatSheet = new StatSheetUI();
StatSheet.Activate();
StatButton = new StatButton();
StatButton.Activate();
StatSheetTogglerUserInterface.SetState(StatButton);
}
}
public void UpdateUI(GameTime gameTime)
{
_lastUpdateUIGameTime = gameTime;
if (!Main.playerInventory)
CloseStatSheet();
if (StatSheetUserInterface?.CurrentState != null)
StatSheetUserInterface.Update(gameTime);
if (StatSheetTogglerUserInterface?.CurrentState != null)
StatSheetTogglerUserInterface.Update(gameTime);
}
public bool IsStatSheetOpen() => StatSheetUserInterface?.CurrentState == null;
public void CloseStatSheet() => StatSheetUserInterface?.SetState(null);
//public bool IsTogglerOpen() => TogglerUserInterface.CurrentState == StatSheet;
public void OpenStatSheet() => StatSheetUserInterface.SetState(StatSheet);
public void ToggleStatSheet()
{
if (IsStatSheetOpen())
{
SoundEngine.PlaySound(SoundID.MenuOpen);
OpenStatSheet();
}
else// if (IsTogglerOpen())
{
SoundEngine.PlaySound(SoundID.MenuClose);
CloseStatSheet();
}
}
public void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int index = layers.FindIndex((layer) => layer.Name == "Vanilla: Inventory");
if (index != -1)
{
layers.Insert(index - 1, new LegacyGameInterfaceLayer("Fargos: Stat Sheet", delegate
{
if (_lastUpdateUIGameTime != null && StatSheetUserInterface?.CurrentState != null)
StatSheetUserInterface.Draw(Main.spriteBatch, _lastUpdateUIGameTime);
return true;
}, InterfaceScaleType.UI));
}
index = layers.FindIndex((layer) => layer.Name == "Vanilla: Mouse Text");
if (index != -1)
{
layers.Insert(index, new LegacyGameInterfaceLayer("Fargos: Stat Sheet Toggler", delegate
{
if (_lastUpdateUIGameTime != null && StatSheetTogglerUserInterface?.CurrentState != null)
StatSheetTogglerUserInterface.Draw(Main.spriteBatch, _lastUpdateUIGameTime);
return true;
}, InterfaceScaleType.UI));
}
}
}
}