mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Save scroll positions on options and roles pages
This commit is contained in:
1 parent
f9600bc906
commit
acc4b1c8dd
2 files changed
+47
-6
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
@@ -30,6 +31,8 @@ internal static class GameSettingMenuPatches
|
|||||||
private static PassiveButton? _modifiersButton;
|
private static PassiveButton? _modifiersButton;
|
||||||
private static PassiveButton? _smallRolesButton;
|
private static PassiveButton? _smallRolesButton;
|
||||||
|
|
||||||
|
private static Dictionary<int, Vector3> OptionsPositions { get; } = [];
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(nameof(GameSettingMenu.ChangeTab))]
|
[HarmonyPatch(nameof(GameSettingMenu.ChangeTab))]
|
||||||
public static void ChangeTabPostfix(GameSettingMenu __instance, int tabNum, bool previewOnly)
|
public static void ChangeTabPostfix(GameSettingMenu __instance, int tabNum, bool previewOnly)
|
||||||
@@ -110,6 +113,11 @@ internal static class GameSettingMenuPatches
|
|||||||
passiveButton.OnClick.AddListener(
|
passiveButton.OnClick.AddListener(
|
||||||
(UnityAction)(() =>
|
(UnityAction)(() =>
|
||||||
{
|
{
|
||||||
|
if (!__instance.RoleSettingsTab.AdvancedRolesSettings.active)
|
||||||
|
{
|
||||||
|
RoleSettingMenuPatches.RolePositions[SelectedModIdx] = __instance.RoleSettingsTab.scrollBar.Inner.localPosition;
|
||||||
|
}
|
||||||
|
OptionsPositions[SelectedModIdx] = __instance.GameSettingsTab.scrollBar.Inner.localPosition;
|
||||||
SelectedModIdx += 1;
|
SelectedModIdx += 1;
|
||||||
if (SelectedModIdx > MiraPluginManager.Instance.RegisteredPlugins().Length)
|
if (SelectedModIdx > MiraPluginManager.Instance.RegisteredPlugins().Length)
|
||||||
{
|
{
|
||||||
@@ -128,6 +136,11 @@ internal static class GameSettingMenuPatches
|
|||||||
backButton.gameObject.GetComponent<PassiveButton>().OnClick.AddListener(
|
backButton.gameObject.GetComponent<PassiveButton>().OnClick.AddListener(
|
||||||
(UnityAction)(() =>
|
(UnityAction)(() =>
|
||||||
{
|
{
|
||||||
|
if (!__instance.RoleSettingsTab.AdvancedRolesSettings.active)
|
||||||
|
{
|
||||||
|
RoleSettingMenuPatches.RolePositions[SelectedModIdx] = __instance.RoleSettingsTab.scrollBar.Inner.localPosition;
|
||||||
|
}
|
||||||
|
OptionsPositions[SelectedModIdx] = __instance.GameSettingsTab.scrollBar.Inner.localPosition;
|
||||||
SelectedModIdx -= 1;
|
SelectedModIdx -= 1;
|
||||||
if (SelectedModIdx < 0)
|
if (SelectedModIdx < 0)
|
||||||
{
|
{
|
||||||
@@ -407,7 +420,15 @@ internal static class GameSettingMenuPatches
|
|||||||
rolesMenu.AdvancedRolesSettings.gameObject.SetActive(false);
|
rolesMenu.AdvancedRolesSettings.gameObject.SetActive(false);
|
||||||
rolesMenu.RoleChancesSettings.gameObject.SetActive(true);
|
rolesMenu.RoleChancesSettings.gameObject.SetActive(true);
|
||||||
rolesMenu.SetQuotaTab();
|
rolesMenu.SetQuotaTab();
|
||||||
rolesMenu.scrollBar.ScrollToTop();
|
if (RoleSettingMenuPatches.RolePositions.TryGetValue(SelectedModIdx, out var pos))
|
||||||
|
{
|
||||||
|
rolesMenu.scrollBar.Inner.localPosition = pos;
|
||||||
|
rolesMenu.scrollBar.UpdateScrollBars();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rolesMenu.scrollBar.ScrollToTop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CleanupSettings(GameOptionsMenu gameOptMenu)
|
void CleanupSettings(GameOptionsMenu gameOptMenu)
|
||||||
@@ -421,7 +442,15 @@ internal static class GameSettingMenuPatches
|
|||||||
.ForEach(header => header.gameObject.DestroyImmediate());
|
.ForEach(header => header.gameObject.DestroyImmediate());
|
||||||
|
|
||||||
gameOptMenu.Initialize();
|
gameOptMenu.Initialize();
|
||||||
gameOptMenu.scrollBar.ScrollToTop();
|
if (OptionsPositions.TryGetValue(SelectedModIdx, out var pos))
|
||||||
|
{
|
||||||
|
gameOptMenu.scrollBar.Inner.localPosition = pos;
|
||||||
|
gameOptMenu.scrollBar.UpdateScrollBars();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameOptMenu.scrollBar.ScrollToTop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roles.roleChances != null && SelectedMod?.CustomRoles.Count > 0)
|
if (roles.roleChances != null && SelectedMod?.CustomRoles.Count > 0)
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ namespace MiraAPI.Patches.Options;
|
|||||||
[HarmonyPatch(typeof(RolesSettingsMenu))]
|
[HarmonyPatch(typeof(RolesSettingsMenu))]
|
||||||
public static class RoleSettingMenuPatches
|
public static class RoleSettingMenuPatches
|
||||||
{
|
{
|
||||||
private static Dictionary<RoleOptionsGroup, bool> RoleGroupHidden { get; set; } = new();
|
public static Dictionary<int, Vector3> RolePositions { get; set; } = [];
|
||||||
private static List<GameObject> Headers { get; set; } = new();
|
|
||||||
private static List<RoleOptionSetting> RoleOptionSettings { get; set; } = new();
|
private static Dictionary<RoleOptionsGroup, bool> RoleGroupHidden { get; set; } = [];
|
||||||
|
private static List<GameObject> Headers { get; set; } = [];
|
||||||
|
private static List<RoleOptionSetting> RoleOptionSettings { get; set; } = [];
|
||||||
|
|
||||||
private static float ScrollerNum { get; set; } = 0.522f;
|
private static float ScrollerNum { get; set; } = 0.522f;
|
||||||
|
|
||||||
@@ -232,6 +234,15 @@ public static class RoleSettingMenuPatches
|
|||||||
private static void SetScrollBounds(this Scroller scroller)
|
private static void SetScrollBounds(this Scroller scroller)
|
||||||
{
|
{
|
||||||
scroller.CalculateAndSetYBounds(1 + 1.5f * Headers.Count + RoleOptionSettings.Count, 1f, 6f, 0.43f);
|
scroller.CalculateAndSetYBounds(1 + 1.5f * Headers.Count + RoleOptionSettings.Count, 1f, 6f, 0.43f);
|
||||||
|
if (RolePositions.TryGetValue(GameSettingMenuPatches.SelectedModIdx, out var scroll))
|
||||||
|
{
|
||||||
|
scroller.Inner.localPosition = scroll;
|
||||||
|
scroller.UpdateScrollBars();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scroller.ScrollToTop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
@@ -251,7 +262,6 @@ public static class RoleSettingMenuPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
__instance.scrollBar.SetScrollBounds();
|
__instance.scrollBar.SetScrollBounds();
|
||||||
__instance.scrollBar.ScrollToTop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ValueChanged(OptionBehaviour obj)
|
private static void ValueChanged(OptionBehaviour obj)
|
||||||
@@ -356,6 +366,8 @@ public static class RoleSettingMenuPatches
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RolePositions[GameSettingMenuPatches.SelectedModIdx] = __instance.scrollBar.Inner.localPosition;
|
||||||
|
|
||||||
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
||||||
__instance.roleTitleText.text = TranslationController.Instance.GetString(
|
__instance.roleTitleText.text = TranslationController.Instance.GetString(
|
||||||
role.StringName,
|
role.StringName,
|
||||||
|
|||||||
Reference in new issue
Block a user