diff --git a/MiraAPI.Example/Buttons/ExampleButton.cs b/MiraAPI.Example/Buttons/ExampleButton.cs index 336896e..3a06661 100644 --- a/MiraAPI.Example/Buttons/ExampleButton.cs +++ b/MiraAPI.Example/Buttons/ExampleButton.cs @@ -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 { get; } = ExampleAssets.ExampleButton; - + public override LoadableAsset Sprite => ExampleAssets.ExampleButton; + public override ButtonLocation Location => ButtonLocation.BottomRight; + protected override void OnClick() { Logger.Info("Example button clicked!"); diff --git a/MiraAPI/Hud/ButtonLocation.cs b/MiraAPI/Hud/ButtonLocation.cs new file mode 100644 index 0000000..e08c9d2 --- /dev/null +++ b/MiraAPI/Hud/ButtonLocation.cs @@ -0,0 +1,7 @@ +namespace MiraAPI.Hud; + +public enum ButtonLocation +{ + BottomLeft, + BottomRight +} \ No newline at end of file diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index c2bf906..bdb4e5b 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -36,6 +36,11 @@ public abstract class CustomActionButton /// public abstract LoadableAsset Sprite { get; } + /// + /// The location of the button on the screen + /// + public virtual ButtonLocation Location => ButtonLocation.BottomLeft; + /// /// Returns true if the button has an effect ability. /// diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 7631523..b30a0ca 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -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(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();