Skip to content

Commit

Permalink
Select first fix (#380)
Browse files Browse the repository at this point in the history
* fixed SelectFirstOnActivate in OWML menus and tweaked nav generation
  • Loading branch information
TAImatem authored and Raicuparta committed Oct 21, 2021
1 parent 65f1365 commit 2bfe6e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/OWML.ModHelper.Menus/ModMenuWithSelectables.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -83,6 +84,8 @@ public override void Initialize(Menu menu)

public override void UpdateNavigation()
{
var options = Layout.GetComponentsInChildren<MenuOption>();
Menu.SetValue("_menuOptions", options.ToArray());
Selectables = Layout.GetComponentsInChildren<MenuOption>()
.Select(x => x.GetComponent<Selectable>())
.Where(x => x != null).ToList();
Expand Down
28 changes: 23 additions & 5 deletions src/OWML.ModHelper.Menus/ModsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ModsMenu : ModPopupMenu, IModsMenu

private readonly IModStorage _storage;
private readonly List<IModConfigMenu> _modConfigMenus = new();
private readonly List<MenuOption> _menuOptions = new();
private IModMenus _menus;

public ModsMenu(
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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<TabButton>());
var menuOpt = modButton.Button.gameObject.AddComponent<MenuOption>();
menuOpt.SetSelectable(modButton.Button);
_menuOptions.Add(menuOpt);
return modButton;
}

private static IModTabMenu CreateTab(IModTabbedMenu options, string name)
{
var modsTab = options.AudioTab.Copy(name);
Expand Down

0 comments on commit 2bfe6e3

Please sign in to comment.