diff --git a/UI/PopupGUI.cs b/UI/PopupGUI.cs index 1704d2d95a..8cf0dc0fa2 100644 --- a/UI/PopupGUI.cs +++ b/UI/PopupGUI.cs @@ -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) diff --git a/UI/PopupGUIManager.cs b/UI/PopupGUIManager.cs index 7b86ad0a6e..f97185dee0 100644 --- a/UI/PopupGUIManager.cs +++ b/UI/PopupGUIManager.cs @@ -10,7 +10,7 @@ namespace CalamityMod.UI [Autoload(Side = ModSide.Client)] public sealed class PopupGUIManager : ModSystem { - private static readonly List gUIs = []; + internal static readonly List 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(action: type => - { - gUIs.Add(Activator.CreateInstance(type) as PopupGUI); - }); - } - public override void Unload() { gUIs?.Clear();