From 721bd20d2bb2a9229da77aa4c6b465a6f93bdaa1 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sun, 16 Aug 2026 11:08:08 -0400 Subject: [PATCH] improve lobby view pane gamemode handling --- .../Patches/Options/LobbyViewPanePatches.cs | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs index ec44875..a048c33 100644 --- a/MiraAPI/Patches/Options/LobbyViewPanePatches.cs +++ b/MiraAPI/Patches/Options/LobbyViewPanePatches.cs @@ -24,7 +24,7 @@ public static class LobbyViewPanePatches { private static int SelectedModIdx { get; set; } - private static MiraPluginInfo[] Plugins => MiraPluginManager.Instance.PluginsWithOptionsOrGameModes; + private static MiraPluginInfo[] Plugins => MiraPluginManager.Instance.RegisteredPluginsWithOptions; private static MiraPluginInfo? SelectedMod => SelectedModIdx == 0 ? null @@ -34,6 +34,41 @@ public static class LobbyViewPanePatches private static StringNames ModifiersTabName { get; } = CustomStringName.CreateAndRegister("ModifiersTab"); + private static AbstractGameMode? GetCustomGamemode() + { + if (!CustomGameModeManager.IsClassic() && !CustomGameModeManager.IsHideNSeek()) + { + return CustomGameModeManager.ActiveMode; + } + + return null; + } + + private static IEnumerable? GetCustomGamemodeOptions() + { + if (CustomGameModeManager.ActiveMode == null) + { + return null; + } + + if (!CustomGameModeManager.IsClassic() && !CustomGameModeManager.IsHideNSeek()) + { + var plugin = CustomGameModeManager.FindParentMod(CustomGameModeManager.ActiveMode); + + return plugin?.InternalOptionGroups + .Where(x => x.OptionableType?.IsAssignableTo(typeof(AbstractGameMode)) == true && x.GroupVisible()); + } + + return null; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(LobbyViewSettingsPane), nameof(LobbyViewSettingsPane.OnEnable))] + public static void OnEnable(LobbyViewSettingsPane __instance) + { + Refresh(__instance); + } + [HarmonyPostfix] [HarmonyPatch(nameof(LobbyViewSettingsPane.Awake))] public static void AwakePatch(LobbyViewSettingsPane __instance) @@ -113,8 +148,10 @@ public static class LobbyViewPanePatches { if (SelectedMod == null) { + var cgm = GetCustomGamemode(); ModifiersTabButton?.gameObject.SetActive(false); - menu.rolesTabButton.gameObject.SetActive(true); + menu.rolesTabButton.gameObject.SetActive(cgm is null or { ShowNormalRoleSettings: true }); + menu.gameModeText.text = cgm is null ? "Main" : cgm.ColoredName; } else { @@ -125,9 +162,9 @@ public static class LobbyViewPanePatches ModifiersTabButton?.gameObject.SetActive(showModifierButton); menu.rolesTabButton.gameObject.SetActive(showRolesButton); + menu.gameModeText.text = SelectedMod.PluginInfo.Metadata.Name; } - menu.gameModeText.text = SelectedMod?.PluginInfo.Metadata.Name ?? "Main"; menu.RefreshTab(); menu.scrollBar.ScrollToTop(); } @@ -159,8 +196,15 @@ public static class LobbyViewPanePatches [HarmonyPatch(nameof(LobbyViewSettingsPane.DrawNormalTab))] public static bool DrawNormalTabPatch(LobbyViewSettingsPane __instance) { - if ((CustomGameModeManager.IsClassic() || CustomGameModeManager.IsHideNSeek()) && (SelectedModIdx == 0 || SelectedMod == null)) + if (SelectedMod == null) { + var gamemodeOpts = GetCustomGamemodeOptions(); + if (gamemodeOpts != null) + { + DrawOptions(__instance, gamemodeOpts); + return false; + } + return true; } @@ -170,9 +214,7 @@ public static class LobbyViewPanePatches } var filteredGroups = SelectedMod.InternalOptionGroups - .Where(x => (x is { ParentMenu: not MenuCategory.Modifiers, OptionableType: null } - || x.OptionableType?.IsAssignableTo(typeof(AbstractGameMode)) == true) - && x.GroupVisible()); + .Where(x => x is { ParentMenu: not MenuCategory.Modifiers, OptionableType: null } && x.GroupVisible()); DrawOptions(__instance, filteredGroups); return false;