From 664f8cb2e85e51360c5221474de11878186d63e0 Mon Sep 17 00:00:00 2001 From: ang-xd Date: Sat, 1 Mar 2025 15:31:48 -0500 Subject: [PATCH] Add PopulateResultsEvent.cs --- MiraAPI.Example/ExampleEventHandlers.cs | 2 ++ .../Meeting/Voting/PopulateResultsEvent.cs | 25 +++++++++++++++++++ MiraAPI/Voting/VotingUtils.cs | 8 ++++++ 3 files changed, 35 insertions(+) create mode 100644 MiraAPI/Events/Vanilla/Meeting/Voting/PopulateResultsEvent.cs diff --git a/MiraAPI.Example/ExampleEventHandlers.cs b/MiraAPI.Example/ExampleEventHandlers.cs index 91d7899..618ea2f 100644 --- a/MiraAPI.Example/ExampleEventHandlers.cs +++ b/MiraAPI.Example/ExampleEventHandlers.cs @@ -35,6 +35,7 @@ public static class ExampleEventHandlers }); } + // If you want to add extra votes to a player, do something like this. [RegisterEvent] public static void StartMeetingEvent(StartMeetingEvent _) { @@ -47,6 +48,7 @@ public static class ExampleEventHandlers } } + // Example of using the Voting API to make a role similar to the Prosecutor from Town of Us. [RegisterEvent(15)] public static void HandleVoteEvent(HandleVoteEvent @event) { diff --git a/MiraAPI/Events/Vanilla/Meeting/Voting/PopulateResultsEvent.cs b/MiraAPI/Events/Vanilla/Meeting/Voting/PopulateResultsEvent.cs new file mode 100644 index 0000000..131b6d5 --- /dev/null +++ b/MiraAPI/Events/Vanilla/Meeting/Voting/PopulateResultsEvent.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using MiraAPI.Voting; + +namespace MiraAPI.Events.Vanilla.Meeting.Voting; + +/// +/// Called in VotingUtils.HandlePopulateResults. +/// Cancelling is NOT advised but if you do plan on cancelling, please ensure you account for displaying ALL player's votes. +/// +public class PopulateResultsEvent : MiraCancelableEvent +{ + /// + /// Gets a list of networked votes. + /// + public List Votes { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The list of votes. + public PopulateResultsEvent(List votes) + { + Votes = votes; + } +} diff --git a/MiraAPI/Voting/VotingUtils.cs b/MiraAPI/Voting/VotingUtils.cs index d850226..d10aeac 100644 --- a/MiraAPI/Voting/VotingUtils.cs +++ b/MiraAPI/Voting/VotingUtils.cs @@ -111,6 +111,14 @@ public static class VotingUtils /// The list of networked votes. public static void HandlePopulateResults(List votes) { + PopulateResultsEvent @event = new PopulateResultsEvent(votes); + MiraEventManager.InvokeEvent(@event); + + if (@event.IsCancelled) + { + return; + } + MeetingHud.Instance.TitleText.text = DestroyableSingleton.Instance.GetString( StringNames.MeetingVotingResults,