mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
little bit more progress, creating main menu page structure
This commit is contained in:
parent
2da293ab21
commit
76c578a9ea
@ -233,6 +233,11 @@
|
|||||||
<Compile Include="Input\LegacyInput.cs" />
|
<Compile Include="Input\LegacyInput.cs" />
|
||||||
<Compile Include="Input\NoInput.cs" />
|
<Compile Include="Input\NoInput.cs" />
|
||||||
<Compile Include="UI\Main\MainMenu.cs" />
|
<Compile Include="UI\Main\MainMenu.cs" />
|
||||||
|
<Compile Include="UI\Main\Pages\BaseMenuPage.cs" />
|
||||||
|
<Compile Include="UI\Main\Pages\ConsolePage.cs" />
|
||||||
|
<Compile Include="UI\Main\Pages\HomePage.cs" />
|
||||||
|
<Compile Include="UI\Main\Pages\OptionsPage.cs" />
|
||||||
|
<Compile Include="UI\Main\Pages\SearchPage.cs" />
|
||||||
<Compile Include="UI\Main\PanelDragger.cs" />
|
<Compile Include="UI\Main\PanelDragger.cs" />
|
||||||
<Compile Include="UI\InteractiveValue\InteractiveValue.cs" />
|
<Compile Include="UI\InteractiveValue\InteractiveValue.cs" />
|
||||||
<Compile Include="UI\Shared\Syntax.cs" />
|
<Compile Include="UI\Shared\Syntax.cs" />
|
||||||
|
@ -38,7 +38,7 @@ namespace ExplorerBeta
|
|||||||
public static bool m_showMenu;
|
public static bool m_showMenu;
|
||||||
|
|
||||||
private static bool m_doneUIInit;
|
private static bool m_doneUIInit;
|
||||||
private static float m_startupTime;
|
private static float m_timeSinceStartup;
|
||||||
|
|
||||||
public ExplorerCore()
|
public ExplorerCore()
|
||||||
{
|
{
|
||||||
@ -52,10 +52,6 @@ namespace ExplorerBeta
|
|||||||
|
|
||||||
ModConfig.OnLoad();
|
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();
|
InputManager.Init();
|
||||||
ForceUnlockCursor.Init();
|
ForceUnlockCursor.Init();
|
||||||
|
|
||||||
@ -88,13 +84,18 @@ namespace ExplorerBeta
|
|||||||
public static void Update()
|
public static void Update()
|
||||||
{
|
{
|
||||||
// Temporary delay before UIManager.Init
|
// Temporary delay before UIManager.Init
|
||||||
if (!m_doneUIInit && Time.realtimeSinceStartup - m_startupTime > 1f)
|
if (!m_doneUIInit)
|
||||||
|
{
|
||||||
|
m_timeSinceStartup += Time.deltaTime;
|
||||||
|
|
||||||
|
if (m_timeSinceStartup > 1f)
|
||||||
{
|
{
|
||||||
UIManager.Init();
|
UIManager.Init();
|
||||||
|
|
||||||
Log("Initialized Explorer UI.");
|
Log("Initialized Explorer UI.");
|
||||||
m_doneUIInit = true;
|
m_doneUIInit = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
|
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,7 @@ using UnityEngine;
|
|||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using ExplorerBeta.UI.Shared;
|
using ExplorerBeta.UI.Shared;
|
||||||
|
using Explorer.UI.Main.Pages;
|
||||||
|
|
||||||
namespace ExplorerBeta.UI.Main
|
namespace ExplorerBeta.UI.Main
|
||||||
{
|
{
|
||||||
@ -19,6 +20,9 @@ namespace ExplorerBeta.UI.Main
|
|||||||
public GameObject MainPanel { get; private set; }
|
public GameObject MainPanel { get; private set; }
|
||||||
public GameObject PageViewport { get; private set; }
|
public GameObject PageViewport { get; private set; }
|
||||||
|
|
||||||
|
public readonly List<BaseMenuPage> Pages = new List<BaseMenuPage>();
|
||||||
|
private BaseMenuPage m_activePage;
|
||||||
|
|
||||||
// Navbar buttons
|
// Navbar buttons
|
||||||
private Button m_lastNavButtonPressed;
|
private Button m_lastNavButtonPressed;
|
||||||
private readonly Color m_navButtonNormal = new Color(65f/255f, 66f/255f, 66f/255f);
|
private readonly Color m_navButtonNormal = new Color(65f/255f, 66f/255f, 66f/255f);
|
||||||
@ -35,7 +39,19 @@ namespace ExplorerBeta.UI.Main
|
|||||||
|
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
|
||||||
|
Pages.Add(new HomePage());
|
||||||
|
Pages.Add(new SearchPage());
|
||||||
|
Pages.Add(new ConsolePage());
|
||||||
|
Pages.Add(new OptionsPage());
|
||||||
|
|
||||||
ConstructMenu();
|
ConstructMenu();
|
||||||
|
|
||||||
|
foreach (var page in Pages)
|
||||||
|
{
|
||||||
|
page.Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPage(Pages[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
@ -43,16 +59,15 @@ namespace ExplorerBeta.UI.Main
|
|||||||
// todo
|
// todo
|
||||||
}
|
}
|
||||||
|
|
||||||
#region UI Interaction Callbacks
|
// todo
|
||||||
|
private void SetPage(BaseMenuPage page)
|
||||||
private void OnPressHide()
|
|
||||||
{
|
{
|
||||||
ExplorerCore.ShowMenu = false;
|
if (m_activePage == page || page == null)
|
||||||
}
|
return;
|
||||||
|
|
||||||
private void OnNavButtonPressed(string pageName, Button button)
|
m_activePage = page;
|
||||||
{
|
|
||||||
ExplorerCore.Log($"Pressed '{pageName}'");
|
var button = page.RefNavbarButton;
|
||||||
|
|
||||||
var colors = button.colors;
|
var colors = button.colors;
|
||||||
colors.normalColor = m_navButtonSelected;
|
colors.normalColor = m_navButtonSelected;
|
||||||
@ -70,6 +85,19 @@ namespace ExplorerBeta.UI.Main
|
|||||||
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
|
#endregion
|
||||||
|
|
||||||
#region UI Construction
|
#region UI Construction
|
||||||
@ -131,7 +159,6 @@ namespace ExplorerBeta.UI.Main
|
|||||||
var hideBtnObj = UIFactory.CreateButton(titleBar);
|
var hideBtnObj = UIFactory.CreateButton(titleBar);
|
||||||
|
|
||||||
var hideBtn = hideBtnObj.GetComponent<Button>();
|
var hideBtn = hideBtnObj.GetComponent<Button>();
|
||||||
hideBtn.onClick = new Button.ButtonClickedEvent();
|
|
||||||
hideBtn.onClick.AddListener(new Action(OnPressHide));
|
hideBtn.onClick.AddListener(new Action(OnPressHide));
|
||||||
var colorBlock = hideBtn.colors;
|
var colorBlock = hideBtn.colors;
|
||||||
colorBlock.normalColor = new Color(65f/255f, 23f/255f, 23f/255f);
|
colorBlock.normalColor = new Color(65f/255f, 23f/255f, 23f/255f);
|
||||||
@ -173,31 +200,21 @@ namespace ExplorerBeta.UI.Main
|
|||||||
navLayout.minHeight = 35;
|
navLayout.minHeight = 35;
|
||||||
navLayout.flexibleHeight = 0;
|
navLayout.flexibleHeight = 0;
|
||||||
|
|
||||||
// todo use page enum instead
|
foreach (var page in Pages)
|
||||||
var names = new string[] { "Home", "Search", "C# Console", "Options/Misc" };
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
{
|
||||||
var btnObj = UIFactory.CreateButton(navbarObj);
|
var btnObj = UIFactory.CreateButton(navbarObj);
|
||||||
var btn = btnObj.GetComponent<Button>();
|
var btn = btnObj.GetComponent<Button>();
|
||||||
|
|
||||||
var name = names[i];
|
page.RefNavbarButton = btn;
|
||||||
|
|
||||||
btn.onClick.AddListener(new Action(() => { OnNavButtonPressed(name, btn); }));
|
btn.onClick.AddListener(new Action(() => { OnNavButtonPressed(page); }));
|
||||||
|
|
||||||
var text = btnObj.GetComponentInChildren<Text>();
|
var text = btnObj.GetComponentInChildren<Text>();
|
||||||
text.text = name;
|
text.text = page.Name;
|
||||||
|
|
||||||
// Set button colors
|
// Set button colors
|
||||||
var colorBlock = btn.colors;
|
var colorBlock = btn.colors;
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
colorBlock.normalColor = m_navButtonSelected;
|
|
||||||
m_lastNavButtonPressed = btn;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
colorBlock.normalColor = m_navButtonNormal;
|
colorBlock.normalColor = m_navButtonNormal;
|
||||||
}
|
|
||||||
colorBlock.selectedColor = colorBlock.normalColor;
|
colorBlock.selectedColor = colorBlock.normalColor;
|
||||||
colorBlock.highlightedColor = m_navButtonHighlight;
|
colorBlock.highlightedColor = m_navButtonHighlight;
|
||||||
colorBlock.pressedColor = m_navButtonSelected;
|
colorBlock.pressedColor = m_navButtonSelected;
|
||||||
|
27
src/UI/Main/Pages/BaseMenuPage.cs
Normal file
27
src/UI/Main/Pages/BaseMenuPage.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace Explorer.UI.Main.Pages
|
||||||
|
{
|
||||||
|
public abstract class BaseMenuPage
|
||||||
|
{
|
||||||
|
public abstract string Name { get; }
|
||||||
|
|
||||||
|
public GameObject Content;
|
||||||
|
public Button RefNavbarButton { get; set; }
|
||||||
|
|
||||||
|
public bool Enabled
|
||||||
|
{
|
||||||
|
get => Content?.activeSelf ?? false;
|
||||||
|
set => Content?.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract void Init();
|
||||||
|
public abstract void Update();
|
||||||
|
}
|
||||||
|
}
|
22
src/UI/Main/Pages/ConsolePage.cs
Normal file
22
src/UI/Main/Pages/ConsolePage.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Explorer.UI.Main.Pages
|
||||||
|
{
|
||||||
|
public class ConsolePage : BaseMenuPage
|
||||||
|
{
|
||||||
|
public override string Name => "C# Console";
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
75
src/UI/Main/Pages/HomePage.cs
Normal file
75
src/UI/Main/Pages/HomePage.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using ExplorerBeta.UI;
|
||||||
|
using ExplorerBeta.UI.Main;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace Explorer.UI.Main.Pages
|
||||||
|
{
|
||||||
|
public class HomePage : BaseMenuPage
|
||||||
|
{
|
||||||
|
public override string Name => "Home";
|
||||||
|
|
||||||
|
private GameObject m_mainViewport;
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
ConstructMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#region UI Construction
|
||||||
|
|
||||||
|
private void ConstructMenu()
|
||||||
|
{
|
||||||
|
var parent = MainMenu.Instance.PageViewport;
|
||||||
|
|
||||||
|
m_mainViewport = UIFactory.CreateHorizontalGroup(parent);
|
||||||
|
var mainGroup = m_mainViewport.GetComponent<HorizontalLayoutGroup>();
|
||||||
|
mainGroup.padding.left = 3;
|
||||||
|
mainGroup.padding.right = 3;
|
||||||
|
mainGroup.padding.top = 3;
|
||||||
|
mainGroup.padding.bottom = 3;
|
||||||
|
mainGroup.spacing = 5;
|
||||||
|
mainGroup.childForceExpandHeight = true;
|
||||||
|
mainGroup.childForceExpandWidth = true;
|
||||||
|
mainGroup.childControlHeight = true;
|
||||||
|
mainGroup.childControlWidth = true;
|
||||||
|
|
||||||
|
var leftPaneObj = UIFactory.CreateVerticalGroup(m_mainViewport, new Color(72f / 255f, 72f / 255f, 72f / 255f));
|
||||||
|
var leftLayout = leftPaneObj.AddComponent<LayoutElement>();
|
||||||
|
leftLayout.minWidth = 350;
|
||||||
|
leftLayout.flexibleWidth = 0;
|
||||||
|
|
||||||
|
var leftGroup = leftPaneObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
leftGroup.padding.left = 8;
|
||||||
|
leftGroup.padding.right = 8;
|
||||||
|
leftGroup.padding.top = 8;
|
||||||
|
leftGroup.padding.bottom = 8;
|
||||||
|
leftGroup.spacing = 5;
|
||||||
|
leftGroup.childControlWidth = true;
|
||||||
|
leftGroup.childControlHeight = true;
|
||||||
|
leftGroup.childForceExpandWidth = false;
|
||||||
|
leftGroup.childForceExpandHeight = true;
|
||||||
|
|
||||||
|
var rightPaneObj = UIFactory.CreateVerticalGroup(m_mainViewport, new Color(72f / 255f, 72f / 255f, 72f / 255f));
|
||||||
|
var rightLayout = rightPaneObj.AddComponent<LayoutElement>();
|
||||||
|
rightLayout.flexibleWidth = 999999;
|
||||||
|
|
||||||
|
var rightGroup = rightPaneObj.GetComponent<VerticalLayoutGroup>();
|
||||||
|
rightGroup.childForceExpandHeight = true;
|
||||||
|
rightGroup.childForceExpandWidth = true;
|
||||||
|
rightGroup.childControlHeight = true;
|
||||||
|
rightGroup.childControlWidth = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
22
src/UI/Main/Pages/OptionsPage.cs
Normal file
22
src/UI/Main/Pages/OptionsPage.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Explorer.UI.Main.Pages
|
||||||
|
{
|
||||||
|
public class OptionsPage : BaseMenuPage
|
||||||
|
{
|
||||||
|
public override string Name => "Options / Misc";
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
src/UI/Main/Pages/SearchPage.cs
Normal file
22
src/UI/Main/Pages/SearchPage.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Explorer.UI.Main.Pages
|
||||||
|
{
|
||||||
|
public class SearchPage : BaseMenuPage
|
||||||
|
{
|
||||||
|
public override string Name => "Search";
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user