From 2da293ab21c45e410fe393d7c1f782db26c949d6 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Fri, 23 Oct 2020 19:55:02 +1100 Subject: [PATCH] A bit more progress, got a good framework for the UI going now. --- src/ExplorerCore.cs | 4 +- src/UI/Main/MainMenu.cs | 286 +++++++++++++++++++++--------------- src/UI/Main/PanelDragger.cs | 65 +++----- src/UI/UIFactory.cs | 127 ++++++++++------ src/UI/UIManager.cs | 8 +- 5 files changed, 275 insertions(+), 215 deletions(-) diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 3824aa6..346690b 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -1,10 +1,10 @@ -using System.Collections; +using System; +using System.Collections; using System.Linq; using ExplorerBeta.Config; using ExplorerBeta.Input; using ExplorerBeta.UI; using UnityEngine; -using UnityEngine.EventSystems; namespace ExplorerBeta { diff --git a/src/UI/Main/MainMenu.cs b/src/UI/Main/MainMenu.cs index 55bcbaf..96162fb 100644 --- a/src/UI/Main/MainMenu.cs +++ b/src/UI/Main/MainMenu.cs @@ -10,14 +10,20 @@ using ExplorerBeta.UI.Shared; namespace ExplorerBeta.UI.Main { - // TODO REMAKE THIS - 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; } + + // 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() { @@ -29,150 +35,186 @@ namespace ExplorerBeta.UI.Main Instance = this; - MainPanel = CreateBasePanel("MainMenu"); - CreateTitleBar(); - CreateNavbar(); - CreateViewArea(); + ConstructMenu(); } public void Update() { - + // todo } - private void TestButtonCallback() + #region UI Interaction Callbacks + + private void OnPressHide() { - //if (EventSystem.current != EventSys) - // return; + ExplorerCore.ShowMenu = false; + } - var go = EventSystem.current.currentSelectedGameObject; - if (!go) - return; + private void OnNavButtonPressed(string pageName, Button button) + { + ExplorerCore.Log($"Pressed '{pageName}'"); - var name = go.name; - if (go.GetComponentInChildren() is Text text) + var colors = button.colors; + colors.normalColor = m_navButtonSelected; + colors.selectedColor = m_navButtonSelected; + button.colors = colors; + + if (m_lastNavButtonPressed && m_lastNavButtonPressed != button) { - name = text.text; + var oldColors = m_lastNavButtonPressed.colors; + oldColors.normalColor = m_navButtonNormal; + oldColors.selectedColor = m_navButtonNormal; + m_lastNavButtonPressed.colors = oldColors; } - ExplorerCore.Log($"{Time.time} | Pressed {name ?? "null"}"); - if (name == "X") + m_lastNavButtonPressed = button; + } + + #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); + } + + 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