diff --git a/src/OWML.Common/Interfaces/IModBehaviour.cs b/src/OWML.Common/Interfaces/IModBehaviour.cs
index 018fe1cf..fa8f827b 100644
--- a/src/OWML.Common/Interfaces/IModBehaviour.cs
+++ b/src/OWML.Common/Interfaces/IModBehaviour.cs
@@ -22,18 +22,33 @@ public interface IModBehaviour
///
void SetupTitleMenu(ITitleMenuManager titleManager);
+ ///
+ /// Called when leaving the title menu scene. Put any event unsubscriptions here.
+ ///
+ void CleanupTitleMenu();
+
///
/// Called when the SolarSystem or EyeOfTheUniverse scene has loaded in.
/// Put any code that edits the pause menu here.
///
void SetupPauseMenu(IPauseMenuManager pauseManager);
+ ///
+ /// Called when leaving either game scene. Put any event unsubscriptions here.
+ ///
+ void CleanupPauseMenu();
+
///
/// Called when the main menu or game has loaded in.
/// Put any code that edits the options menu here.
///
void SetupOptionsMenu(IOptionsMenuManager optionsManager);
+ ///
+ /// Called when leaving the title or either game scene. Put any event unsubscriptions here.
+ ///
+ void CleanupOptionsMenu();
+
void Init(IModHelper helper);
}
}
diff --git a/src/OWML.ModHelper.Menus/NewMenuSystem/MenuManager.cs b/src/OWML.ModHelper.Menus/NewMenuSystem/MenuManager.cs
index 8e511fcf..f16142ff 100644
--- a/src/OWML.ModHelper.Menus/NewMenuSystem/MenuManager.cs
+++ b/src/OWML.ModHelper.Menus/NewMenuSystem/MenuManager.cs
@@ -58,6 +58,23 @@ public MenuManager(
var harmonyInstance = harmony.GetValue("_harmony");
harmonyInstance.PatchAll(typeof(Patches));
+ LoadManager.OnStartSceneLoad += (oldScene, newScene) =>
+ {
+ foreach (var mod in ((IMenuManager)this).ModList)
+ {
+ if (oldScene == OWScene.TitleScreen)
+ {
+ mod.CleanupTitleMenu();
+ mod.CleanupOptionsMenu();
+ }
+ else if (oldScene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse)
+ {
+ mod.CleanupPauseMenu();
+ mod.CleanupOptionsMenu();
+ }
+ }
+ };
+
LoadManager.OnCompleteSceneLoad += (_, newScene) =>
{
_hasSetupMenusThisScene = false;
diff --git a/src/OWML.ModHelper/ModBehaviour.cs b/src/OWML.ModHelper/ModBehaviour.cs
index 5fa3e8b2..31f2588d 100644
--- a/src/OWML.ModHelper/ModBehaviour.cs
+++ b/src/OWML.ModHelper/ModBehaviour.cs
@@ -24,17 +24,14 @@ public virtual void Configure(IModConfig config)
public virtual object GetApi() => null;
- public virtual void SetupTitleMenu(ITitleMenuManager titleManager)
- {
- }
+ public virtual void SetupTitleMenu(ITitleMenuManager titleManager) { }
+ public virtual void CleanupTitleMenu() { }
- public virtual void SetupPauseMenu(IPauseMenuManager pauseManager)
- {
- }
+ public virtual void SetupPauseMenu(IPauseMenuManager pauseManager) { }
+ public virtual void CleanupPauseMenu() { }
- public virtual void SetupOptionsMenu(IOptionsMenuManager optionsManager)
- {
- }
+ public virtual void SetupOptionsMenu(IOptionsMenuManager optionsManager) { }
+ public virtual void CleanupOptionsMenu() { }
public IList GetDependants() =>
ModHelper.Interaction.GetDependants(ModHelper.Manifest.UniqueName);
diff --git a/src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs b/src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs
index 3799cde0..ff87e024 100644
--- a/src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs
+++ b/src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs
@@ -84,6 +84,11 @@ public override void SetupTitleMenu(ITitleMenuManager titleManager)
}
+ public override void CleanupTitleMenu()
+ {
+ ModHelper.Console.WriteLine($"CLEANUP TITLE MENU");
+ }
+
public override void SetupPauseMenu(IPauseMenuManager pauseManager)
{
var listMenu = pauseManager.MakePauseListMenu("TEST");
@@ -93,8 +98,24 @@ public override void SetupPauseMenu(IPauseMenuManager pauseManager)
var button2 = pauseManager.MakeSimpleButton("2", 1, true, listMenu);
var button3 = pauseManager.MakeSimpleButton("3", 2, true, listMenu);
- pauseManager.PauseMenuOpened += () => ModHelper.Console.WriteLine($"PAUSE MENU OPENED!", MessageType.Success);
- pauseManager.PauseMenuClosed += () => ModHelper.Console.WriteLine($"PAUSE MENU CLOSED!", MessageType.Success);
+ pauseManager.PauseMenuOpened += LogOpened;
+ pauseManager.PauseMenuClosed += LogClosed;
+ }
+
+ public override void CleanupPauseMenu()
+ {
+ ModHelper.MenuHelper.PauseMenuManager.PauseMenuOpened -= LogOpened;
+ ModHelper.MenuHelper.PauseMenuManager.PauseMenuClosed -= LogClosed;
+ }
+
+ private void LogOpened()
+ {
+ ModHelper.Console.WriteLine($"PAUSE MENU OPENED!", MessageType.Success);
+ }
+
+ private void LogClosed()
+ {
+ ModHelper.Console.WriteLine($"PAUSE MENU CLOSED!", MessageType.Success);
}
public override void SetupOptionsMenu(IOptionsMenuManager optionsManager)
@@ -120,6 +141,11 @@ public override void SetupOptionsMenu(IOptionsMenuManager optionsManager)
var slider = optionsManager.AddSliderInput(subTab2Menu, "Test Slider", 0, 100, "* It's a test slider.", 50);
}
+ public override void CleanupOptionsMenu()
+ {
+ ModHelper.Console.WriteLine($"CLEANUP OPTIONS MENU");
+ }
+
private void TestAPI()
{
var api = ModHelper.Interaction.TryGetModApi("_nebula.ExampleAPI");