diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index fcc3722..d18407d 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using HarmonyLib; using MiraAPI.Modifiers; @@ -30,6 +31,8 @@ internal static class GameSettingMenuPatches private static PassiveButton? _modifiersButton; private static PassiveButton? _smallRolesButton; + private static Dictionary OptionsPositions { get; } = []; + [HarmonyPostfix] [HarmonyPatch(nameof(GameSettingMenu.ChangeTab))] public static void ChangeTabPostfix(GameSettingMenu __instance, int tabNum, bool previewOnly) @@ -110,6 +113,11 @@ internal static class GameSettingMenuPatches passiveButton.OnClick.AddListener( (UnityAction)(() => { + if (!__instance.RoleSettingsTab.AdvancedRolesSettings.active) + { + RoleSettingMenuPatches.RolePositions[SelectedModIdx] = __instance.RoleSettingsTab.scrollBar.Inner.localPosition; + } + OptionsPositions[SelectedModIdx] = __instance.GameSettingsTab.scrollBar.Inner.localPosition; SelectedModIdx += 1; if (SelectedModIdx > MiraPluginManager.Instance.RegisteredPlugins().Length) { @@ -128,6 +136,11 @@ internal static class GameSettingMenuPatches backButton.gameObject.GetComponent().OnClick.AddListener( (UnityAction)(() => { + if (!__instance.RoleSettingsTab.AdvancedRolesSettings.active) + { + RoleSettingMenuPatches.RolePositions[SelectedModIdx] = __instance.RoleSettingsTab.scrollBar.Inner.localPosition; + } + OptionsPositions[SelectedModIdx] = __instance.GameSettingsTab.scrollBar.Inner.localPosition; SelectedModIdx -= 1; if (SelectedModIdx < 0) { @@ -407,7 +420,15 @@ internal static class GameSettingMenuPatches rolesMenu.AdvancedRolesSettings.gameObject.SetActive(false); rolesMenu.RoleChancesSettings.gameObject.SetActive(true); 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) @@ -421,7 +442,15 @@ internal static class GameSettingMenuPatches .ForEach(header => header.gameObject.DestroyImmediate()); 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) diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 8d171a1..a15ce2a 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -22,9 +22,11 @@ namespace MiraAPI.Patches.Options; [HarmonyPatch(typeof(RolesSettingsMenu))] public static class RoleSettingMenuPatches { - private static Dictionary RoleGroupHidden { get; set; } = new(); - private static List Headers { get; set; } = new(); - private static List RoleOptionSettings { get; set; } = new(); + public static Dictionary RolePositions { get; set; } = []; + + private static Dictionary RoleGroupHidden { get; set; } = []; + private static List Headers { get; set; } = []; + private static List RoleOptionSettings { get; set; } = []; private static float ScrollerNum { get; set; } = 0.522f; @@ -232,6 +234,15 @@ public static class RoleSettingMenuPatches private static void SetScrollBounds(this Scroller scroller) { 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] @@ -251,7 +262,6 @@ public static class RoleSettingMenuPatches } __instance.scrollBar.SetScrollBounds(); - __instance.scrollBar.ScrollToTop(); } private static void ValueChanged(OptionBehaviour obj) @@ -356,6 +366,8 @@ public static class RoleSettingMenuPatches return; } + RolePositions[GameSettingMenuPatches.SelectedModIdx] = __instance.scrollBar.Inner.localPosition; + __instance.roleDescriptionText.text = customRole.RoleLongDescription; __instance.roleTitleText.text = TranslationController.Instance.GetString( role.StringName,