InvasionProgressUI as ILoadable
This commit is contained in:
1 parent
8e4ff84f18
commit
a5c107810a
2 files changed
+14
-11
No files matched your search
@@ -5,10 +5,11 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.GameContent;
|
||||
using Terraria.Localization;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.UI
|
||||
{
|
||||
public abstract class InvasionProgressUI
|
||||
public abstract class InvasionProgressUI : ILoadable
|
||||
{
|
||||
public virtual int SecondaryDigitPrecision { get; } = 0;
|
||||
public abstract bool IsActive { get; }
|
||||
@@ -89,5 +90,15 @@ namespace CalamityMod.UI
|
||||
DrawBackground(spriteBatch, yScale, newBarPosition, barOffsetY);
|
||||
DrawProgressTextAndIcons(spriteBatch, barOffsetY);
|
||||
}
|
||||
|
||||
public void Load(Mod mod)
|
||||
{
|
||||
InvasionProgressUIManager.gUIs.Add(this);
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ namespace CalamityMod.UI
|
||||
[Autoload(Side = ModSide.Client)]
|
||||
public sealed class InvasionProgressUIManager : ModSystem
|
||||
{
|
||||
private static readonly List<InvasionProgressUI> gUIs = [];
|
||||
internal 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,15 +24,6 @@ namespace CalamityMod.UI
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
ReflectionHelper.IterateCalamityTypes<InvasionProgressUI>(action: type =>
|
||||
{
|
||||
gUIs.Add(Activator.CreateInstance(type) as InvasionProgressUI);
|
||||
});
|
||||
}
|
||||
|
||||
public override void Unload()
|
||||
{
|
||||
gUIs?.Clear();
|
||||
|
||||
Reference in new issue
Block a user