mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Add UiButtonResetEvent for better ui button grid
This commit is contained in:
1 parent
85fb507a43
commit
81c6bac979
6 files changed
+125
-42
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace MiraAPI.Events.Mira;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event fired by Mira API to adjust the UI buttons at the top right of the screen.
|
||||||
|
/// </summary>
|
||||||
|
public class UiButtonPostResetEvent : MiraEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="GameObject"/> parent for the very top UI row.
|
||||||
|
/// </summary>
|
||||||
|
public GameObject MainTopUiRow { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="GameObject"/> parent for the second top UI row.
|
||||||
|
/// </summary>
|
||||||
|
public GameObject SecondTopUiRow { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="UiButtonPostResetEvent"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="topUiRow">The <see cref="GameObject"/> for the top UI row.</param>
|
||||||
|
/// <param name="secondUiRow">The <see cref="GameObject"/> for the second UI row.</param>
|
||||||
|
public UiButtonPostResetEvent(GameObject topUiRow, GameObject secondUiRow)
|
||||||
|
{
|
||||||
|
MainTopUiRow = topUiRow;
|
||||||
|
SecondTopUiRow = secondUiRow;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
namespace MiraAPI.Events.Mira;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event fired by Mira API prior to adjusting the UI buttons at the top right of the screen.
|
||||||
|
/// </summary>
|
||||||
|
public class UiButtonResetEvent : MiraEvent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="UiButtonResetEvent"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public UiButtonResetEvent()
|
||||||
|
{
|
||||||
|
// nothing!
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -186,7 +186,7 @@ public sealed class MiraHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
{
|
{
|
||||||
ExtraUiTopRight = new GameObject("ExtraUiTopRight")
|
ExtraUiTopRight = new GameObject("ExtraUiTopRight")
|
||||||
{
|
{
|
||||||
layer = UiTopRight.layer
|
layer = UiTopRight.layer,
|
||||||
};
|
};
|
||||||
ExtraUiTopRight.transform.SetParent(instance.MapButton.transform.parent.parent, false);
|
ExtraUiTopRight.transform.SetParent(instance.MapButton.transform.parent.parent, false);
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
|
|||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
Harmony.PatchAll();
|
Harmony.PatchAll();
|
||||||
|
UiResetEvents.Initialize();
|
||||||
JudgeEvents.Initialize();
|
JudgeEvents.Initialize();
|
||||||
|
|
||||||
ReactorCredits.Register("Mira API", Version, IsDevBuild, ReactorCredits.AlwaysShow);
|
ReactorCredits.Register("Mira API", Version, IsDevBuild, ReactorCredits.AlwaysShow);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
|
using MiraAPI.Events;
|
||||||
|
using MiraAPI.Events.Mira;
|
||||||
using MiraAPI.Hud;
|
using MiraAPI.Hud;
|
||||||
using MiraAPI.LocalSettings;
|
using MiraAPI.LocalSettings;
|
||||||
using MiraAPI.LocalSettings.Attributes;
|
using MiraAPI.LocalSettings.Attributes;
|
||||||
@@ -80,54 +82,18 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
|||||||
{
|
{
|
||||||
var topUi = MiraHudHelper.UiTopRight;
|
var topUi = MiraHudHelper.UiTopRight;
|
||||||
var extraTopUi = MiraHudHelper.ExtraUiTopRight;
|
var extraTopUi = MiraHudHelper.ExtraUiTopRight;
|
||||||
var wikiButton = MiraHudHelper.VanillaMatchInfoButton;
|
|
||||||
var subButton = MiraHudHelper.SubmergedFloorButton;
|
|
||||||
var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!;
|
|
||||||
ResetButtonPositions();
|
|
||||||
if (topUi && extraTopUi)
|
if (topUi && extraTopUi)
|
||||||
{
|
{
|
||||||
var opts = LocalSettingsTabSingleton<MiraApiSettings>.Instance;
|
var genericEvent = new UiButtonResetEvent();
|
||||||
if (wikiButton)
|
MiraEventManager.InvokeEvent(genericEvent);
|
||||||
{
|
|
||||||
wikiButton.transform.SetParent(opts.WikiOnBottomRow.Value ? extraTopUi.transform : topUi.transform);
|
var genericEvent2 = new UiButtonPostResetEvent(topUi, extraTopUi);
|
||||||
}
|
MiraEventManager.InvokeEvent(genericEvent2);
|
||||||
if (subButton)
|
|
||||||
{
|
|
||||||
subButton.transform.SetParent(extraTopUi.transform);
|
|
||||||
}
|
|
||||||
if (modDisplay)
|
|
||||||
{
|
|
||||||
modDisplay.transform.SetParent(extraTopUi.transform);
|
|
||||||
}
|
|
||||||
MiraHudHelper.UiGrid.ArrangeChilds();
|
MiraHudHelper.UiGrid.ArrangeChilds();
|
||||||
MiraHudHelper.ExtraUiGrid.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()
|
public static IEnumerator CoResizeSettingsUI()
|
||||||
{
|
{
|
||||||
while (!HudManager.Instance || !MiraHudHelper.UiGrid || !MiraHudHelper.ExtraUiGrid)
|
while (!HudManager.Instance || !MiraHudHelper.UiGrid || !MiraHudHelper.ExtraUiGrid)
|
||||||
|
|||||||
@@ -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<UiButtonResetEvent>(@event => ResetButtonParents(@event));
|
||||||
|
MiraEventManager.RegisterEventHandler<UiButtonPostResetEvent>(@event => PlaceWikiButton(@event), -900);
|
||||||
|
MiraEventManager.RegisterEventHandler<UiButtonPostResetEvent>(@event => PlaceSubmergedButton(@event), -800);
|
||||||
|
MiraEventManager.RegisterEventHandler<UiButtonPostResetEvent>(@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<MiraApiSettings>.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user