PopupGUIManager as ModSystem

This commit is contained in:
Flowaria authored and Cameron Ewell committed 2024-09-30 03:37:06 -04:00
1 parent 1050972ce9
commit e94aa9212e
3 files changed
+12 -18

No files matched your search

-2
View File
@@ -132,8 +132,6 @@ namespace CalamityMod
CalamityGlobalItem.UnloadTweaks();
CalamityGlobalProjectile.UnloadTweaks();
PopupGUIManager.UnloadGUIs();
Main.QueueMainThreadAction(() =>
{
Main.OnPreDraw -= PrepareRenderTargets;
-1
View File
@@ -201,7 +201,6 @@ namespace CalamityMod
if (!Main.dedServ)
{
WikiThisSupport();
PopupGUIManager.LoadGUIs();
}
}
+12 -15
View File
@@ -8,10 +8,10 @@ using Terraria.ModLoader.Core;
namespace CalamityMod.UI
{
// TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks.
public static class PopupGUIManager
[Autoload(Side = ModSide.Client)]
public sealed class PopupGUIManager : ModSystem
{
private static readonly List<PopupGUI> gUIs = new List<PopupGUI>();
private 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);
@@ -57,21 +57,18 @@ namespace CalamityMod.UI
gUIs.First(gui => gui.GetType() == type).Active = !gUIs.First(gui => gui.GetType() == type).Active;
}
public static void LoadGUIs()
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.
foreach (Mod mod in ModLoader.Mods)
ReflectionHelper.IterateEveryModsTypes<PopupGUI>(action: type =>
{
foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code))
{
// Don't load abstract classes since they cannot have instances.
if (type.IsAbstract)
continue;
if (type.IsSubclassOf(typeof(PopupGUI)))
gUIs.Add(Activator.CreateInstance(type) as PopupGUI);
}
}
gUIs.Add(Activator.CreateInstance(type) as PopupGUI);
});
}
public override void Unload()
{
gUIs?.Clear();
}
public static void UnloadGUIs() => gUIs.Clear();
}
}