Skip to content

Commit

Permalink
fix #592
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula committed Oct 10, 2024
1 parent 6392f7d commit 7d2f751
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/OWML.Common/Interfaces/Menus/IMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ public interface IMenuManager
public IPopupMenuManager PopupMenuManager { get; }

internal IList<IModBehaviour> ModList { get; set; }

/// <summary>
/// Keeps the Mod Options tab open, since it is ephemeral.
/// Otherwise, a popup opening in the tab would close it.
/// </summary>
public void ForceModOptionsOpen(bool force);
}
}
13 changes: 12 additions & 1 deletion src/OWML.ModHelper.Menus/NewMenuSystem/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum SettingType
internal static List<(IModBehaviour behaviour, Menu modMenu)> ModSettingsMenus = new();

private bool _hasSetupMenusThisScene = false;
private bool _forceModOptionsOpen;

public MenuManager(
IModConsole console,
Expand All @@ -52,7 +53,7 @@ public MenuManager(
_unityEvents = unityEvents;
TitleMenuManager = new TitleMenuManager();
PopupMenuManager = new PopupMenuManager(console, harmony, this);
OptionsMenuManager = new OptionsMenuManager(console, unityEvents, PopupMenuManager);
OptionsMenuManager = new OptionsMenuManager(console, unityEvents, PopupMenuManager, this);
PauseMenuManager = new PauseMenuManager(console);

var harmonyInstance = harmony.GetValue<Harmony>("_harmony");
Expand Down Expand Up @@ -85,6 +86,11 @@ public MenuManager(
};
}

public void ForceModOptionsOpen(bool force)
{
_forceModOptionsOpen = force;
}

internal void SetupMenus(IList<IModBehaviour> modList)
{
if (_hasSetupMenusThisScene)
Expand Down Expand Up @@ -210,6 +216,11 @@ void SaveConfig()

newModTab.OnDeactivateMenu += () =>
{
if (_forceModOptionsOpen)
{
return;
}

// Fixes tab dissapearing when you click on it again
// Clicking on a tab closes and opens it again
_unityEvents.FireOnNextUpdate(() =>
Expand Down
15 changes: 13 additions & 2 deletions src/OWML.ModHelper.Menus/NewMenuSystem/OptionsMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ internal class OptionsMenuManager : IOptionsMenuManager
private readonly IModConsole _console;
private readonly IModUnityEvents _unityEvents;
private readonly IPopupMenuManager _popupMenuManager;
private readonly IMenuManager _menuManager;

public OptionsMenuManager(IModConsole console, IModUnityEvents unityEvents, IPopupMenuManager popupMenuManager)
public OptionsMenuManager(IModConsole console, IModUnityEvents unityEvents, IPopupMenuManager popupMenuManager, IMenuManager menuManager)
{
_console = console;
_unityEvents = unityEvents;
_popupMenuManager = popupMenuManager;
_menuManager = menuManager;
}

public (Menu menu, TabButton button) CreateStandardTab(string name)
Expand Down Expand Up @@ -697,13 +699,22 @@ public IOWMLTextEntryElement AddTextEntryInput(Menu menu, string label, string i
{
var submitAction = CreateButtonWithLabel(menu, label, initialValue, tooltip);
var textInputPopup = _popupMenuManager.CreateInputFieldPopup($"Enter the new value for \"{label}\".", initialValue, "Confirm", "Cancel");
submitAction.OnSubmitAction += () => textInputPopup.EnableMenu(true);
submitAction.OnSubmitAction += () =>
{
_menuManager.ForceModOptionsOpen(true);
textInputPopup.EnableMenu(true);
};

var textEntry = submitAction.gameObject.AddComponent<OWMLTextEntryElement>();
textEntry._overrideTooltipText = tooltip;
textEntry.RegisterPopup(textInputPopup);
textEntry.IsNumeric = isNumeric;

textEntry.OnConfirmEntry += () =>
{
_menuManager.ForceModOptionsOpen(false);
};

if (isNumeric)
{
textInputPopup.OnInputPopupValidateChar += (string input, int charIndex, char addedChar) =>
Expand Down

0 comments on commit 7d2f751

Please sign in to comment.