mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Fix conflicting Local Settings Tabs
Neil made this change fyi
This commit is contained in:
1 parent
e4cb4a28df
commit
dc87c0fc7f
1 file changed
+56
-54
@@ -2,9 +2,9 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||||
using MiraAPI.LocalSettings;
|
using MiraAPI.LocalSettings;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Utilities.Extensions;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -15,12 +15,18 @@ namespace MiraAPI.Patches.LocalSettings;
|
|||||||
public static class OptionsMenuPatches
|
public static class OptionsMenuPatches
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<int, List<GameObject>> TabButtons = [];
|
private static readonly Dictionary<int, List<GameObject>> TabButtons = [];
|
||||||
private static int currentPage = 1;
|
private static int _currentPage = 1;
|
||||||
|
|
||||||
internal static OptionsMenuBehaviour? Instance { get; private set; }
|
internal static OptionsMenuBehaviour? Instance { get; private set; }
|
||||||
|
|
||||||
[SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Internal behaviour that does not need property-level validation.")]
|
[SuppressMessage(
|
||||||
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")]
|
"Critical Code Smell",
|
||||||
|
"S2223:Non-constant static fields should not be visible",
|
||||||
|
Justification = "Internal behaviour that does not need property-level validation.")]
|
||||||
|
[SuppressMessage(
|
||||||
|
"StyleCop.CSharp.MaintainabilityRules",
|
||||||
|
"SA1401:Fields should be private",
|
||||||
|
Justification = "Read above.")]
|
||||||
internal static BoxCollider2D MaskCollider = null!;
|
internal static BoxCollider2D MaskCollider = null!;
|
||||||
|
|
||||||
private static SpriteRenderer? background;
|
private static SpriteRenderer? background;
|
||||||
@@ -69,7 +75,7 @@ public static class OptionsMenuPatches
|
|||||||
MaskCollider.isTrigger = true;
|
MaskCollider.isTrigger = true;
|
||||||
MaskCollider.enabled = true;
|
MaskCollider.enabled = true;
|
||||||
|
|
||||||
currentPage = 1;
|
_currentPage = 1;
|
||||||
TabButtons.Clear();
|
TabButtons.Clear();
|
||||||
float yOffset = 0;
|
float yOffset = 0;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@@ -83,7 +89,7 @@ public static class OptionsMenuPatches
|
|||||||
{
|
{
|
||||||
var button = settings.CreateTabButton(__instance, ref tabIdx, ref yOffset);
|
var button = settings.CreateTabButton(__instance, ref tabIdx, ref yOffset);
|
||||||
button.GetComponent<TabGroup>().Content = tab;
|
button.GetComponent<TabGroup>().Content = tab;
|
||||||
button.SetActive(page == currentPage);
|
button.SetActive(page == _currentPage);
|
||||||
|
|
||||||
if (!TabButtons.TryGetValue(page, out var list))
|
if (!TabButtons.TryGetValue(page, out var list))
|
||||||
{
|
{
|
||||||
@@ -105,20 +111,6 @@ public static class OptionsMenuPatches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ChangePage(int increase)
|
|
||||||
{
|
|
||||||
currentPage += increase;
|
|
||||||
if (currentPage > TabButtons.Count)
|
|
||||||
{
|
|
||||||
currentPage = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentPage < 1)
|
|
||||||
{
|
|
||||||
currentPage = TabButtons.Count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create page buttons
|
// Create page buttons
|
||||||
// TODO: In-game menu has no close button. I tried making one from scratch but failed. Add one later plz
|
// TODO: In-game menu has no close button. I tried making one from scratch but failed. Add one later plz
|
||||||
if (TabButtons.Count <= 1)
|
if (TabButtons.Count <= 1)
|
||||||
@@ -126,44 +118,56 @@ public static class OptionsMenuPatches
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextButton = Object.Instantiate(__instance.BackButton, __instance.transform).GetComponent<PassiveButton>();
|
CreatePageButton(__instance, 3.2f, false, 1);
|
||||||
nextButton.transform.localPosition = new Vector3(3.2f, 2.6f, -10);
|
CreatePageButton(__instance, 2.9f, true, -1);
|
||||||
nextButton.transform.localScale = new Vector2(0.25f, 0.25f);
|
}
|
||||||
var nextRend = nextButton.GetComponent<SpriteRenderer>();
|
|
||||||
nextRend.sprite = MiraAssets.NextButton.LoadAsset();
|
|
||||||
nextButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
|
||||||
|
|
||||||
var nextRollover = nextButton.gameObject.AddComponent<ButtonRolloverHandler>();
|
private static void CreatePageButton(OptionsMenuBehaviour menu, float x, bool flip, int direction)
|
||||||
nextRollover.Target = nextRend;
|
{
|
||||||
nextRollover.OverColor = Palette.AcceptedGreen;
|
var obj = new GameObject("PageButton") { layer = 5 };
|
||||||
|
obj.transform.SetParent(menu.transform);
|
||||||
|
obj.transform.localPosition = new Vector3(x, 2.6f, -10);
|
||||||
|
obj.transform.localScale = new Vector3(0.25f, 0.25f, 1);
|
||||||
|
|
||||||
nextButton.OnClick = new Button.ButtonClickedEvent();
|
var rend = obj.AddComponent<SpriteRenderer>();
|
||||||
nextButton.OnClick.AddListener(
|
rend.sprite = MiraAssets.NextButton.LoadAsset();
|
||||||
|
rend.flipX = flip;
|
||||||
|
|
||||||
|
var col = obj.AddComponent<BoxCollider2D>();
|
||||||
|
col.size = rend.sprite.bounds.size;
|
||||||
|
|
||||||
|
var rollover = obj.AddComponent<ButtonRolloverHandler>();
|
||||||
|
rollover.Target = rend;
|
||||||
|
rollover.OverColor = Palette.AcceptedGreen;
|
||||||
|
rollover.OutColor = Color.white;
|
||||||
|
|
||||||
|
var button = obj.AddComponent<PassiveButton>();
|
||||||
|
button.Colliders = new Il2CppReferenceArray<Collider2D>([col]);
|
||||||
|
button.OnClick = new Button.ButtonClickedEvent();
|
||||||
|
button.OnClick.AddListener(
|
||||||
(UnityAction)(() =>
|
(UnityAction)(() =>
|
||||||
{
|
{
|
||||||
ChangePage(1);
|
ChangePage(direction);
|
||||||
UpdatePages();
|
UpdatePages();
|
||||||
}));
|
}));
|
||||||
|
button.OnMouseOver = new UnityEvent();
|
||||||
|
button.OnMouseOver.AddListener((UnityAction)(() => rollover.DoMouseOver()));
|
||||||
|
button.OnMouseOut = new UnityEvent();
|
||||||
|
button.OnMouseOut.AddListener((UnityAction)(() => rollover.DoMouseOut()));
|
||||||
|
}
|
||||||
|
|
||||||
var backButton = Object.Instantiate(__instance.BackButton, __instance.transform).GetComponent<PassiveButton>();
|
private static void ChangePage(int increase)
|
||||||
backButton.transform.localPosition = new Vector3(2.9f, 2.6f, -10);
|
{
|
||||||
backButton.transform.localScale = new Vector2(0.25f, 0.25f);
|
_currentPage += increase;
|
||||||
var backRend = backButton.GetComponent<SpriteRenderer>();
|
if (_currentPage > TabButtons.Count)
|
||||||
backRend.sprite = MiraAssets.NextButton.LoadAsset();
|
{
|
||||||
backRend.flipX = true;
|
_currentPage = 1;
|
||||||
backButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
}
|
||||||
|
|
||||||
var backRollover = backButton.gameObject.AddComponent<ButtonRolloverHandler>();
|
if (_currentPage < 1)
|
||||||
backRollover.Target = backRend;
|
{
|
||||||
backRollover.OverColor = Palette.AcceptedGreen;
|
_currentPage = TabButtons.Count;
|
||||||
|
}
|
||||||
backButton.OnClick = new Button.ButtonClickedEvent();
|
|
||||||
backButton.OnClick.AddListener(
|
|
||||||
(UnityAction)(() =>
|
|
||||||
{
|
|
||||||
ChangePage(-1);
|
|
||||||
UpdatePages();
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -194,7 +198,7 @@ public static class OptionsMenuPatches
|
|||||||
public static void OpenPostfix()
|
public static void OpenPostfix()
|
||||||
{
|
{
|
||||||
LocalSettingsManager.AvailableTabs.ForEach(CustomClose);
|
LocalSettingsManager.AvailableTabs.ForEach(CustomClose);
|
||||||
currentPage = 1;
|
_currentPage = 1;
|
||||||
UpdatePages();
|
UpdatePages();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,9 +208,7 @@ public static class OptionsMenuPatches
|
|||||||
{
|
{
|
||||||
pages.Value?
|
pages.Value?
|
||||||
.Where(x => x != null)
|
.Where(x => x != null)
|
||||||
.Do(
|
.Do(x => x?.SetActive(pages.Key == _currentPage));
|
||||||
x => x?.SetActive(
|
|
||||||
pages.Key == currentPage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user