Skip to content

Commit ea69c61

Browse files
committed
feat: add portable config mode, relocate toggle, and adjust UI layout
1 parent 05f2b52 commit ea69c61

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

Data/ProfileManager.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Godot;
66
using MegaCrit.Sts2.Core.Logging;
77
using MegaCrit.Sts2.Core.Saves;
8+
using System.Linq;
89

910
namespace BetterModMenu.Data;
1011

@@ -28,10 +29,25 @@ public static class ProfileManager
2829
{
2930
public static readonly MegaCrit.Sts2.Core.Logging.Logger ModLogger = new("BetterModMenu", LogType.Generic);
3031
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };
31-
private static string SavePath
32+
public static string PortableConfigPath
3233
{
3334
get
3435
{
36+
var mod = MegaCrit.Sts2.Core.Modding.ModManager.LoadedMods.FirstOrDefault(m => m.manifest?.id == "BetterModMenu");
37+
string assemblyFolder = (mod != null && !string.IsNullOrEmpty(mod.path))
38+
? mod.path
39+
: (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? "");
40+
return System.IO.Path.Combine(assemblyFolder, "mod_profiles.json");
41+
}
42+
}
43+
44+
public static string SavePath
45+
{
46+
get
47+
{
48+
if (File.Exists(PortableConfigPath))
49+
return PortableConfigPath;
50+
3551
string userPath = UserDataPathProvider.GetAccountScopedBasePath("mod_data/BetterModMenu");
3652
string absolutePath = ProjectSettings.GlobalizePath(userPath);
3753
if (!System.IO.Directory.Exists(absolutePath))

Patches/NModdingScreenPatch.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,35 @@ private static void BuildGroupBar(NModdingScreen __instance, Control? modInfoPan
116116
_groupBar.Position = new Vector2(550, 30);
117117
_groupBar.Size = new Vector2(400, 28);
118118
}
119-
_groupBar.Alignment = BoxContainer.AlignmentMode.End;
119+
_groupBar.Alignment = BoxContainer.AlignmentMode.Begin;
120+
121+
var portableToggle = new CheckButton { Text = "Portable Mode" };
122+
portableToggle.ButtonPressed = System.IO.File.Exists(ProfileManager.PortableConfigPath);
123+
portableToggle.Toggled += (isToggled) => {
124+
if (isToggled) {
125+
try {
126+
if (System.IO.File.Exists(ProfileManager.SavePath) && ProfileManager.SavePath != ProfileManager.PortableConfigPath)
127+
System.IO.File.Copy(ProfileManager.SavePath, ProfileManager.PortableConfigPath, true);
128+
else
129+
ProfileManager.SaveProfiles();
130+
} catch (System.Exception ex) { ProfileManager.ModLogger.Error("Failed to enable portable mode: " + ex); }
131+
} else {
132+
try {
133+
string userPath = UserDataPathProvider.GetAccountScopedBasePath("mod_data/BetterModMenu");
134+
string absolutePath = Godot.ProjectSettings.GlobalizePath(userPath);
135+
if (!System.IO.Directory.Exists(absolutePath)) System.IO.Directory.CreateDirectory(absolutePath);
136+
string target = System.IO.Path.Combine(absolutePath, "mod_profiles.json");
137+
138+
if (System.IO.File.Exists(ProfileManager.PortableConfigPath))
139+
System.IO.File.Copy(ProfileManager.PortableConfigPath, target, true);
140+
141+
System.IO.File.Delete(ProfileManager.PortableConfigPath);
142+
} catch (System.Exception ex) { ProfileManager.ModLogger.Error("Failed to disable portable mode: " + ex); }
143+
}
144+
};
145+
_groupBar.AddChild(portableToggle);
146+
147+
_groupBar.AddChild(new Control { SizeFlagsHorizontal = Control.SizeFlags.ExpandFill });
120148

121149
var groupLabel = new Label { Text = "Group:" };
122150
_groupBar.AddChild(groupLabel);
@@ -285,14 +313,20 @@ private static void BuildGroupHeaders(Control container, Dictionary<string, List
285313
renameBtn.Pressed += () => RenameGroup(grpName);
286314
header.AddChild(renameBtn);
287315

316+
header.AddChild(new Control { CustomMinimumSize = new Vector2(10, 0) });
317+
288318
var upBtn = new Button { Text = "^" };
289319
upBtn.Pressed += () => MoveGroup(grpName, -1);
290320
header.AddChild(upBtn);
291321

322+
header.AddChild(new Control { CustomMinimumSize = new Vector2(10, 0) });
323+
292324
var downBtn = new Button { Text = "v" };
293325
downBtn.Pressed += () => MoveGroup(grpName, 1);
294326
header.AddChild(downBtn);
295327

328+
header.AddChild(new Control { CustomMinimumSize = new Vector2(10, 0) });
329+
296330
var deleteBtn = new Button { Text = "Del" };
297331
deleteBtn.Pressed += () => {
298332
ProfileManager.CustomGroups.Remove(grpName);

0 commit comments

Comments
 (0)