diff --git a/src/Explorer.csproj b/src/Explorer.csproj index 8bcc7c8..da0d6dc 100644 --- a/src/Explorer.csproj +++ b/src/Explorer.csproj @@ -233,6 +233,11 @@ + + + + + diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 346690b..e8b716e 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -38,7 +38,7 @@ namespace ExplorerBeta public static bool m_showMenu; private static bool m_doneUIInit; - private static float m_startupTime; + private static float m_timeSinceStartup; public ExplorerCore() { @@ -52,10 +52,6 @@ namespace ExplorerBeta ModConfig.OnLoad(); - // Temporary? Need a small delay after OnApplicationStart before we can safely make our GameObject. - // Can't use Threads (crash), can't use Coroutine (no BepInEx support yet). - m_startupTime = Time.realtimeSinceStartup; - InputManager.Init(); ForceUnlockCursor.Init(); @@ -88,12 +84,17 @@ namespace ExplorerBeta public static void Update() { // Temporary delay before UIManager.Init - if (!m_doneUIInit && Time.realtimeSinceStartup - m_startupTime > 1f) + if (!m_doneUIInit) { - UIManager.Init(); + m_timeSinceStartup += Time.deltaTime; - Log("Initialized Explorer UI."); - m_doneUIInit = true; + if (m_timeSinceStartup > 1f) + { + UIManager.Init(); + + Log("Initialized Explorer UI."); + m_doneUIInit = true; + } } if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle)) diff --git a/src/UI/Main/MainMenu.cs b/src/UI/Main/MainMenu.cs index 96162fb..e5e0f43 100644 --- a/src/UI/Main/MainMenu.cs +++ b/src/UI/Main/MainMenu.cs @@ -7,6 +7,7 @@ using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using ExplorerBeta.UI.Shared; +using Explorer.UI.Main.Pages; namespace ExplorerBeta.UI.Main { @@ -19,6 +20,9 @@ namespace ExplorerBeta.UI.Main public GameObject MainPanel { get; private set; } public GameObject PageViewport { get; private set; } + public readonly List Pages = new List(); + private BaseMenuPage m_activePage; + // Navbar buttons private Button m_lastNavButtonPressed; private readonly Color m_navButtonNormal = new Color(65f/255f, 66f/255f, 66f/255f); @@ -35,7 +39,19 @@ namespace ExplorerBeta.UI.Main Instance = this; + Pages.Add(new HomePage()); + Pages.Add(new SearchPage()); + Pages.Add(new ConsolePage()); + Pages.Add(new OptionsPage()); + ConstructMenu(); + + foreach (var page in Pages) + { + page.Init(); + } + + SetPage(Pages[0]); } public void Update() @@ -43,16 +59,15 @@ namespace ExplorerBeta.UI.Main // todo } - #region UI Interaction Callbacks - - private void OnPressHide() + // todo + private void SetPage(BaseMenuPage page) { - ExplorerCore.ShowMenu = false; - } + if (m_activePage == page || page == null) + return; - private void OnNavButtonPressed(string pageName, Button button) - { - ExplorerCore.Log($"Pressed '{pageName}'"); + m_activePage = page; + + var button = page.RefNavbarButton; var colors = button.colors; colors.normalColor = m_navButtonSelected; @@ -67,7 +82,20 @@ namespace ExplorerBeta.UI.Main m_lastNavButtonPressed.colors = oldColors; } - m_lastNavButtonPressed = button; + m_lastNavButtonPressed = button; + } + + #region UI Interaction Callbacks + + private void OnPressHide() + { + ExplorerCore.ShowMenu = false; + } + + private void OnNavButtonPressed(BaseMenuPage page) + { + ExplorerCore.Log($"Pressed '{page.Name}'"); + SetPage(page); } #endregion @@ -131,7 +159,6 @@ namespace ExplorerBeta.UI.Main var hideBtnObj = UIFactory.CreateButton(titleBar); var hideBtn = hideBtnObj.GetComponent