Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 2310f2f

Browse files
committed
Add "Default Tab" config setting instead of "last active tab"
1 parent 2cc403a commit 2310f2f

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

src/Core/Config/ConfigManager.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ public static class ConfigManager
1717
// See the UnityExplorer.Loader namespace for the implementations.
1818
public static ConfigHandler Handler { get; private set; }
1919

20-
public static ConfigElement<KeyCode> Main_Menu_Toggle;
21-
public static ConfigElement<bool> Force_Unlock_Mouse;
22-
public static ConfigElement<int> Default_Page_Limit;
23-
public static ConfigElement<string> Default_Output_Path;
24-
public static ConfigElement<bool> Log_Unity_Debug;
25-
public static ConfigElement<bool> Hide_On_Startup;
26-
27-
public static ConfigElement<string> Last_Window_Anchors;
28-
public static ConfigElement<string> Last_Window_Position;
29-
public static ConfigElement<int> Last_Active_Tab;
30-
public static ConfigElement<bool> Last_DebugConsole_State;
31-
public static ConfigElement<bool> Last_SceneExplorer_State;
20+
public static ConfigElement<KeyCode> Main_Menu_Toggle;
21+
public static ConfigElement<bool> Force_Unlock_Mouse;
22+
public static ConfigElement<MenuPages> Default_Tab;
23+
public static ConfigElement<int> Default_Page_Limit;
24+
public static ConfigElement<string> Default_Output_Path;
25+
public static ConfigElement<bool> Log_Unity_Debug;
26+
public static ConfigElement<bool> Hide_On_Startup;
27+
28+
public static ConfigElement<string> Last_Window_Anchors;
29+
public static ConfigElement<string> Last_Window_Position;
30+
public static ConfigElement<bool> Last_DebugConsole_State;
31+
public static ConfigElement<bool> Last_SceneExplorer_State;
3232

3333
internal static readonly Dictionary<string, IConfigElement> ConfigElements = new Dictionary<string, IConfigElement>();
3434

@@ -44,7 +44,6 @@ public static void Init(ConfigHandler configHandler)
4444
SceneExplorer.OnToggleShow += SceneExplorer_OnToggleShow;
4545
PanelDragger.OnFinishResize += PanelDragger_OnFinishResize;
4646
PanelDragger.OnFinishDrag += PanelDragger_OnFinishDrag;
47-
MainMenu.OnActiveTabChanged += MainMenu_OnActiveTabChanged;
4847
DebugConsole.OnToggleShow += DebugConsole_OnToggleShow;
4948

5049
InitConsoleCallback();
@@ -66,6 +65,10 @@ private static void CreateConfigElements()
6665
"Should UnityExplorer be hidden on startup?",
6766
false);
6867

68+
Default_Tab = new ConfigElement<MenuPages>("Default Tab",
69+
"The default menu page when starting the game.",
70+
MenuPages.Home);
71+
6972
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
7073
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
7174
false);
@@ -94,11 +97,6 @@ private static void CreateConfigElements()
9497
DEFAULT_WINDOW_POSITION,
9598
true);
9699

