More documentation + Button outline color

This commit is contained in:
wanderingpix committed 2026-08-21 12:32:43 +01:00
1 parent 54d7c84e91
commit 605c792e8f
6 files changed
+66 -10

No files matched your search

@@ -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> Sprite => ExampleAssets.SharpshootButton;
public override MeetingButtonUsesMode ButtonUsesMode => MeetingButtonUsesMode.PerGame;
public override Color OutlineColor => Color.red;
public override bool Enabled(RoleBehaviour r)
{
@@ -7,16 +7,52 @@ using UnityEngine;
namespace MiraAPI.MeetingAbilities;
/// <summary>
/// A component for handling targeted meeting buttons.
/// </summary>
[RegisterInIl2Cpp]
public class MeetingAbilityBehaviour(IntPtr cppPtr) : MonoBehaviour(cppPtr)
public class MeetingAbilityBehaviour : MonoBehaviour
{
private bool _init = false;
/// <summary>
/// Gets or sets whether the component has been initialized.
/// </summary>
private bool _init;
/// <summary>
/// The <see cref="TargetedMeetingButton"/> attached to this component.
/// </summary>
private TargetedMeetingButton _button = null!;
/// <summary>
/// The <see cref="PassiveButton"/> of this component.
/// </summary>
public PassiveButton Button;
/// <summary>
/// The parent <see cref="PlayerVoteArea"/>.
/// </summary>
public PlayerVoteArea VoteArea;
/// <summary>
/// The button's <see cref="SpriteRenderer"/> component.
/// </summary>
public SpriteRenderer Renderer;
/// <summary>
/// The <see cref="TextMeshPro"/> label used for showing the ability's cooldown.
/// </summary>
public TextMeshPro CooldownText;
/// <summary>
/// The <see cref="TextMeshPro"/> label used for showing the ability's remaining uses.
/// </summary>
public TextMeshPro UsesText;
/// <summary>
/// Initializes the various properties of this component.
/// </summary>
/// <param name="button">The <see cref="TargetedMeetingButton"/> to initialize this component for.</param>
/// <param name="voteArea">The parent <see cref="PlayerVoteArea"/>.</param>
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)
@@ -8,6 +8,9 @@ using UnityEngine;
namespace MiraAPI.MeetingAbilities;
/// <summary>
/// Class for managing all registered meeting abilities.
/// </summary>
public static class TargetedMeetingAbilityManager
{
/// <summary>
@@ -57,6 +57,11 @@ public abstract class TargetedMeetingButton
/// </summary>
public abstract LoadableAsset<Sprite> Sprite { get; }
/// <summary>
/// Gets the button's outline color.
/// </summary>
public abstract Color OutlineColor { get; }
/// <summary>
/// Gets the <see cref="MeetingButtonUsesMode"/> for this button.
/// </summary>
@@ -93,11 +98,14 @@ public abstract class TargetedMeetingButton
spriteRenderer.SetCooldownNormalizedUvs();
btn.gameObject.SetActive(true);
btn.transform.GetChild(0).GetComponent<SpriteRenderer>().color = OutlineColor;
btn.OnClick = new Button.ButtonClickedEvent();
btn.OnClick.AddListener(new System.Action(() => ClickHandler(playerVoteArea)));
var abilityBehaviour = btn.gameObject.AddComponent<MeetingAbilityBehaviour>();
abilityBehaviour.Initialize(this, playerVoteArea);
Timer = InitialCooldown;
return abilityBehaviour;
}
@@ -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));
}
}
+1 -1
View File
@@ -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();
}