From 786450c7c18e0a3af34bb26423f972d0c7e45f1c Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Fri, 27 Dec 2024 18:48:43 -0500 Subject: [PATCH] fix SetUses bug in buttons and make effect and use limit optional --- MiraAPI.Example/Buttons/Freezer/FreezeButton.cs | 4 +++- MiraAPI.Example/Buttons/MeetingButton.cs | 2 -- .../Buttons/Teleporter/TeleportButton.cs | 5 +++-- MiraAPI/Hud/CustomActionButton.cs | 14 +++++++------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/MiraAPI.Example/Buttons/Freezer/FreezeButton.cs b/MiraAPI.Example/Buttons/Freezer/FreezeButton.cs index d357932..8db98c7 100644 --- a/MiraAPI.Example/Buttons/Freezer/FreezeButton.cs +++ b/MiraAPI.Example/Buttons/Freezer/FreezeButton.cs @@ -13,9 +13,11 @@ namespace MiraAPI.Example.Buttons.Freezer; public class FreezeButton : CustomActionButton { public override string Name => "Freeze"; + public override float Cooldown => OptionGroupSingleton.Instance.FreezeDuration; - public override float EffectDuration => 0f; + public override int MaxUses => (int)OptionGroupSingleton.Instance.FreezeUses; + public override LoadableAsset Sprite => ExampleAssets.ExampleButton; protected override void OnClick() diff --git a/MiraAPI.Example/Buttons/MeetingButton.cs b/MiraAPI.Example/Buttons/MeetingButton.cs index a5de0e9..85b8ff1 100644 --- a/MiraAPI.Example/Buttons/MeetingButton.cs +++ b/MiraAPI.Example/Buttons/MeetingButton.cs @@ -13,8 +13,6 @@ public class MeetingButton : CustomActionButton public override float Cooldown => 15; - public override float EffectDuration => 0; - public override int MaxUses => 3; public override LoadableAsset Sprite => ExampleAssets.ExampleButton; diff --git a/MiraAPI.Example/Buttons/Teleporter/TeleportButton.cs b/MiraAPI.Example/Buttons/Teleporter/TeleportButton.cs index 3a8d810..564b738 100644 --- a/MiraAPI.Example/Buttons/Teleporter/TeleportButton.cs +++ b/MiraAPI.Example/Buttons/Teleporter/TeleportButton.cs @@ -8,6 +8,7 @@ using UnityEngine; namespace MiraAPI.Example.Buttons.Teleporter; + [RegisterButton] public class TeleportButton : CustomActionButton { @@ -17,15 +18,15 @@ public class TeleportButton : CustomActionButton public override float EffectDuration => OptionGroupSingleton.Instance.TeleportDuration; - public override int MaxUses => 0; - public override LoadableAsset Sprite => ExampleAssets.TeleportButton; + public static bool IsZoom { get; private set; } public override bool Enabled(RoleBehaviour? role) { return role is TeleporterRole; } + protected override void OnClick() { Coroutines.Start(ZoomOutCoroutine()); diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index 1c22152..640417a 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -25,19 +25,19 @@ public abstract class CustomActionButton public abstract float Cooldown { get; } /// - /// Gets the button's effect duration in seconds. If the button has no effect, set to 0. + /// Gets the sprite of the button. Use to load a sprite from a resource path. Use to load a sprite from an asset bundle. /// - public abstract float EffectDuration { get; } + public abstract LoadableAsset Sprite { get; } /// - /// Gets the maximum amount of uses the button has. If the button has infinite uses, set to 0. + /// Gets the button's effect duration in seconds. If the button has no effect, set to 0. /// - public abstract int MaxUses { get; } + public virtual float EffectDuration => 0; /// - /// Gets the sprite of the button. Use to load a sprite from a resource path. Use to load a sprite from an asset bundle. + /// Gets the maximum amount of uses the button has. If the button has infinite uses, set to 0. /// - public abstract LoadableAsset Sprite { get; } + public virtual int MaxUses => 0; /// /// Gets the location of the button on the screen. @@ -206,7 +206,7 @@ public void DecreaseTimer(float amount) public void SetUses(int amount) { UsesLeft = Mathf.Clamp(amount, 0, int.MaxValue); - Button?.SetUsesRemaining(MaxUses); + Button?.SetUsesRemaining(UsesLeft); } ///