From 2bfe6e34aef4248a890bd4fb427796625bd99cc9 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 21 Oct 2021 20:18:58 +0500 Subject: [PATCH] Select first fix (#380) * fixed SelectFirstOnActivate in OWML menus and tweaked nav generation --- .../ModMenuWithSelectables.cs | 3 ++ src/OWML.ModHelper.Menus/ModsMenu.cs | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/OWML.ModHelper.Menus/ModMenuWithSelectables.cs b/src/OWML.ModHelper.Menus/ModMenuWithSelectables.cs index 08bf9b8e..3bda16ce 100644 --- a/src/OWML.ModHelper.Menus/ModMenuWithSelectables.cs +++ b/src/OWML.ModHelper.Menus/ModMenuWithSelectables.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OWML.Utils; using OWML.Common; using OWML.Common.Menus; using OWML.ModHelper.Input; @@ -83,6 +84,8 @@ public override void Initialize(Menu menu) public override void UpdateNavigation() { + var options = Layout.GetComponentsInChildren(); + Menu.SetValue("_menuOptions", options.ToArray()); Selectables = Layout.GetComponentsInChildren() .Select(x => x.GetComponent()) .Where(x => x != null).ToList(); diff --git a/src/OWML.ModHelper.Menus/ModsMenu.cs b/src/OWML.ModHelper.Menus/ModsMenu.cs index 82ed70a1..df39681e 100644 --- a/src/OWML.ModHelper.Menus/ModsMenu.cs +++ b/src/OWML.ModHelper.Menus/ModsMenu.cs @@ -16,6 +16,7 @@ public class ModsMenu : ModPopupMenu, IModsMenu private readonly IModStorage _storage; private readonly List _modConfigMenus = new(); + private readonly List _menuOptions = new(); private IModMenus _menus; public ModsMenu( @@ -64,9 +65,10 @@ public void Initialize(IModMenus menus, IModOWMenu owMenu) private IModPopupMenu CreateModsMenu(IModTabbedMenu options) { + _menuOptions.Clear(); var modsTab = CreateTab(options, ModsTitle); - var owmlButton = options.GameplayTab.Buttons.First().Copy(Constants.OwmlTitle); + var owmlButton = CreateButton(options, Constants.OwmlTitle); modsTab.AddButton((IModButtonBase)owmlButton, 0); var owmlTab = CreateTab(options, Constants.OwmlTitle); owmlTab.HideButton(); @@ -78,8 +80,7 @@ private IModPopupMenu CreateModsMenu(IModTabbedMenu options) var disabledMods = _modConfigMenus.Except(enabledMods).ToList(); CreateBlockOfButtons(options, modsTab, disabledMods, index, "DISABLED MODS"); - modsTab.UpdateNavigation(); - modsTab.SelectFirst(); + modsTab.Menu.SetValue("_menuOptions", _menuOptions.ToArray()); return modsTab; } @@ -98,8 +99,7 @@ private int CreateBlockOfButtons(IModTabbedMenu options, IModTabMenu menu, separator.Element.transform.localScale = options.GameplayTab.Buttons.First().Button.transform.localScale; foreach (var modConfigMenu in configMenus) { - var modButton = options.GameplayTab.Buttons.First().Copy(modConfigMenu.Manifest.Name); - modButton.Button.enabled = true; + var modButton = CreateButton(options, modConfigMenu.Manifest.Name); var modTab = CreateTab(options, modConfigMenu.Manifest.Name); modTab.HideButton(); InitConfigMenu(modConfigMenu, options, modTab); @@ -122,6 +122,24 @@ private void InitConfigMenu(IModConfigMenuBase modConfigMenu, IModTabbedMenu opt modConfigMenu.UpdateUIValues(); } + private IModButton CreateButton(IModTabbedMenu options, string name) + { + var modButton = options.GameplayTab.Buttons.First().Copy(name); + modButton.Button.enabled = true; + if ((modButton.Button.FindSelectableOnRight() != null) || (modButton.Button.FindSelectableOnLeft() != null)) + { + var nav = modButton.Button.navigation; + nav.selectOnLeft = null; + nav.selectOnRight = null; + modButton.Button.navigation = nav; + } + GameObject.Destroy(modButton.Button.GetComponent()); + var menuOpt = modButton.Button.gameObject.AddComponent(); + menuOpt.SetSelectable(modButton.Button); + _menuOptions.Add(menuOpt); + return modButton; + } + private static IModTabMenu CreateTab(IModTabbedMenu options, string name) { var modsTab = options.AudioTab.Copy(name);