From 81c6bac979e6fa7fd1f01d782c7bfed146e6565d Mon Sep 17 00:00:00 2001 From: Atony <75191600+AtonyGit@users.noreply.github.com> Date: Wed, 2 Sep 2026 15:16:32 -0500 Subject: [PATCH] Add UiButtonResetEvent for better ui button grid --- MiraAPI/Events/Mira/UiButtonPostResetEvent.cs | 30 ++++++++ MiraAPI/Events/Mira/UiButtonResetEvent.cs | 15 ++++ MiraAPI/Hud/MiraHudHelper.cs | 2 +- MiraAPI/MiraApiPlugin.cs | 1 + MiraAPI/MiraApiSettings.cs | 48 ++----------- MiraAPI/VanillaEvents/UiResetEvents.cs | 71 +++++++++++++++++++ 6 files changed, 125 insertions(+), 42 deletions(-) create mode 100644 MiraAPI/Events/Mira/UiButtonPostResetEvent.cs create mode 100644 MiraAPI/Events/Mira/UiButtonResetEvent.cs create mode 100644 MiraAPI/VanillaEvents/UiResetEvents.cs diff --git a/MiraAPI/Events/Mira/UiButtonPostResetEvent.cs b/MiraAPI/Events/Mira/UiButtonPostResetEvent.cs new file mode 100644 index 0000000..e7221ae --- /dev/null +++ b/MiraAPI/Events/Mira/UiButtonPostResetEvent.cs @@ -0,0 +1,30 @@ +using UnityEngine; + +namespace MiraAPI.Events.Mira; + +/// +/// Event fired by Mira API to adjust the UI buttons at the top right of the screen. +/// +public class UiButtonPostResetEvent : MiraEvent +{ + /// + /// Gets the parent for the very top UI row. + /// + public GameObject MainTopUiRow { get; } + + /// + /// Gets the parent for the second top UI row. + /// + public GameObject SecondTopUiRow { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The for the top UI row. + /// The for the second UI row. + public UiButtonPostResetEvent(GameObject topUiRow, GameObject secondUiRow) + { + MainTopUiRow = topUiRow; + SecondTopUiRow = secondUiRow; + } +} diff --git a/MiraAPI/Events/Mira/UiButtonResetEvent.cs b/MiraAPI/Events/Mira/UiButtonResetEvent.cs new file mode 100644 index 0000000..2ad8698 --- /dev/null +++ b/MiraAPI/Events/Mira/UiButtonResetEvent.cs @@ -0,0 +1,15 @@ +namespace MiraAPI.Events.Mira; + +/// +/// Event fired by Mira API prior to adjusting the UI buttons at the top right of the screen. +/// +public class UiButtonResetEvent : MiraEvent +{ + /// + /// Initializes a new instance of the class. + /// + public UiButtonResetEvent() + { + // nothing! + } +} diff --git a/MiraAPI/Hud/MiraHudHelper.cs b/MiraAPI/Hud/MiraHudHelper.cs index 59a8857..b072dc8 100644 --- a/MiraAPI/Hud/MiraHudHelper.cs +++ b/MiraAPI/Hud/MiraHudHelper.cs @@ -186,7 +186,7 @@ public sealed class MiraHudHelper(nint cppPtr) : MonoBehaviour(cppPtr) { ExtraUiTopRight = new GameObject("ExtraUiTopRight") { - layer = UiTopRight.layer + layer = UiTopRight.layer, }; ExtraUiTopRight.transform.SetParent(instance.MapButton.transform.parent.parent, false); diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index ef9b2b9..0ea0b20 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -70,6 +70,7 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin public override void Load() { Harmony.PatchAll(); + UiResetEvents.Initialize(); JudgeEvents.Initialize(); ReactorCredits.Register("Mira API", Version, IsDevBuild, ReactorCredits.AlwaysShow); diff --git a/MiraAPI/MiraApiSettings.cs b/MiraAPI/MiraApiSettings.cs index 9999f15..3d74768 100644 --- a/MiraAPI/MiraApiSettings.cs +++ b/MiraAPI/MiraApiSettings.cs @@ -1,5 +1,7 @@ using System.Collections; using BepInEx.Configuration; +using MiraAPI.Events; +using MiraAPI.Events.Mira; using MiraAPI.Hud; using MiraAPI.LocalSettings; using MiraAPI.LocalSettings.Attributes; @@ -80,54 +82,18 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config) { var topUi = MiraHudHelper.UiTopRight; var extraTopUi = MiraHudHelper.ExtraUiTopRight; - var wikiButton = MiraHudHelper.VanillaMatchInfoButton; - var subButton = MiraHudHelper.SubmergedFloorButton; - var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!; - ResetButtonPositions(); if (topUi && extraTopUi) { - var opts = LocalSettingsTabSingleton.Instance; - if (wikiButton) - { - wikiButton.transform.SetParent(opts.WikiOnBottomRow.Value ? extraTopUi.transform : topUi.transform); - } - if (subButton) - { - subButton.transform.SetParent(extraTopUi.transform); - } - if (modDisplay) - { - modDisplay.transform.SetParent(extraTopUi.transform); - } + var genericEvent = new UiButtonResetEvent(); + MiraEventManager.InvokeEvent(genericEvent); + + var genericEvent2 = new UiButtonPostResetEvent(topUi, extraTopUi); + MiraEventManager.InvokeEvent(genericEvent2); MiraHudHelper.UiGrid.ArrangeChilds(); MiraHudHelper.ExtraUiGrid.ArrangeChilds(); } } - public static void ResetButtonPositions() - { - var topUi = MiraHudHelper.UiTopRight; - var extraTopUi = MiraHudHelper.ExtraUiTopRight; - var subButton = MiraHudHelper.SubmergedFloorButton; - var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!; - if (topUi && extraTopUi) - { - var wikiButton = MiraHudHelper.VanillaMatchInfoButton; - if (wikiButton) - { - wikiButton.transform.SetParent(null); - } - if (subButton) - { - subButton.transform.SetParent(null); - } - if (modDisplay) - { - modDisplay.transform.SetParent(null); - } - } - } - public static IEnumerator CoResizeSettingsUI() { while (!HudManager.Instance || !MiraHudHelper.UiGrid || !MiraHudHelper.ExtraUiGrid) diff --git a/MiraAPI/VanillaEvents/UiResetEvents.cs b/MiraAPI/VanillaEvents/UiResetEvents.cs new file mode 100644 index 0000000..fe0e6e5 --- /dev/null +++ b/MiraAPI/VanillaEvents/UiResetEvents.cs @@ -0,0 +1,71 @@ +using MiraAPI.Events; +using MiraAPI.Events.Mira; +using MiraAPI.Hud; +using MiraAPI.LocalSettings; + +namespace MiraAPI.VanillaEvents; + +public static class UiResetEvents +{ + public static void Initialize() + { + MiraEventManager.RegisterEventHandler(@event => ResetButtonParents(@event)); + MiraEventManager.RegisterEventHandler(@event => PlaceWikiButton(@event), -900); + MiraEventManager.RegisterEventHandler(@event => PlaceSubmergedButton(@event), -800); + MiraEventManager.RegisterEventHandler(@event => PlaceModifierUi(@event), -700); + } + + public static void ResetButtonParents(UiButtonResetEvent @event) + { + var wikiButton = MiraHudHelper.VanillaMatchInfoButton; + var subButton = MiraHudHelper.SubmergedFloorButton; + var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!; + if (wikiButton) + { + wikiButton.transform.SetParent(null); + } + if (subButton) + { + subButton.transform.SetParent(null); + } + if (modDisplay) + { + modDisplay.transform.SetParent(null); + } + } + + public static void PlaceWikiButton(UiButtonPostResetEvent @event) + { + var wikiButton = MiraHudHelper.VanillaMatchInfoButton; + if (!wikiButton) + { + return; + } + var firstRow = @event.MainTopUiRow; + var secondRow = @event.SecondTopUiRow; + var opts = LocalSettingsTabSingleton.Instance; + wikiButton.transform.SetParent(opts.WikiOnBottomRow.Value ? secondRow.transform : firstRow.transform); + } + + public static void PlaceSubmergedButton(UiButtonPostResetEvent @event) + { + var subButton = MiraHudHelper.SubmergedFloorButton; + if (!subButton) + { + return; + } + var secondRow = @event.SecondTopUiRow; + subButton.transform.SetParent(secondRow.transform); + } + + public static void PlaceModifierUi(UiButtonPostResetEvent @event) + { + var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!; + if (!modDisplay) + { + return; + } + var secondRow = @event.SecondTopUiRow; + modDisplay.transform.SetParent(secondRow.transform); + } +}