PopupGUI as ILoadable
This commit is contained in:
1 parent
b52c2c01a2
commit
4ab4bcdd3c
2 files changed
+15
-11
No files matched your search
+14
-1
@@ -1,14 +1,27 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.UI
|
||||
{
|
||||
public abstract class PopupGUI
|
||||
[Autoload(Side = ModSide.Client)]
|
||||
public abstract class PopupGUI : ILoadable
|
||||
{
|
||||
public int FadeTime;
|
||||
public bool Active;
|
||||
public virtual int FadeTimeMax { get; set; } = 30;
|
||||
|
||||
public void Load(Mod mod)
|
||||
{
|
||||
PopupGUIManager.gUIs.Add(this);
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
if (Active)
|
||||
|
||||
+1
-10
@@ -10,7 +10,7 @@ namespace CalamityMod.UI
|
||||
[Autoload(Side = ModSide.Client)]
|
||||
public sealed class PopupGUIManager : ModSystem
|
||||
{
|
||||
private static readonly List<PopupGUI> gUIs = [];
|
||||
internal static readonly List<PopupGUI> gUIs = [];
|
||||
public static bool GUIActive(PopupGUI gui) => gui.Active || gui.FadeTime > 0;
|
||||
public static bool AnyGUIsActive => gUIs.Any(GUIActive);
|
||||
public static PopupGUI GetActiveGUI => gUIs.FirstOrDefault(GUIActive);
|
||||
@@ -56,15 +56,6 @@ namespace CalamityMod.UI
|
||||
gUIs.First(gui => gui.GetType() == type).Active = !gUIs.First(gui => gui.GetType() == type).Active;
|
||||
}
|
||||
|
||||
public override void OnModLoad()
|
||||
{
|
||||
// Look through every type in the mod, and check if it's derived from PopupGUI. If it is, create a copy and save it in the static list.
|
||||
ReflectionHelper.IterateEveryModsTypes<PopupGUI>(action: type =>
|
||||
{
|
||||
gUIs.Add(Activator.CreateInstance(type) as PopupGUI);
|
||||
});
|
||||
}
|
||||
|
||||
public override void Unload()
|
||||
{
|
||||
gUIs?.Clear();
|
||||
|
||||
Reference in new issue
Block a user