97-
Last_Active_Tab = new ConfigElement<int>("Last_Active_Tab",
98-
"For internal use, the last active tab index.",
99-
0,
100-
true);
101-
102100
Last_DebugConsole_State = new ConfigElement<bool>("Last_DebugConsole_State",
103101
"For internal use, the collapsed state of the Debug Console.",
104102
true,
@@ -115,18 +113,14 @@ private static void CreateConfigElements()
115113
private static void PanelDragger_OnFinishResize(RectTransform rect)
116114
{
117115
Last_Window_Anchors.Value = rect.RectAnchorsToString();
116+
PanelDragger_OnFinishDrag(rect);
118117
}
119118

120119
private static void PanelDragger_OnFinishDrag(RectTransform rect)
121120
{
122121
Last_Window_Position.Value = rect.RectPositionToString();
123122
}
124123

125-
private static void MainMenu_OnActiveTabChanged(int page)
126-
{
127-
Last_Active_Tab.Value = page;
128-
}
129-
130124
private static void DebugConsole_OnToggleShow(bool showing)
131125
{
132126
Last_DebugConsole_State.Value = showing;

src/UI/Main/Home/HomePage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class HomePage : BaseMenuPage
1313

1414
public static HomePage Instance { get; internal set; }
1515

16+
public override MenuPages Type => MenuPages.Home;
17+
1618
public override bool Init()
1719
{
1820
Instance = this;

src/UI/Main/MainMenu.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class MainMenu
2626
public readonly List<BaseMenuPage> Pages = new List<BaseMenuPage>();
2727
private BaseMenuPage m_activePage;
2828

29-
public static Action<int> OnActiveTabChanged;
29+
public static Action<MenuPages> OnActiveTabChanged;
3030

3131
// Navbar buttons
3232
private Button m_lastNavButtonPressed;
@@ -38,8 +38,6 @@ public class MainMenu
3838
internal bool pageLayoutInit;
3939
internal int layoutInitIndex;
4040

41-
private int origDesiredPage = -1;
42-
4341
public static void Create()
4442
{
4543
if (Instance != null)
@@ -67,6 +65,7 @@ private void Init()
6765

6866
if (!page.Init())
6967
{
68+
page.WasDisabled = true;
7069
// page init failed.
7170
Pages.RemoveAt(i);
7271
i--;
@@ -88,9 +87,6 @@ public void Update()
8887
{
8988
if (!pageLayoutInit)
9089
{
91-
if (origDesiredPage == -1)
92-
origDesiredPage = ConfigManager.Last_Active_Tab?.Value ?? 0;
93-
9490
if (layoutInitIndex < Pages.Count)
9591
{
9692
SetPage(Pages[layoutInitIndex]);
@@ -100,17 +96,26 @@ public void Update()
10096
{
10197
pageLayoutInit = true;
10298
MainPanel.transform.position = initPos;
103-
SetPage(Pages[origDesiredPage]);
99+
100+
SetPage(ConfigManager.Default_Tab.Value);
104101
}
105102
return;
106103
}
107104

108105
m_activePage?.Update();
109106
}
110107

108+
public void SetPage(MenuPages page)
109+
{
110+
var pageObj = Pages.Find(it => it.Type == page);
111+
if (pageObj == null || pageObj.WasDisabled)
112+
return;
113+
SetPage(pageObj);
114+
}
115+
111116
public void SetPage(BaseMenuPage page)
112117
{
113-
if (page == null || m_activePage == page)
118+
if (page == null || m_activePage == page || page.WasDisabled)
114119
return;
115120

116121
m_activePage?.Content?.SetActive(false);
@@ -131,7 +136,7 @@ public void SetPage(BaseMenuPage page)
131136

132137
m_lastNavButtonPressed = button;
133138

134-
OnActiveTabChanged?.Invoke(Pages.IndexOf(m_activePage));
139+
OnActiveTabChanged?.Invoke(m_activePage.Type);
135140
}
136141

137142
internal void SetButtonActiveColors(Button button)

src/UI/Main/Options/OptionsPage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace UnityExplorer.UI.Main.Options
1212
public class OptionsPage : BaseMenuPage
1313
{
1414
public override string Name => "Options";
15+
public override MenuPages Type => MenuPages.Options;
1516

1617
internal static readonly List<CacheConfigEntry> _cachedConfigEntries = new List<CacheConfigEntry>();
1718

src/UI/Main/Search/SearchPage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace UnityExplorer.UI.Main.Search
1717
public class SearchPage : BaseMenuPage
1818
{
1919
public override string Name => "Search";
20+
public override MenuPages Type => MenuPages.Search;
2021

2122
public static SearchPage Instance;
2223

0 commit comments

Comments
 (0)