InvasionProgressUIManager as ModSystem

This commit is contained in:
Flowaria authored and Cameron Ewell committed 2024-09-30 03:37:06 -04:00
1 parent 40b269ee30
commit 64a0223fcc
2 files changed
+13 -16

No files matched your search

-3
View File
@@ -158,8 +158,6 @@ namespace CalamityMod
{
Main.OnPreDraw += PrepareRenderTargets;
});
InvasionProgressUIManager.LoadGUIs();
}
#endregion
@@ -177,7 +175,6 @@ namespace CalamityMod
CalamityGlobalProjectile.UnloadTweaks();
PopupGUIManager.UnloadGUIs();
InvasionProgressUIManager.UnloadGUIs();
SchematicManager.Unload();
PlayerDashManager.Unload();
+13 -13
View File
@@ -2,14 +2,15 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ModLoader;
using Terraria.ModLoader.Core;
namespace CalamityMod.UI
{
// TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks.
public static class InvasionProgressUIManager
[Autoload(Side = ModSide.Client)]
public sealed class InvasionProgressUIManager : ModSystem
{
private static readonly List<InvasionProgressUI> gUIs = new List<InvasionProgressUI>();
private static readonly List<InvasionProgressUI> gUIs = [];
public static int TotalGUIsActive => gUIs.Count(gui => gui.IsActive);
public static bool AnyGUIsActive => TotalGUIsActive > 0;
public static InvasionProgressUI GetActiveGUI => gUIs.FirstOrDefault(gui => gui.IsActive);
@@ -23,19 +24,18 @@ namespace CalamityMod.UI
}
}
public static void LoadGUIs()
public override void OnModLoad()
{
// Look through every type in the mod, and check if it's derived from InvasionProgressUI. If it is, create a copy and save it in the static list.
Type[] types = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code);
foreach (Type type in types)
ReflectionHelper.IterateCalamityModTypes<InvasionProgressUI>(includeBaseType: false, type =>
{
// Don't load abstract classes since they cannot have instances.
if (type.IsAbstract)
continue;
if (type.IsSubclassOf(typeof(InvasionProgressUI)))
gUIs.Add(Activator.CreateInstance(type) as InvasionProgressUI);
}
gUIs.Add(Activator.CreateInstance(type) as InvasionProgressUI);
});
}
public override void Unload()
{
gUIs?.Clear();
}
public static void UnloadGUIs() => gUIs.Clear();
}
}