cancelable abilities

This commit is contained in:
xChipseq committed 2025-08-29 13:38:35 +02:00
1 parent 2237d3a2df
commit 5f67960b28
2 files changed
+48 -8

No files matched your search

+29
View File
@@ -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> 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;
}
}
+19 -8
View File
@@ -47,10 +47,20 @@ public abstract class CustomActionButton
public virtual string CooldownTimerFormatString => "0";
/// <summary>
/// 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 <see cref="EffectDuration"/> is greater than 0.
/// </summary>
public virtual bool HasEffect => EffectDuration > 0;
/// <summary>
/// Gets the button's effect duration in seconds. If 0, the effect needs to be ended manually.
/// </summary>
public virtual float EffectDuration => 0;
/// <summary>
/// Gets a value indicating whether the effect can be ended early by the player.
/// </summary>
public virtual bool EffectCancelable => false;
/// <summary>
/// Gets the maximum amount of uses the button has. If the button has infinite uses, set to 0.
/// </summary>
@@ -88,11 +98,6 @@ public abstract class CustomActionButton
/// </summary>
public virtual ButtonLocation Location { get; set; } = ButtonLocation.BottomLeft;
/// <summary>
/// Gets a value indicating whether the button has an effect ability.
/// </summary>
public bool HasEffect => EffectDuration > 0;
/// <summary>
/// Gets a value indicating whether the button has limited uses.
/// </summary>
@@ -416,7 +421,7 @@ public abstract class CustomActionButton
/// <returns>A value that represents whether the button can be clicked or not.</returns>
public virtual bool CanClick()
{
return Timer <= 0 && !EffectActive && CanUse();
return (EffectActive ? EffectCancelable : Timer <= 0) && CanUse();
}
/// <summary>
@@ -426,7 +431,7 @@ public abstract class CustomActionButton
/// <returns>A value that represents whether the button should light up or not.</returns>
public virtual bool CanUse()
{
return PlayerControl.LocalPlayer.moveable && (!LimitedUses || UsesLeft > 0);
return PlayerControl.LocalPlayer.moveable && (EffectActive || !LimitedUses || UsesLeft > 0);
}
/// <summary>
@@ -448,6 +453,12 @@ public abstract class CustomActionButton
/// </summary>
public virtual void ClickHandler()
{
if (EffectActive && EffectCancelable)
{
ResetCooldownAndOrEffect();
return;
}
if (!CanClick())
{
return;