Skip to content

Commit

Permalink
fix SetUses bug in buttons and make effect and use limit optional
Browse files Browse the repository at this point in the history
  • Loading branch information
XtraCube committed Dec 27, 2024
1 parent 82050b9 commit 786450c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 3 additions & 1 deletion MiraAPI.Example/Buttons/Freezer/FreezeButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ namespace MiraAPI.Example.Buttons.Freezer;
public class FreezeButton : CustomActionButton<PlayerControl>
{
public override string Name => "Freeze";

public override float Cooldown => OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeDuration;
public override float EffectDuration => 0f;

public override int MaxUses => (int)OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeUses;

public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;

protected override void OnClick()
Expand Down
2 changes: 0 additions & 2 deletions MiraAPI.Example/Buttons/MeetingButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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> Sprite => ExampleAssets.ExampleButton;
Expand Down
5 changes: 3 additions & 2 deletions MiraAPI.Example/Buttons/Teleporter/TeleportButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using UnityEngine;

namespace MiraAPI.Example.Buttons.Teleporter;

[RegisterButton]
public class TeleportButton : CustomActionButton
{
Expand All @@ -17,15 +18,15 @@ public class TeleportButton : CustomActionButton

public override float EffectDuration => OptionGroupSingleton<TeleporterOptions>.Instance.TeleportDuration;

public override int MaxUses => 0;

public override LoadableAsset<Sprite> 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());
Expand Down
14 changes: 7 additions & 7 deletions MiraAPI/Hud/CustomActionButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ public abstract class CustomActionButton
public abstract float Cooldown { get; }

/// <summary>
/// Gets the button's effect duration in seconds. If the button has no effect, set to 0.
/// Gets the sprite of the button. Use <see cref="LoadableResourceAsset"/> to load a sprite from a resource path. Use <see cref="LoadableBundleAsset{T}"/> to load a sprite from an asset bundle.
/// </summary>
public abstract float EffectDuration { get; }
public abstract LoadableAsset<Sprite> Sprite { get; }

/// <summary>
/// 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.
/// </summary>
public abstract int MaxUses { get; }
public virtual float EffectDuration => 0;

/// <summary>
/// Gets the sprite of the button. Use <see cref="LoadableResourceAsset"/> to load a sprite from a resource path. Use <see cref="LoadableBundleAsset{T}"/> 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.
/// </summary>
public abstract LoadableAsset<Sprite> Sprite { get; }
public virtual int MaxUses => 0;

/// <summary>
/// Gets the location of the button on the screen.
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down

0 comments on commit 786450c

Please sign in to comment.