Skip to content

Commit

Permalink
Fix issue where clicking too fast on helpbar buttons would pop all me…
Browse files Browse the repository at this point in the history
…nus (#899)
  • Loading branch information
polson authored Oct 12, 2024
1 parent 7e71b25 commit 85b4282
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Assets/Script/Menu/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,34 @@ public MenuObject PushMenu(Menu menu, bool setActiveImmediate = true)

public void PopMenu()
{
//Don't pop the only remaining menu
if (_openMenus.Count == 1)
{
return;
}

// Close the currently open one
if (_openMenus.TryPeek(out var currentMenuEnum) &&
if (_openMenus.TryPop(out var currentMenuEnum) &&
_menus.TryGetValue(currentMenuEnum, out var currentMenu))
{
currentMenu.gameObject.SetActive(false);
}

_openMenus.Pop();
var menu = _openMenus.Peek();

// Show the under one
if (_menus.TryGetValue(menu, out var newMenu))
if (_openMenus.TryPeek(out var newMenuEnum) &&
_menus.TryGetValue(newMenuEnum, out var newMenu))
{
newMenu.gameObject.SetActive(true);
}
else
{
throw new InvalidOperationException($"Failed to open menu {menu}.");
throw new InvalidOperationException($"Failed to open menu {newMenuEnum}.");
}
}

public void ReactivateCurrentMenu()
{
var menu = _openMenus.Peek();

// Show the under one
if (_menus.TryGetValue(menu, out var newMenu))
if (_openMenus.TryPeek(out var menu) && _menus.TryGetValue(menu, out var newMenu))
{
newMenu.gameObject.SetActive(false);
newMenu.gameObject.SetActive(true);
Expand Down

0 comments on commit 85b4282

Please sign in to comment.