add button location property

This commit is contained in:
XtraCube committed 2024-08-26 11:17:53 -04:00
1 parent 55b7174be2
commit c77664936f
4 files changed
+30 -6

No files matched your search

+3 -2
View File
@@ -12,8 +12,9 @@ public class ExampleButton : CustomActionButton
public override float Cooldown => 5f;
public override float EffectDuration => 0f;
public override int MaxUses => 5;
public override LoadableAsset<Sprite> Sprite { get; } = ExampleAssets.ExampleButton;
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
public override ButtonLocation Location => ButtonLocation.BottomRight;
protected override void OnClick()
{
Logger<ExamplePlugin>.Info("Example button clicked!");
+7
View File
@@ -0,0 +1,7 @@
namespace MiraAPI.Hud;
public enum ButtonLocation
{
BottomLeft,
BottomRight
}
+5
View File
@@ -36,6 +36,11 @@ public abstract class CustomActionButton
/// </summary>
public abstract LoadableAsset<Sprite> Sprite { get; }
/// <summary>
/// The location of the button on the screen
/// </summary>
public virtual ButtonLocation Location => ButtonLocation.BottomLeft;
/// <summary>
/// Returns true if the button has an effect ability.
/// </summary>
+15 -4
View File
@@ -1,9 +1,11 @@
using HarmonyLib;
using System;
using HarmonyLib;
using InnerNet;
using MiraAPI.Hud;
using MiraAPI.Roles;
using Reactor.Utilities.Extensions;
using UnityEngine;
using Object = UnityEngine.Object;
namespace MiraAPI.Patches;
@@ -78,10 +80,12 @@ public static class HudManagerPatches
[HarmonyPatch(nameof(HudManager.Start))]
public static void StartPostfix(HudManager __instance)
{
var buttons = __instance.transform.Find("Buttons");
var bottomRight = buttons.Find("BottomRight");
if (!_bottomLeft)
{
var buttons = __instance.transform.Find("Buttons");
_bottomLeft = Object.Instantiate(buttons.Find("BottomRight").gameObject, buttons);
_bottomLeft = Object.Instantiate(bottomRight.gameObject, buttons);
}
foreach (var t in _bottomLeft.GetComponentsInChildren<ActionButton>(true))
@@ -98,7 +102,14 @@ public static class HudManagerPatches
foreach (var button in CustomButtonManager.CustomButtons)
{
button.CreateButton(_bottomLeft.transform);
Transform location = button.Location switch
{
ButtonLocation.BottomLeft => _bottomLeft.transform,
ButtonLocation.BottomRight => bottomRight,
_ => throw new ArgumentOutOfRangeException()
};
button.CreateButton(location);
}
gridArrange.Start();