diff --git a/MiraAPI.Example/Buttons/ThinkButton.cs b/MiraAPI.Example/Buttons/ThinkButton.cs new file mode 100644 index 0000000..95ce73a --- /dev/null +++ b/MiraAPI.Example/Buttons/ThinkButton.cs @@ -0,0 +1,29 @@ +using MiraAPI.Hud; +using MiraAPI.Utilities.Assets; +using UnityEngine; + +namespace MiraAPI.Example.Buttons; + +public class ThinkButton : CustomActionButton +{ + public override string Name => "Think"; + public override float Cooldown => 10f; + public override float EffectDuration => 10f; + public override bool EffectCancelable => true; + public override LoadableAsset Sprite => ExampleAssets.ExampleButton; + protected override void OnClick() + { + // This button does absolutely nothing besides changing its text + Button!.OverrideText("Thinking..."); + } + + public override void OnEffectEnd() + { + Button!.OverrideText("Think"); + } + + public override bool Enabled(RoleBehaviour? role) + { + return role != null && role.IsImpostor; + } +} diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index ffaa315..78ebd4d 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -47,10 +47,20 @@ public abstract class CustomActionButton public virtual string CooldownTimerFormatString => "0"; /// - /// Gets the button's effect duration in seconds. If the button has no effect, set to 0. + /// Gets a value indicating whether the button has an effect ability. By default true if is greater than 0. + /// + public virtual bool HasEffect => EffectDuration > 0; + + /// + /// Gets the button's effect duration in seconds. If 0, the effect needs to be ended manually. /// public virtual float EffectDuration => 0; + /// + /// Gets a value indicating whether the effect can be ended early by the player. + /// + public virtual bool EffectCancelable => false; + /// /// Gets the maximum amount of uses the button has. If the button has infinite uses, set to 0. /// @@ -88,11 +98,6 @@ public abstract class CustomActionButton /// public virtual ButtonLocation Location { get; set; } = ButtonLocation.BottomLeft; - /// - /// Gets a value indicating whether the button has an effect ability. - /// - public bool HasEffect => EffectDuration > 0; - /// /// Gets a value indicating whether the button has limited uses. /// @@ -416,7 +421,7 @@ public abstract class CustomActionButton /// A value that represents whether the button can be clicked or not. public virtual bool CanClick() { - return Timer <= 0 && !EffectActive && CanUse(); + return (EffectActive ? EffectCancelable : Timer <= 0) && CanUse(); } /// @@ -426,7 +431,7 @@ public abstract class CustomActionButton /// A value that represents whether the button should light up or not. public virtual bool CanUse() { - return PlayerControl.LocalPlayer.moveable && (!LimitedUses || UsesLeft > 0); + return PlayerControl.LocalPlayer.moveable && (EffectActive || !LimitedUses || UsesLeft > 0); } /// @@ -448,6 +453,12 @@ public abstract class CustomActionButton /// public virtual void ClickHandler() { + if (EffectActive && EffectCancelable) + { + ResetCooldownAndOrEffect(); + return; + } + if (!CanClick()) { return;