diff --git a/RogueLibs/CustomMutator.cs b/RogueLibs/CustomMutator.cs index bdba6208d..b996281d3 100644 --- a/RogueLibs/CustomMutator.cs +++ b/RogueLibs/CustomMutator.cs @@ -78,8 +78,31 @@ public override bool Available /// public event Action OnUnlockedInMutatorMenu; + /// + /// Event that is invoked when this mutator is toggled on, in the Mutator menu or by cancellations. + /// + public event Action OnEnabled; + /// + /// Event that is invoked when this mutator is toggled off, in the Mutator menu or by cancellations. + /// + public event Action OnDisabled; + /// + /// Event that is invoked when this mutator is toggled on/off, in the Mutator menu or by cancellations. + /// obj is the new mutator's state. + /// + public event Action OnChangedState; + internal void InvokeOnToggledEvent(ScrollingMenu sm, ButtonHelper bh, bool newState) => OnToggledInMutatorMenu?.Invoke(sm, bh, newState); internal void InvokeOnUnlockedEvent(ScrollingMenu sm, ButtonHelper bh) => OnUnlockedInMutatorMenu?.Invoke(sm, bh); + /// + /// Invoke this method when you enable/disable custom mutators from other mods! + /// + public void InvokeOnChangedState(bool newState) + { + (newState ? OnEnabled : OnDisabled)?.Invoke(); + OnChangedState?.Invoke(newState); + } + } } diff --git a/RogueLibs/CustomUnlock.cs b/RogueLibs/CustomUnlock.cs index 5721f7a58..c583e4acf 100644 --- a/RogueLibs/CustomUnlock.cs +++ b/RogueLibs/CustomUnlock.cs @@ -53,7 +53,12 @@ internal CustomUnlock(string id, CustomName name, CustomName description) public int CompareTo(CustomUnlock another) { int res = SortingOrder.CompareTo(another.SortingOrder); - return res != 0 ? res : SortingIndex.CompareTo(another.SortingIndex); + if (res == 0) + { + res = SortingIndex.CompareTo(another.SortingIndex); + if (res == 0) res = unlock.CompareTo(another.unlock); + } + return res; } private bool unlocked = false; diff --git a/RogueLibs/Properties/AssemblyInfo.cs b/RogueLibs/Properties/AssemblyInfo.cs index eb3e18be3..9677b4894 100644 --- a/RogueLibs/Properties/AssemblyInfo.cs +++ b/RogueLibs/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // Можно задать все значения или принять номера сборки и редакции по умолчанию // используя "*", как показано ниже: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.5.0")] -[assembly: AssemblyFileVersion("2.0.5.0")] +[assembly: AssemblyVersion("2.1.0.0")] +[assembly: AssemblyFileVersion("2.1.0.0")] diff --git a/RogueLibs/RogueLibs.cs b/RogueLibs/RogueLibs.cs index f1f6d5c78..f71cd6a33 100644 --- a/RogueLibs/RogueLibs.cs +++ b/RogueLibs/RogueLibs.cs @@ -22,7 +22,7 @@ public static class RogueLibs /// /// ' version. Do not use this value in your attribute! /// - public const string pluginVersion = "2.0.5"; + public const string pluginVersion = "2.1"; /// /// Main instance. diff --git a/RogueLibs/RogueLibsPlugin.cs b/RogueLibs/RogueLibsPlugin.cs index 4c3937439..18a2420e7 100644 --- a/RogueLibs/RogueLibsPlugin.cs +++ b/RogueLibs/RogueLibsPlugin.cs @@ -513,6 +513,8 @@ protected static bool ScrollingMenu_PushedButton(ScrollingMenu __instance, Butto buttonData.highlightedSprite = __instance.solidObjectButton; if (buttonData.scrollingButtonUnlock.unlockName == "SuperSpecialCharacters") __instance.gc.mainGUI.characterSelectScript.RefreshSuperSpecials(); + CustomMutator dsb = RogueLibs.GetCustomMutator(buttonData.scrollingButtonUnlock.unlockName); + dsb?.InvokeOnChangedState(false); } if (__instance.gc.multiplayerMode) __instance.agent.objectMult.SendChatAnnouncement("ClearedAllChallenges", string.Empty, string.Empty); @@ -536,15 +538,21 @@ protected static bool ScrollingMenu_PushedButton(ScrollingMenu __instance, Butto __instance.gc.originalChallenges.Remove(buttonData.scrollingButtonType); if (buttonData.scrollingButtonUnlock.unlockName == "SuperSpecialCharacters") __instance.gc.mainGUI.characterSelectScript.RefreshSuperSpecials(); + CustomMutator dsb2 = RogueLibs.GetCustomMutator(buttonData.scrollingButtonUnlock.unlockName); + dsb2?.InvokeOnChangedState(false); } __instance.gc.challenges.Add(myButton.scrollingButtonType); __instance.gc.originalChallenges.Add(myButton.scrollingButtonType); + CustomMutator dsb = RogueLibs.GetCustomMutator(myButton.scrollingButtonType); + dsb?.InvokeOnChangedState(true); } else { // was toggled off __instance.gc.challenges.Remove(myButton.scrollingButtonType); __instance.gc.originalChallenges.Remove(myButton.scrollingButtonType); + CustomMutator dsb = RogueLibs.GetCustomMutator(myButton.scrollingButtonType); + dsb?.InvokeOnChangedState(false); } custom?.InvokeOnToggledEvent(__instance, myButton, myButton.scrollingHighlighted); diff --git a/md/2.3. Custom Mutators.md b/md/2.3. Custom Mutators.md index 3b71ba93f..f3d98a6e1 100644 --- a/md/2.3. Custom Mutators.md +++ b/md/2.3. Custom Mutators.md @@ -34,8 +34,13 @@ public Func ScrollingMenu_PushedButton { get; ``` When set to anything but `null`, allows you to customize the the toggling on/off process of this specific custom mutator in the Mutator Menu. The return value determines whether the original RogueLibs patch should be executed. -`CustomMutator` also has 2 events - `OnToggledInMutatorMenu` and `OnUnlockedInMutatorMenu`: +`CustomMutator` also has these 5 events - `OnToggledInMutatorMenu`, `OnUnlockedInMutatorMenu`, `OnEnabled`, `OnDisabled`, `OnChangedState`: ```cs public event Action OnToggledInMutatorMenu; public event Action OnUnlockedInMutatorMenu; -``` \ No newline at end of file +public event Action OnEnabled; +public event Action OnDisabled; +public event Action OnChangedState; +``` + +**If you're going to enable/disable custom mutators from other mods, use method `InvokeOnChangedState` to inform other mods of their mutator's new state!** \ No newline at end of file diff --git a/md/4. Changelog.md b/md/4. Changelog.md index 18077636a..d9a734ffe 100644 --- a/md/4. Changelog.md +++ b/md/4. Changelog.md @@ -16,6 +16,9 @@ ## Changelog ## +#### RogueLibs v2.1 #### +- Added `OnEnabled`, `OnDisabled` and `OnChangedState` events to `CustomMutator`; + #### RogueLibs v2.0.5 #### - Fixed an error with aToM's category buttons;