using System; using System.Collections.Generic; using System.Linq; using System.Text; using ExplorerBeta.UI; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using ExplorerBeta.UI.Shared; using Explorer.UI.Main.Pages; namespace ExplorerBeta.UI.Main { public class MainMenu { public static MainMenu Instance { get; set; } public PanelDragger Dragger { get; private set; } 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); private readonly Color m_navButtonHighlight = new Color(50f/255f, 195f/255f, 50f/255f); private readonly Color m_navButtonSelected = new Color(60f/255f, 120f/255f, 60f/255f); public MainMenu() { if (Instance != null) { ExplorerCore.LogWarning("An instance of MainMenu already exists, cannot create another!"); return; } 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() { // todo } // todo private void SetPage(BaseMenuPage page) { if (m_activePage == page || page == null) return; m_activePage?.Content?.SetActive(false); m_activePage = page; m_activePage.Content?.SetActive(true); var button = page.RefNavbarButton; var colors = button.colors; colors.normalColor = m_navButtonSelected; //try { colors.selectedColor = m_navButtonSelected; } catch { } button.colors = colors; if (m_lastNavButtonPressed && m_lastNavButtonPressed != button) { var oldColors = m_lastNavButtonPressed.colors; oldColors.normalColor = m_navButtonNormal; //try { oldColors.selectedColor = m_navButtonNormal; } catch { } m_lastNavButtonPressed.colors = oldColors; } m_lastNavButtonPressed = button; } #region UI Interaction Callbacks // ... none needed yet #endregion #region UI Construction private void ConstructMenu() { MainPanel = UIFactory.CreatePanel(UIManager.CanvasRoot, "MainMenu", out GameObject content); var panelRect = MainPanel.GetComponent(); panelRect.anchorMin = new Vector2(0.25f, 0.1f); panelRect.anchorMax = new Vector2(0.75f, 0.95f); ConstructTitleBar(content); ConstructNavbar(content); ConstructMainViewport(content); ConstructDebugConsole(content); } private void ConstructDebugConsole(GameObject content) { new DebugConsole(content); } private void ConstructTitleBar(GameObject content) { // Core title bar holder var titleBar = UIFactory.CreateHorizontalGroup(content); var titleGroup = titleBar.GetComponent(); titleGroup.childControlHeight = true; titleGroup.childControlWidth = true; titleGroup.childForceExpandHeight = true; titleGroup.childForceExpandWidth = true; titleGroup.padding.left = 15; titleGroup.padding.right = 3; titleGroup.padding.top = 3; titleGroup.padding.bottom = 3; var titleLayout = titleBar.AddComponent(); titleLayout.minHeight = 35; titleLayout.flexibleHeight = 0; // Explorer label var textObj = UIFactory.CreateLabel(titleBar, TextAnchor.MiddleLeft); var text = textObj.GetComponent(); text.text = $"Explorer v{ExplorerCore.VERSION}"; text.resizeTextForBestFit = true; text.resizeTextMinSize = 12; text.resizeTextMaxSize = 20; var textLayout = textObj.AddComponent(); textLayout.flexibleWidth = 50; // Add PanelDragger using the label object Dragger = new PanelDragger(titleBar.GetComponent(), MainPanel.GetComponent()); // Hide button var hideBtnObj = UIFactory.CreateButton(titleBar); var hideBtn = hideBtnObj.GetComponent