Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmical committed Sep 6, 2020
1 parent 83ae96a commit ea35366
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
23 changes: 23 additions & 0 deletions RogueLibs/CustomMutator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,31 @@ public override bool Available
/// </summary>
public event Action<ScrollingMenu, ButtonHelper> OnUnlockedInMutatorMenu;

/// <summary>
/// <para>Event that is invoked when this mutator is toggled on, in the Mutator menu or by cancellations.</para>
/// </summary>
public event Action OnEnabled;
/// <summary>
/// <para>Event that is invoked when this mutator is toggled off, in the Mutator menu or by cancellations.</para>
/// </summary>
public event Action OnDisabled;
/// <summary>
/// <para>Event that is invoked when this mutator is toggled on/off, in the Mutator menu or by cancellations.</para>
/// <para><see cref="bool"/> obj is the new mutator's state.</para>
/// </summary>
public event Action<bool> 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);

/// <summary>
/// <para>Invoke this method when you enable/disable custom mutators from other mods!</para>
/// </summary>
public void InvokeOnChangedState(bool newState)
{
(newState ? OnEnabled : OnDisabled)?.Invoke();
OnChangedState?.Invoke(newState);
}

}
}
7 changes: 6 additions & 1 deletion RogueLibs/CustomUnlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions RogueLibs/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion RogueLibs/RogueLibs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class RogueLibs
/// <summary>
/// <para><see cref="RogueLibs"/>' version. Do not use this value in your <see cref="BepInDependency"/> attribute!</para>
/// </summary>
public const string pluginVersion = "2.0.5";
public const string pluginVersion = "2.1";

/// <summary>
/// <para>Main <see cref="RogueLibsPlugin"/> instance.</para>
Expand Down
8 changes: 8 additions & 0 deletions RogueLibs/RogueLibsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
9 changes: 7 additions & 2 deletions md/2.3. Custom Mutators.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ public Func<ScrollingMenu, ButtonHelper, bool> 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<ScrollingMenu, ButtonHelper, bool> OnToggledInMutatorMenu;
public event Action<ScrollingMenu, ButtonHelper> OnUnlockedInMutatorMenu;
```
public event Action OnEnabled;
public event Action OnDisabled;
public event Action<bool> 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!**
3 changes: 3 additions & 0 deletions md/4. Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ea35366

Please sign in to comment.