Skip to content

Commit

Permalink
Save menu state when changing to the menu scene (YARG-234)
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Mar 13, 2024
1 parent 650fa16 commit f17649c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
40 changes: 33 additions & 7 deletions Assets/Script/Menu/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ public enum Menu
History,
}

private static bool _firstLaunch = true;
/// <summary>
/// The values that <see cref="_lastOpenMenu"/> is allowed to be set to
/// (not including <see cref="Menu.None"/>.
/// </summary>
private static readonly HashSet<Menu> _allowedLastOpenMenus = new()
{
Menu.MusicLibrary,
Menu.History
};

/// <summary>
/// The menu that was last open when the menu scene gets disabled.
/// </summary>
private static Menu _lastOpenMenu = Menu.None;

private Dictionary<Menu, MenuObject> _menus;

Expand All @@ -34,15 +47,28 @@ protected override void SingletonAwake()

private void Start()
{
if (_firstLaunch)
// Always push the main menu
PushMenu(Menu.MainMenu);

if (_lastOpenMenu != Menu.None)
{
PushMenu(Menu.MainMenu);
_firstLaunch = false;
PushMenu(_lastOpenMenu);
}
else
}

private void OnDisable()
{
_lastOpenMenu = Menu.None;

// Set the last open menu to the first instance of the allowed menu
// Loops from top to bottom
foreach (var menu in _openMenus)
{
PushMenu(Menu.MainMenu);
PushMenu(Menu.MusicLibrary);
if (_allowedLastOpenMenus.Contains(menu))
{
_lastOpenMenu = menu;
break;
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions Assets/Script/Menu/MusicLibrary/MusicLibraryMenu.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Cysharp.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using YARG.Audio;
using YARG.Core.Input;
using YARG.Core.Song;
Expand Down

0 comments on commit f17649c

Please sign in to comment.