Add "Default Tab" config setting instead of "last active tab"

This commit is contained in:
Sinai 2021-04-07 17:20:42 +10:00
parent 2cc403ad17
commit 2310f2f7ce
5 changed files with 34 additions and 31 deletions

View File

@ -17,18 +17,18 @@ namespace UnityExplorer.Core.Config
// See the UnityExplorer.Loader namespace for the implementations. // See the UnityExplorer.Loader namespace for the implementations.
public static ConfigHandler Handler { get; private set; } public static ConfigHandler Handler { get; private set; }
public static ConfigElement<KeyCode> Main_Menu_Toggle; public static ConfigElement<KeyCode> Main_Menu_Toggle;
public static ConfigElement<bool> Force_Unlock_Mouse; public static ConfigElement<bool> Force_Unlock_Mouse;
public static ConfigElement<int> Default_Page_Limit; public static ConfigElement<MenuPages> Default_Tab;
public static ConfigElement<string> Default_Output_Path; public static ConfigElement<int> Default_Page_Limit;
public static ConfigElement<bool> Log_Unity_Debug; public static ConfigElement<string> Default_Output_Path;
public static ConfigElement<bool> Hide_On_Startup; public static ConfigElement<bool> Log_Unity_Debug;
public static ConfigElement<bool> Hide_On_Startup;
public static ConfigElement<string> Last_Window_Anchors; public static ConfigElement<string> Last_Window_Anchors;
public static ConfigElement<string> Last_Window_Position; public static ConfigElement<string> Last_Window_Position;
public static ConfigElement<int> Last_Active_Tab; public static ConfigElement<bool> Last_DebugConsole_State;
public static ConfigElement<bool> Last_DebugConsole_State; public static ConfigElement<bool> Last_SceneExplorer_State;
public static ConfigElement<bool> Last_SceneExplorer_State;
internal static readonly Dictionary<string, IConfigElement> ConfigElements = new Dictionary<string, IConfigElement>(); internal static readonly Dictionary<string, IConfigElement> ConfigElements = new Dictionary<string, IConfigElement>();
@ -44,7 +44,6 @@ namespace UnityExplorer.Core.Config
SceneExplorer.OnToggleShow += SceneExplorer_OnToggleShow; SceneExplorer.OnToggleShow += SceneExplorer_OnToggleShow;
PanelDragger.OnFinishResize += PanelDragger_OnFinishResize; PanelDragger.OnFinishResize += PanelDragger_OnFinishResize;
PanelDragger.OnFinishDrag += PanelDragger_OnFinishDrag; PanelDragger.OnFinishDrag += PanelDragger_OnFinishDrag;
MainMenu.OnActiveTabChanged += MainMenu_OnActiveTabChanged;
DebugConsole.OnToggleShow += DebugConsole_OnToggleShow; DebugConsole.OnToggleShow += DebugConsole_OnToggleShow;
InitConsoleCallback(); InitConsoleCallback();
@ -66,6 +65,10 @@ namespace UnityExplorer.Core.Config
"Should UnityExplorer be hidden on startup?", "Should UnityExplorer be hidden on startup?",
false); false);
Default_Tab = new ConfigElement<MenuPages>("Default Tab",
"The default menu page when starting the game.",
MenuPages.Home);
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug", Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?", "Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
false); false);
@ -94,11 +97,6 @@ namespace UnityExplorer.Core.Config
DEFAULT_WINDOW_POSITION, DEFAULT_WINDOW_POSITION,
true); true);
Last_Active_Tab = new ConfigElement<int>("Last_Active_Tab",
"For internal use, the last active tab index.",
0,
true);
Last_DebugConsole_State = new ConfigElement<bool>("Last_DebugConsole_State", Last_DebugConsole_State = new ConfigElement<bool>("Last_DebugConsole_State",
"For internal use, the collapsed state of the Debug Console.", "For internal use, the collapsed state of the Debug Console.",
true, true,
@ -115,6 +113,7 @@ namespace UnityExplorer.Core.Config
private static void PanelDragger_OnFinishResize(RectTransform rect) private static void PanelDragger_OnFinishResize(RectTransform rect)
{ {
Last_Window_Anchors.Value = rect.RectAnchorsToString(); Last_Window_Anchors.Value = rect.RectAnchorsToString();
PanelDragger_OnFinishDrag(rect);
} }
private static void PanelDragger_OnFinishDrag(RectTransform rect) private static void PanelDragger_OnFinishDrag(RectTransform rect)
@ -122,11 +121,6 @@ namespace UnityExplorer.Core.Config
Last_Window_Position.Value = rect.RectPositionToString(); Last_Window_Position.Value = rect.RectPositionToString();
} }
private static void MainMenu_OnActiveTabChanged(int page)
{
Last_Active_Tab.Value = page;
}
private static void DebugConsole_OnToggleShow(bool showing) private static void DebugConsole_OnToggleShow(bool showing)
{ {
Last_DebugConsole_State.Value = showing; Last_DebugConsole_State.Value = showing;

View File

@ -13,6 +13,8 @@ namespace UnityExplorer.UI.Main.Home
public static HomePage Instance { get; internal set; } public static HomePage Instance { get; internal set; }
public override MenuPages Type => MenuPages.Home;
public override bool Init() public override bool Init()
{ {
Instance = this; Instance = this;

View File

@ -26,7 +26,7 @@ namespace UnityExplorer.UI.Main
public readonly List<BaseMenuPage> Pages = new List<BaseMenuPage>(); public readonly List<BaseMenuPage> Pages = new List<BaseMenuPage>();
private BaseMenuPage m_activePage; private BaseMenuPage m_activePage;
public static Action<int> OnActiveTabChanged; public static Action<MenuPages> OnActiveTabChanged;
// Navbar buttons // Navbar buttons
private Button m_lastNavButtonPressed; private Button m_lastNavButtonPressed;
@ -38,8 +38,6 @@ namespace UnityExplorer.UI.Main
internal bool pageLayoutInit; internal bool pageLayoutInit;
internal int layoutInitIndex; internal int layoutInitIndex;
private int origDesiredPage = -1;
public static void Create() public static void Create()
{ {
if (Instance != null) if (Instance != null)
@ -67,6 +65,7 @@ namespace UnityExplorer.UI.Main
if (!page.Init()) if (!page.Init())
{ {
page.WasDisabled = true;
// page init failed. // page init failed.
Pages.RemoveAt(i); Pages.RemoveAt(i);
i--; i--;
@ -88,9 +87,6 @@ namespace UnityExplorer.UI.Main
{ {
if (!pageLayoutInit) if (!pageLayoutInit)
{ {
if (origDesiredPage == -1)
origDesiredPage = ConfigManager.Last_Active_Tab?.Value ?? 0;
if (layoutInitIndex < Pages.Count) if (layoutInitIndex < Pages.Count)
{ {
SetPage(Pages[layoutInitIndex]); SetPage(Pages[layoutInitIndex]);
@ -100,7 +96,8 @@ namespace UnityExplorer.UI.Main
{ {
pageLayoutInit = true; pageLayoutInit = true;
MainPanel.transform.position = initPos; MainPanel.transform.position = initPos;
SetPage(Pages[origDesiredPage]);
SetPage(ConfigManager.Default_Tab.Value);
} }
return; return;
} }
@ -108,9 +105,17 @@ namespace UnityExplorer.UI.Main
m_activePage?.Update(); m_activePage?.Update();
} }
public void SetPage(MenuPages page)
{
var pageObj = Pages.Find(it => it.Type == page);
if (pageObj == null || pageObj.WasDisabled)
return;
SetPage(pageObj);
}
public void SetPage(BaseMenuPage page) public void SetPage(BaseMenuPage page)
{ {
if (page == null || m_activePage == page) if (page == null || m_activePage == page || page.WasDisabled)
return; return;
m_activePage?.Content?.SetActive(false); m_activePage?.Content?.SetActive(false);
@ -131,7 +136,7 @@ namespace UnityExplorer.UI.Main
m_lastNavButtonPressed = button; m_lastNavButtonPressed = button;
OnActiveTabChanged?.Invoke(Pages.IndexOf(m_activePage)); OnActiveTabChanged?.Invoke(m_activePage.Type);
} }
internal void SetButtonActiveColors(Button button) internal void SetButtonActiveColors(Button button)

View File

@ -12,6 +12,7 @@ namespace UnityExplorer.UI.Main.Options
public class OptionsPage : BaseMenuPage public class OptionsPage : BaseMenuPage
{ {
public override string Name => "Options"; public override string Name => "Options";
public override MenuPages Type => MenuPages.Options;
internal static readonly List<CacheConfigEntry> _cachedConfigEntries = new List<CacheConfigEntry>(); internal static readonly List<CacheConfigEntry> _cachedConfigEntries = new List<CacheConfigEntry>();

View File

@ -17,6 +17,7 @@ namespace UnityExplorer.UI.Main.Search
public class SearchPage : BaseMenuPage public class SearchPage : BaseMenuPage
{ {
public override string Name => "Search"; public override string Name => "Search";
public override MenuPages Type => MenuPages.Search;
public static SearchPage Instance; public static SearchPage Instance;