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

Commit 9072b16

Browse files
committed
Save window size between launches
1 parent 2140899 commit 9072b16

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

src/Config/ExplorerConfig.cs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using IniParser;
55
using IniParser.Parser;
6+
using UnityExplorer.UI;
67

78
namespace UnityExplorer.Config
89
{
@@ -16,16 +17,20 @@ public class ExplorerConfig
1617
static ExplorerConfig()
1718
{
1819
_parser.Configuration.CommentString = "#";
20+
21+
PanelDragger.OnFinishResize += PanelDragger_OnFinishResize;
1922
}
2023

2124
// Actual configs
2225
public KeyCode Main_Menu_Toggle = KeyCode.F7;
2326
public bool Force_Unlock_Mouse = true;
2427
public int Default_Page_Limit = 25;
25-
public string Default_Output_Path = ExplorerCore.ExplorerFolder + @"\Output";
28+
public string Default_Output_Path = Path.Combine(ExplorerCore.ExplorerFolder, "Output");
2629
public bool Log_Unity_Debug = false;
2730
public bool Hide_On_Startup = false;
28-
//public bool Save_Logs_To_Disk = true;
31+
public string Window_Anchors = DEFAULT_WINDOW_ANCHORS;
32+
33+
private const string DEFAULT_WINDOW_ANCHORS = "0.25,0.1,0.78,0.95";
2934

3035
public static event Action OnConfigChanged;
3136

@@ -75,9 +80,9 @@ public static bool LoadSettings()
7580
case nameof(Hide_On_Startup):
7681
Instance.Hide_On_Startup = bool.Parse(config.Value);
7782
break;
78-
//case nameof(Save_Logs_To_Disk):
79-
// Instance.Save_Logs_To_Disk = bool.Parse(config.Value);
80-
// break;
83+
case nameof(Window_Anchors):
84+
Instance.Window_Anchors = config.Value;
85+
break;
8186
}
8287
}
8388

@@ -97,12 +102,52 @@ public static void SaveSettings()
97102
sec.AddKey(nameof(Log_Unity_Debug), Instance.Log_Unity_Debug.ToString());
98103
sec.AddKey(nameof(Default_Output_Path), Instance.Default_Output_Path);
99104
sec.AddKey(nameof(Hide_On_Startup), Instance.Hide_On_Startup.ToString());
100-
//sec.AddKey("Save_Logs_To_Disk", Instance.Save_Logs_To_Disk.ToString());
105+
sec.AddKey(nameof(Window_Anchors), GetWindowAnchorsString());
101106

102107
if (!Directory.Exists(ExplorerCore.Loader.ConfigFolder))
103108
Directory.CreateDirectory(ExplorerCore.Loader.ConfigFolder);
104109

105110
File.WriteAllText(INI_PATH, data.ToString());
106111
}
112+
113+
// ============ Window Anchors specific stuff ============== //
114+
115+
private static void PanelDragger_OnFinishResize()
116+
{
117+
Instance.Window_Anchors = GetWindowAnchorsString();
118+
SaveSettings();
119+
}
120+
121+
internal Vector4 GetWindowAnchorsVector()
122+
{
123+
try
124+
{
125+
var split = Window_Anchors.Split(',');
126+
Vector4 ret = Vector4.zero;
127+
ret.x = float.Parse(split[0]);
128+
ret.y = float.Parse(split[1]);
129+
ret.z = float.Parse(split[2]);
130+
ret.w = float.Parse(split[3]);
131+
return ret;
132+
}
133+
catch
134+
{
135+
Window_Anchors = DEFAULT_WINDOW_ANCHORS;
136+
return GetWindowAnchorsVector();
137+
}
138+
}
139+
140+
internal static string GetWindowAnchorsString()
141+
{
142+
try
143+
{
144+
var rect = PanelDragger.Instance.Panel;
145+
return $"{rect.anchorMin.x},{rect.anchorMin.y},{rect.anchorMax.x},{rect.anchorMax.y}";
146+
}
147+
catch
148+
{
149+
return DEFAULT_WINDOW_ANCHORS;
150+
}
151+
}
107152
}
108153
}

src/UI/MainMenu.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,11 @@ private void ConstructMenu()
155155
MainPanel = UIFactory.CreatePanel(UIManager.CanvasRoot, "MainMenu", out GameObject content);
156156

157157
RectTransform panelRect = MainPanel.GetComponent<RectTransform>();
158-
panelRect.anchorMin = new Vector2(0.25f, 0.1f);
159-
panelRect.anchorMax = new Vector2(0.78f, 0.95f);
158+
//panelRect.anchorMin = new Vector2(0.25f, 0.1f);
159+
//panelRect.anchorMax = new Vector2(0.78f, 0.95f);
160+
var anchors = ExplorerConfig.Instance.GetWindowAnchorsVector();
161+
panelRect.anchorMin = new Vector2(anchors.x, anchors.y);
162+
panelRect.anchorMax = new Vector2(anchors.z, anchors.w);
160163

161164
MainPanel.AddComponent<Mask>();
162165

0 commit comments

Comments
 (0)