UnityExplorer/src/UI/MainMenu.cs

126 lines
3.8 KiB
C#
Raw Normal View History

2020-08-07 22:19:03 +10:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
2020-10-08 06:15:42 +11:00
using Explorer.Config;
using Explorer.UI.Main;
using Explorer.UI.Shared;
using Explorer.UI.Inspectors;
2020-08-07 22:19:03 +10:00
2020-10-08 06:15:42 +11:00
namespace Explorer.UI
2020-08-07 22:19:03 +10:00
{
public class MainMenu
{
public static MainMenu Instance;
public MainMenu()
{
Instance = this;
Pages.Add(new ScenePage());
Pages.Add(new SearchPage());
2020-08-07 23:45:09 +10:00
Pages.Add(new ConsolePage());
Pages.Add(new OptionsPage());
2020-08-07 22:19:03 +10:00
for (int i = 0; i < Pages.Count; i++)
2020-08-07 22:19:03 +10:00
{
var page = Pages[i];
2020-08-07 22:19:03 +10:00
page.Init();
// If page failed to init, it will remove itself from the list. Lower the iterate counter.
if (!Pages.Contains(page)) i--;
2020-08-07 22:19:03 +10:00
}
}
public const int MainWindowID = 5000;
public static Rect MainRect = new Rect(5, 5, ModConfig.Instance.Default_Window_Size.x, ModConfig.Instance.Default_Window_Size.y);
2020-10-08 06:15:42 +11:00
public static readonly List<BaseMainMenuPage> Pages = new List<BaseMainMenuPage>();
2020-08-07 22:19:03 +10:00
private static int m_currentPage = 0;
public static void SetCurrentPage(int index)
{
if (index < 0 || Pages.Count <= index)
{
ExplorerCore.Log("cannot set page " + index);
2020-08-07 22:19:03 +10:00
return;
}
m_currentPage = index;
GUIHelper.BringWindowToFront(MainWindowID);
2020-08-07 22:19:03 +10:00
GUI.FocusWindow(MainWindowID);
}
public void Update()
{
Pages[m_currentPage].Update();
}
public void OnGUI()
{
MainRect = GUIHelper.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, ExplorerCore.NAME);
2020-08-07 22:19:03 +10:00
}
private void MainWindow(int id)
{
GUI.DragWindow(new Rect(0, 0, MainRect.width - 90, 20));
if (GUIHelper.Button(new Rect(MainRect.width - 90, 2, 80, 20), $"Hide ({ModConfig.Instance.Main_Menu_Toggle})"))
2020-08-07 22:19:03 +10:00
{
ExplorerCore.ShowMenu = false;
2020-08-07 22:19:03 +10:00
return;
}
GUIHelper.BeginArea(new Rect(5, 25, MainRect.width - 10, MainRect.height - 35), GUI.skin.box);
2020-08-07 22:19:03 +10:00
MainHeader();
var page = Pages[m_currentPage];
page.scroll = GUIHelper.BeginScrollView(page.scroll);
2020-08-07 22:19:03 +10:00
page.DrawWindow();
GUIHelper.EndScrollView();
2020-08-07 22:19:03 +10:00
MainRect = ResizeDrag.ResizeWindow(MainRect, MainWindowID);
2020-08-07 22:19:03 +10:00
GUIHelper.EndArea();
2020-08-07 22:19:03 +10:00
}
private void MainHeader()
{
GUIHelper.BeginHorizontal(new GUILayoutOption[0]);
2020-08-07 22:19:03 +10:00
for (int i = 0; i < Pages.Count; i++)
{
if (m_currentPage == i)
GUI.color = Color.green;
else
GUI.color = Color.white;
if (GUILayout.Button(Pages[i].Name, new GUILayoutOption[0]))
2020-08-07 22:19:03 +10:00
{
m_currentPage = i;
}
}
GUILayout.EndHorizontal();
2020-08-07 22:19:03 +10:00
GUIHelper.BeginHorizontal(new GUILayoutOption[0]);
GUI.color = Color.white;
InspectUnderMouse.EnableInspect = GUILayout.Toggle(InspectUnderMouse.EnableInspect, "Inspect Under Mouse (Shift + RMB)", new GUILayoutOption[0]);
2020-10-08 06:15:42 +11:00
bool mouseState = ForceUnlockCursor.Unlock;
bool setMouse = GUILayout.Toggle(mouseState, "Force Unlock Mouse (Left Alt)", new GUILayoutOption[0]);
2020-10-08 06:15:42 +11:00
if (setMouse != mouseState) ForceUnlockCursor.Unlock = setMouse;
2020-10-08 06:15:42 +11:00
//WindowManager.TabView = GUILayout.Toggle(WindowManager.TabView, "Tab View", new GUILayoutOption[0]);
GUILayout.EndHorizontal();
//GUIUnstrip.Space(10);
GUIHelper.Space(10);
2020-08-07 22:19:03 +10:00
GUI.color = Color.white;
}
}
}