From 605c792e8fc11ae6815f16850dd9674198e2afab Mon Sep 17 00:00:00 2001 From: wanderingpix Date: Fri, 21 Aug 2026 12:32:43 +0100 Subject: [PATCH] More documentation + Button outline color --- .../MeetingAbilities/ShootButton.cs | 10 ++--- .../MeetingAbilityBehaviour.cs | 45 +++++++++++++++++-- .../TargetedMeetingAbilityManager.cs | 3 ++ .../MeetingAbilities/TargetedMeetingButton.cs | 8 ++++ .../Patches/Events/FreeplayRoundStartPatch.cs | 8 +++- MiraAPI/Patches/Voting/MeetingHudPatches.cs | 2 +- 6 files changed, 66 insertions(+), 10 deletions(-) diff --git a/MiraAPI.Example/MeetingAbilities/ShootButton.cs b/MiraAPI.Example/MeetingAbilities/ShootButton.cs index 628f50c..ad5f336 100644 --- a/MiraAPI.Example/MeetingAbilities/ShootButton.cs +++ b/MiraAPI.Example/MeetingAbilities/ShootButton.cs @@ -8,17 +8,17 @@ namespace MiraAPI.Example.MeetingAbilities; public class ShootButton : TargetedMeetingButton { - public override string Name => "Shooooooot"; + public override string Name => "Shoot"; - public override int MaxUses => 0; + public override int MaxUses => 3; - public override float InitialCooldown => 99; + public override float InitialCooldown => 5; - public override float Cooldown => 10; + public override float Cooldown => 3; public override LoadableAsset Sprite => ExampleAssets.SharpshootButton; - public override MeetingButtonUsesMode ButtonUsesMode => MeetingButtonUsesMode.PerGame; + public override Color OutlineColor => Color.red; public override bool Enabled(RoleBehaviour r) { diff --git a/MiraAPI/MeetingAbilities/MeetingAbilityBehaviour.cs b/MiraAPI/MeetingAbilities/MeetingAbilityBehaviour.cs index 9d7160c..e390b8d 100644 --- a/MiraAPI/MeetingAbilities/MeetingAbilityBehaviour.cs +++ b/MiraAPI/MeetingAbilities/MeetingAbilityBehaviour.cs @@ -7,16 +7,52 @@ using UnityEngine; namespace MiraAPI.MeetingAbilities; +/// +/// A component for handling targeted meeting buttons. +/// [RegisterInIl2Cpp] -public class MeetingAbilityBehaviour(IntPtr cppPtr) : MonoBehaviour(cppPtr) +public class MeetingAbilityBehaviour : MonoBehaviour { - private bool _init = false; + /// + /// Gets or sets whether the component has been initialized. + /// + private bool _init; + + /// + /// The attached to this component. + /// private TargetedMeetingButton _button = null!; + + /// + /// The of this component. + /// public PassiveButton Button; + + /// + /// The parent . + /// public PlayerVoteArea VoteArea; + + /// + /// The button's component. + /// public SpriteRenderer Renderer; + + /// + /// The label used for showing the ability's cooldown. + /// public TextMeshPro CooldownText; + + /// + /// The label used for showing the ability's remaining uses. + /// public TextMeshPro UsesText; + + /// + /// Initializes the various properties of this component. + /// + /// The to initialize this component for. + /// The parent . public void Initialize(TargetedMeetingButton button, PlayerVoteArea voteArea) { if (_init) return; @@ -38,6 +74,9 @@ public class MeetingAbilityBehaviour(IntPtr cppPtr) : MonoBehaviour(cppPtr) UsesText = Instantiate(CooldownText, transform); UsesText.transform.localPosition = new Vector3(0.25f, 0.25f, -10); UsesText.transform.localScale = Vector3.one * 0.7f; + + CooldownText.gameObject.SetActive(true); + UsesText.gameObject.SetActive(true); } private void OnEnable() @@ -50,7 +89,7 @@ public class MeetingAbilityBehaviour(IntPtr cppPtr) : MonoBehaviour(cppPtr) Renderer.enabled = false; } - public void Update() + private void Update() { if (!_init) return; if (_button.Timer < 0.01f) diff --git a/MiraAPI/MeetingAbilities/TargetedMeetingAbilityManager.cs b/MiraAPI/MeetingAbilities/TargetedMeetingAbilityManager.cs index fa40a46..a07f632 100644 --- a/MiraAPI/MeetingAbilities/TargetedMeetingAbilityManager.cs +++ b/MiraAPI/MeetingAbilities/TargetedMeetingAbilityManager.cs @@ -8,6 +8,9 @@ using UnityEngine; namespace MiraAPI.MeetingAbilities; +/// +/// Class for managing all registered meeting abilities. +/// public static class TargetedMeetingAbilityManager { /// diff --git a/MiraAPI/MeetingAbilities/TargetedMeetingButton.cs b/MiraAPI/MeetingAbilities/TargetedMeetingButton.cs index a6b448f..606eeff 100644 --- a/MiraAPI/MeetingAbilities/TargetedMeetingButton.cs +++ b/MiraAPI/MeetingAbilities/TargetedMeetingButton.cs @@ -57,6 +57,11 @@ public abstract class TargetedMeetingButton /// public abstract LoadableAsset Sprite { get; } + /// + /// Gets the button's outline color. + /// + public abstract Color OutlineColor { get; } + /// /// Gets the for this button. /// @@ -93,11 +98,14 @@ public abstract class TargetedMeetingButton spriteRenderer.SetCooldownNormalizedUvs(); btn.gameObject.SetActive(true); + btn.transform.GetChild(0).GetComponent().color = OutlineColor; + btn.OnClick = new Button.ButtonClickedEvent(); btn.OnClick.AddListener(new System.Action(() => ClickHandler(playerVoteArea))); var abilityBehaviour = btn.gameObject.AddComponent(); abilityBehaviour.Initialize(this, playerVoteArea); Timer = InitialCooldown; + return abilityBehaviour; } diff --git a/MiraAPI/Patches/Events/FreeplayRoundStartPatch.cs b/MiraAPI/Patches/Events/FreeplayRoundStartPatch.cs index 3bda24d..f81332b 100644 --- a/MiraAPI/Patches/Events/FreeplayRoundStartPatch.cs +++ b/MiraAPI/Patches/Events/FreeplayRoundStartPatch.cs @@ -1,7 +1,9 @@ -using System.Reflection; +using System.Linq; +using System.Reflection; using HarmonyLib; using MiraAPI.Events; using MiraAPI.Events.Vanilla.Gameplay; +using MiraAPI.MeetingAbilities; using MiraAPI.Utilities; namespace MiraAPI.Patches.Events; @@ -18,6 +20,10 @@ public static class FreeplayRoundStartPatch { if (!__result) { + foreach (var ability in TargetedMeetingAbilityManager.Buttons.Where(x => x.ButtonUsesMode == MeetingButtonUsesMode.PerGame)) + { + ability.UsesRemaining = ability.MaxUses; + } MiraEventManager.InvokeEvent(new RoundStartEvent(true)); } } diff --git a/MiraAPI/Patches/Voting/MeetingHudPatches.cs b/MiraAPI/Patches/Voting/MeetingHudPatches.cs index b0e084a..64764e8 100644 --- a/MiraAPI/Patches/Voting/MeetingHudPatches.cs +++ b/MiraAPI/Patches/Voting/MeetingHudPatches.cs @@ -133,7 +133,7 @@ internal static class MeetingHudPatches [HarmonyPatch(nameof(MeetingHud.Update))] public static void ForceSkipPatch(MeetingHud __instance) { - foreach (var targetedMeetingAbility in TargetedMeetingAbilityManager.Buttons) + foreach (var targetedMeetingAbility in TargetedMeetingAbilityManager.Buttons.Where(x => x.Enabled(PlayerControl.LocalPlayer.Data.Role))) { targetedMeetingAbility.UpdateHandler(); }