Fix roles breaking from VanillaButtonClickEvent<T>

This commit is contained in:
Atony committed 2026-11-15 20:22:20 -06:00
1 parent e4b98acf68
commit fcf99cfb02
3 files changed
+1 -46

No files matched your search

@@ -2,20 +2,6 @@
namespace MiraAPI.Events.Vanilla.Gameplay;
/// <summary>
/// Invoked when a Vanilla <see cref="AbilityButton"/> click is cancelled. Do not use for <see cref="CustomActionButton"/>.
/// </summary>
/// <typeparam name="T">The vanilla <see cref="AbilityButton"/> type.</typeparam>
/// <param name="button">The vanilla <see cref="AbilityButton"/> whose click was cancelled.</param>
public sealed class VanillaButtonCancelledEvent<T>(T button) : MiraEvent
where T : AbilityButton
{
/// <summary>
/// Gets the Vanilla <see cref="AbilityButton"/> whose click was cancelled.
/// </summary>
public T Button => button;
}
/// <summary>
/// Invoked when a Vanilla <see cref="AbilityButton"/> click is cancelled. Do not use for <see cref="CustomActionButton"/>s.
/// </summary>
@@ -2,26 +2,6 @@
namespace MiraAPI.Events.Vanilla.Gameplay;
/// <summary>
/// Button click event for Vanilla <see cref="AbilityButton"/>s only. Do not use for <see cref="CustomActionButton"/>s.
/// </summary>
/// <typeparam name="T">The vanilla <see cref="AbilityButton"/> type.</typeparam>
/// <param name="button">The vanilla <see cref="AbilityButton"/> that was clicked.</param>
/// <param name="genericClickEvent">The generic <see cref="VanillaButtonClickEvent"/> invoked before button-specific events.</param>
public sealed class VanillaButtonClickEvent<T>(T button, VanillaButtonClickEvent genericClickEvent) : MiraCancelableEvent
where T : AbilityButton
{
/// <summary>
/// Gets the vanilla <see cref="AbilityButton"/> that was clicked.
/// </summary>
public T Button => button;
/// <summary>
/// Gets the generic <see cref="VanillaButtonClickEvent"/> that is invoked before this button-specific event.
/// </summary>
public VanillaButtonClickEvent GenericClickEvent => genericClickEvent;
}
/// <summary>
/// Button click event for Vanilla <see cref="AbilityButton"/> only. Do not use for <see cref="CustomActionButton"/>s.
/// </summary>
+1 -12
View File
@@ -72,17 +72,6 @@ public static class VanillaButtonPatches
new VanillaButtonCancelledEvent(__instance).InvokeEvent();
}
var eventType = typeof(VanillaButtonClickEvent<>).MakeGenericType(__instance.GetType());
var @event = (MiraCancelableEvent)Activator.CreateInstance(eventType, [__instance])!;
var specificInvoked = @event.InvokeEvent(eventType);
if (@event.IsCancelled)
{
var cancelEventType = typeof(VanillaButtonCancelledEvent<>).MakeGenericType(__instance.GetType());
var cancelEvent = (MiraEvent)Activator.CreateInstance(cancelEventType, [__instance])!;
cancelEvent.InvokeEvent(cancelEventType);
}
MiraCancelableEvent eventCheck = specificInvoked ? @event : genericEvent;
return !eventCheck.IsCancelled;
return !genericEvent.IsCancelled;
}
}