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; 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 MainMenu() { if (Instance != null) { ExplorerCore.LogWarning("An instance of MainMenu already exists, cannot create another!"); return; } Instance = this; MainPanel = CreateBasePanel("MainMenu"); CreateTitleBar(); CreateNavbar(); CreateViewArea(); } public void Update() { } private void TestButtonCallback() { //if (EventSystem.current != EventSys) // return; var go = EventSystem.current.currentSelectedGameObject; if (!go) return; var name = go.name; if (go.GetComponentInChildren() is Text text) { name = text.text; } ExplorerCore.Log($"{Time.time} | Pressed {name ?? "null"}"); if (name == "X") { ExplorerCore.ShowMenu = false; } } #region UI Generator public virtual GameObject CreateBasePanel(string name) { var basePanel = UIFactory.CreatePanel(UIManager.CanvasRoot.gameObject, name); var panelRect = basePanel.GetComponent(); panelRect.anchorMin = new Vector2(0.327f, 0.0967f); panelRect.anchorMax = new Vector2(0.672f, 0.904f); panelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 620f); panelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 800f); return basePanel; } private void CreateTitleBar() { // Make the horizontal group for window title area var titleGroup = UIFactory.CreateHorizontalGroup(MainPanel); var titleRect = titleGroup.GetComponent(); titleRect.anchorMin = new Vector2(0.005f, 0.96f); titleRect.anchorMax = new Vector2(0.995f, 0.994f); titleRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 613); titleRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 30); var group = titleGroup.GetComponent(); group.childControlWidth = true; //group.childScaleWidth = true; group.childForceExpandHeight = true; group.childForceExpandWidth = true; // Create window title var titleLabel = UIFactory.CreateLabel(titleGroup, TextAnchor.MiddleCenter); var labelText = titleLabel.GetComponent(); labelText.text = ExplorerCore.NAME; labelText.fontSize = 15; var labelRect = labelText.GetComponent(); labelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 575); labelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25); // Add drag handler (on Title label) Dragger = new PanelDragger(titleLabel.transform.TryCast(), MainPanel.GetComponent()); // Create X Button var exitBtnObj = UIFactory.CreateButton(titleGroup); var exitBtn = exitBtnObj.GetComponentInChildren