mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Merge pull request #62 from All-Of-Us-Mods/vote-event-tweaks
Add Before and After Vote Events
This commit is contained in:
3 files changed
+78
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
using MiraAPI.Voting;
|
||||||
|
|
||||||
|
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that is invoked after the local player successfully votes a player or skips. This event is not cancelable.
|
||||||
|
/// </summary>
|
||||||
|
public class AfterVoteEvent : MiraEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the instance of the voter's vote data.
|
||||||
|
/// </summary>
|
||||||
|
public PlayerVoteArea VoteArea { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the player who voted.
|
||||||
|
/// </summary>
|
||||||
|
public PlayerControl Player { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="AfterVoteEvent"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerVoteArea">The player vote area that was voted on.</param>
|
||||||
|
/// <param name="voter">The player who voted.</param>
|
||||||
|
public AfterVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter)
|
||||||
|
{
|
||||||
|
VoteArea = playerVoteArea;
|
||||||
|
Player = voter;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using MiraAPI.Voting;
|
||||||
|
|
||||||
|
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that is invoked before the local player confirms a vote on a player or when skipping. This event is cancelable.
|
||||||
|
/// </summary>
|
||||||
|
public class BeforeVoteEvent : MiraCancelableEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the instance of the voter's vote data.
|
||||||
|
/// </summary>
|
||||||
|
public PlayerVoteArea VoteArea { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the player who voted.
|
||||||
|
/// </summary>
|
||||||
|
public PlayerControl Player { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="BeforeVoteEvent"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playerVoteArea">The player vote area that was voted on.</param>
|
||||||
|
/// <param name="voter">The player who voted.</param>
|
||||||
|
public BeforeVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter)
|
||||||
|
{
|
||||||
|
VoteArea = playerVoteArea;
|
||||||
|
Player = voter;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,24 @@ namespace MiraAPI.Patches.Voting;
|
|||||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony Convention")]
|
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony Convention")]
|
||||||
internal static class MeetingHudPatches
|
internal static class MeetingHudPatches
|
||||||
{
|
{
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(PlayerVoteArea), nameof(PlayerVoteArea.VoteForMe))]
|
||||||
|
public static bool VotePatch(PlayerVoteArea __instance)
|
||||||
|
{
|
||||||
|
var beforeVoteEvent = new BeforeVoteEvent(__instance, PlayerControl.LocalPlayer);
|
||||||
|
MiraEventManager.InvokeEvent(beforeVoteEvent);
|
||||||
|
|
||||||
|
if (beforeVoteEvent.IsCancelled)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterVoteEvent = new AfterVoteEvent(__instance, PlayerControl.LocalPlayer);
|
||||||
|
MiraEventManager.InvokeEvent(afterVoteEvent);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(MeetingHud.Start))]
|
[HarmonyPatch(nameof(MeetingHud.Start))]
|
||||||
public static void MeetingHudStartPatch(MeetingHud __instance)
|
public static void MeetingHudStartPatch(MeetingHud __instance)
|
||||||
|
|||||||
Reference in new issue
Block a user