little bit more progress, creating main menu page structure

This commit is contained in:
sinaioutlander 2020-10-23 20:40:44 +11:00
parent 2da293ab21
commit 76c578a9ea
8 changed files with 225 additions and 34 deletions

View File

@ -233,6 +233,11 @@
<Compile Include="Input\LegacyInput.cs" />
<Compile Include="Input\NoInput.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\InteractiveValue\InteractiveValue.cs" />
<Compile Include="UI\Shared\Syntax.cs" />

View File

@ -38,7 +38,7 @@ namespace ExplorerBeta
public static bool m_showMenu;
private static bool m_doneUIInit;
private static float m_startupTime;
private static float m_timeSinceStartup;
public ExplorerCore()
{
@ -52,10 +52,6 @@ namespace ExplorerBeta
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();
ForceUnlockCursor.Init();
@ -88,12 +84,17 @@ namespace ExplorerBeta
public static void Update()
{
// Temporary delay before UIManager.Init
if (!m_doneUIInit && Time.realtimeSinceStartup - m_startupTime > 1f)
if (!m_doneUIInit)
{
UIManager.Init();
m_timeSinceStartup += Time.deltaTime;
Log("Initialized Explorer UI.");
m_doneUIInit = true;
if (m_timeSinceStartup > 1f)
{
UIManager.Init();
Log("Initialized Explorer UI.");
m_doneUIInit = true;
}
}
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))

View File

@ -7,6 +7,7 @@ using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using ExplorerBeta.UI.Shared;
using Explorer.UI.Main.Pages;
namespace ExplorerBeta.UI.Main
{
@ -19,6 +20,9 @@ namespace ExplorerBeta.UI.Main
public GameObject MainPanel { get; private set; }
public GameObject PageViewport { get; private set; }
public readonly List<BaseMenuPage> Pages = new List<BaseMenuPage>();
private BaseMenuPage m_activePage;
// Navbar buttons
private Button m_lastNavButtonPressed;
private readonly Color m_navButtonNormal = new Color(65f/255f, 66f/255f, 66f/255f);
@ -35,7 +39,19 @@ namespace ExplorerBeta.UI.Main
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()
@ -43,16 +59,15 @@ namespace ExplorerBeta.UI.Main
// todo
}
#region UI Interaction Callbacks
private void OnPressHide()
// todo
private void SetPage(BaseMenuPage page)
{
ExplorerCore.ShowMenu = false;
}
if (m_activePage == page || page == null)
return;
private void OnNavButtonPressed(string pageName, Button button)
{
ExplorerCore.Log($"Pressed '{pageName}'");
m_activePage = page;
var button = page.RefNavbarButton;
var colors = button.colors;
colors.normalColor = m_navButtonSelected;
@ -67,7 +82,20 @@ namespace ExplorerBeta.UI.Main
m_lastNavButtonPressed.colors = oldColors;
}
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
@ -131,7 +159,6 @@ namespace ExplorerBeta.UI.Main
var hideBtnObj = UIFactory.CreateButton(titleBar);
var hideBtn = hideBtnObj.GetComponent<Button>();
hideBtn.onClick = new Button.ButtonClickedEvent();
hideBtn.onClick.AddListener(new Action(OnPressHide));
var colorBlock = hideBtn.colors;
colorBlock.normalColor = new Color(65f/255f, 23f/255f, 23f/255f);
@ -173,31 +200,21 @@ namespace ExplorerBeta.UI.Main
navLayout.minHeight = 35;
navLayout.flexibleHeight = 0;
// todo use page enum instead
var names = new string[] { "Home", "Search", "C# Console", "Options/Misc" };
for (int i = 0; i < 4; i++)
foreach (var page in Pages)
{
var btnObj = UIFactory.CreateButton(navbarObj);
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>();
text.text = name;
text.text = page.Name;
// Set button 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.highlightedColor = m_navButtonHighlight;
colorBlock.pressedColor = m_navButtonSelected;

View 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();
}
}

View 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()
{
}
}
}

View 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
}
}

View 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()
{
}
}
}

View 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()
{
}
}
}