-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeaponOven.cs
88 lines (83 loc) · 2.01 KB
/
WeaponOven.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
using Terraria;
using Terraria.ModLoader;
using Terraria.UI;
using WeaponOven.Ovens.Tiles;
using WeaponOven.UI;
using Terraria.Audio;
using Terraria.ID;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
namespace WeaponOven
{
public class WeaponOven : Mod
{
}
class OvenUISystem : ModSystem
{
internal UserInterface oveninterface;
internal OvenInterface ovenUI;
internal
static OvenUISystem Instance { get; private set; }
public override void Load()
{
Instance=this;
if (!Main.dedServ)
{
oveninterface = new UserInterface();
ovenUI = new OvenInterface();
ovenUI.Activate();
}
}
public override void Unload()
{
Instance = null;
oveninterface = null;
ovenUI = null;
}
private GameTime _lastUpdateUiGameTime;
public override void UpdateUI(GameTime gameTime)
{
_lastUpdateUiGameTime = gameTime;
if (Instance.oveninterface?.CurrentState != null)
{
Instance.oveninterface.Update(gameTime);
}
}
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int mouseTextIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));
if (mouseTextIndex != -1)
{
layers.Insert(mouseTextIndex, new LegacyGameInterfaceLayer(
"WeaponOven: OvenUI",
delegate
{
if (_lastUpdateUiGameTime != null && Instance.oveninterface?.CurrentState != null)
{
Instance.oveninterface.Draw(Main.spriteBatch, _lastUpdateUiGameTime);
}
return true;
},
InterfaceScaleType.UI));
}
}
/// <summary>
/// Method for controlling the opening and closing of the oven UI
/// </summary>
/// <param name="open">Whether the UI should be opened or closed.</param>
internal static void SetUI(bool open)
{
if (open == true)
{
Main.playerInventory = true;
Instance.oveninterface.SetState(Instance.ovenUI);
SoundEngine.PlaySound(SoundID.MenuOpen);
}
else
{
Instance.oveninterface.SetState(null);
SoundEngine.PlaySound(SoundID.MenuClose);
}
}
}
}