Skip to content

Commit d931d9d

Browse files
committed
Update UI.
1 parent 113b968 commit d931d9d

8 files changed

Lines changed: 50 additions & 32 deletions

File tree

000-ModManager/Config/Localization.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ xuiModsSortAlphanumerical,UI,XUI,x,,"Alphanumerical"
4747
xuiModsSortLoadOrder,UI,XUI,x,,"Load Order"
4848
xuiModsSortAuthor,UI,XUI,x,,"Author"
4949
xuiModsSortUndefined,UI,XUI,x,,"Undefined"
50+
xuiModsRefresh,UI,XUI,x,,"Refresh Mod List"
5051
xuiModsListStateVanilla,UI,XUI,x,,"This is an unmodded game."
5152
xuiModsListStateModded,UI,XUI,x,,"This is a modded game.\n\nMods Used:\n{0}"
5253
xuiModsListStateUnknown,UI,XUI,x,,"This game hasn't been opened with Mod Manager before."

000-ModManager/Config/XUi_Menu/windows.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<textfield name="searchInput" depth="5" pos="40,-22" width="250" height="30" pivot="Left" search_field="true" />
3030

3131
<button name="btnSort" depth="3" pos="384,-22" sprite="ui_game_symbol_sort" style="icon32px, press, hover" pivot="center" tooltip="{sortingTooltip}"/>
32+
<button name="btnRefresh" depth="3" pos="420,-22" sprite="server_refresh" style="icon32px, press, hover" pivot="center" tooltip="{refreshTooltip}"/>
3233

3334
<panel pos="478,0" width="98" height="43" disableautobackground="true">
3435
<pager name="pager" pos="1,-6" />
@@ -59,7 +60,7 @@
5960
<rect name="modInfo" tab_key="xuiModInformation" controller="CustomModManager.UI.XUiC_ModsListModInfo, ModManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
6061
<label name="Name" depth="4" pos="6,-6" width="414" height="32" font_size="32" text="{modName}"/>
6162
<label name="Author" depth="4" pos="6,-43" width="200" height="32" font_size="26" color="255,255,255,128" text="{modAuthor}"/>
62-
<label name="Version" depth="4" pos="505,-6" width="80" height="32" font_size="26" justify="right" text="{modVersion}"/>
63+
<label name="Version" depth="4" pos="383,-6" width="202" height="32" font_size="26" justify="right" text="{modVersion}"/>
6364
<label name="Description" depth="4" pos="6,-80" width="584" height="300" font_size="26" text="{modDescription}"/>
6465

6566
<togglebutton name="enableDisableButton" depth="4" pos="6,-570" width="120" height="36" font_size="32" caption_key="xuiModEnabled"/>

Source/Mod/Mod.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ public IModVersion Version
2020
private bool stateSwapFlag;
2121
private EModDisableState modDisableState;
2222

23-
public bool Enabled
24-
{
25-
get
26-
{
27-
return true;
28-
}
29-
}
30-
3123
public bool Loaded
3224
{
3325
get
@@ -107,7 +99,10 @@ public void ToggleNextState()
10799
public bool Load()
108100
{
109101
if (this.instance == null)
102+
{
110103
this.instance = global::Mod.LoadFromFolder(this.Info.Path);
104+
ThreadManager.RunCoroutineSync(ModManager.LoadPatchStuff(false));
105+
}
111106

112107
if (this.stateSwapFlag)
113108
this.stateSwapFlag = false;

Source/Mod/ModLoader.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ public bool SaveModChanges()
119119

120120
foreach(var mod in this.GetMods(false))
121121
{
122-
if(mod.WillChangeState)
122+
flag |= (mod.WillChangeState && mod.Loaded);
123+
124+
if (mod.WillChangeState)
123125
{
124126
if (mod.NextState)
125127
{
@@ -129,9 +131,12 @@ public bool SaveModChanges()
129131
else if(!lines.Contains(mod.Info.Name))
130132
{
131133
lines.Add(Path.GetFileName(mod.Info.Name));
132-
flag |= true;
133134
}
134135
}
136+
else
137+
{
138+
lines.RemoveAll(modName => mod.Info.Name.EqualsCaseInsensitive(modName));
139+
}
135140
}
136141

137142
if (lines.Count > 0)

Source/ModManager.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
</Reference>
6262
</ItemGroup>
6363
<ItemGroup>
64-
<Compile Include="..\API\ModManagerAPI.cs" />
64+
<Compile Include="..\API\ModManagerAPI.cs">
65+
<Link>ModManagerAPI.cs</Link>
66+
</Compile>
6567
<Compile Include="API\IModSetting.cs" />
6668
<Compile Include="API\IModSettings.cs" />
6769
<Compile Include="Mod\ModErrorLogger.cs" />

Source/ModManagerMod.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ModManagerMod : IModApi
1919
private ModManagerAPI.ModSettings.ModSetting<int> currentModDirSetting;
2020
private ModManagerAPI.ModSettings.ModSetting<string> openModDirButton;
2121

22-
private readonly ISet<string> modPaths = new HashSet<string>();
22+
internal static readonly ISet<string> modPaths = new HashSet<string>();
2323
private int selectedModDir;
2424

2525
private bool showPatchNotesOnStartup = true, showUpdatesOnStartup = true;
@@ -38,10 +38,10 @@ public ModManagerMod()
3838
private void AddBasePaths()
3939
{
4040
if (MODS_BASE_PATH_LEGACY_FIELD != null)
41-
this.modPaths.Add((string)MODS_BASE_PATH_LEGACY_FIELD.GetValue(null));
41+
modPaths.Add((string)MODS_BASE_PATH_LEGACY_FIELD.GetValue(null));
4242

4343
if (MODS_BASE_PATH_PROPERTY != null)
44-
this.modPaths.Add((string)MODS_BASE_PATH_PROPERTY.GetValue(null));
44+
modPaths.Add((string)MODS_BASE_PATH_PROPERTY.GetValue(null));
4545
}
4646

4747
public void InitMod(global::Mod _modInstance)
@@ -61,14 +61,14 @@ private void InitSettings(ModManagerAPI.ModSettings settings)
6161
{
6262
List<string> paths = value.Split(';').ToList();
6363

64-
this.modPaths.Clear();
64+
modPaths.Clear();
6565

6666
this.AddBasePaths();
6767
foreach (var path in paths)
6868
{
69-
this.modPaths.Add(path);
69+
modPaths.Add(path);
7070
}
71-
this.loader.Load(this.modPaths.ToArray());
71+
this.loader.Load(modPaths.ToArray());
7272

7373
if (currentModDirSetting != null)
7474
{
@@ -78,7 +78,7 @@ private void InitSettings(ModManagerAPI.ModSettings settings)
7878
if (openModDirButton != null)
7979
openModDirButton.Update();
8080
}
81-
}, () => this.modPaths.ToList().StringFromList(";"), toStr =>
81+
}, () => modPaths.ToList().StringFromList(";"), toStr =>
8282
{
8383
int dirCount = toStr.Split(';').Length;
8484
return (toStr, dirCount + " Director" + (dirCount > 1 ? "ies" : "y"));
@@ -96,18 +96,18 @@ private void InitSettings(ModManagerAPI.ModSettings settings)
9696

9797
if (openModDirButton != null)
9898
openModDirButton.Update();
99-
}, () => selectedModDir, toStr => (toStr.ToString(), toStr <= this.modPaths.Count && toStr > 0 ? this.modPaths.ToList()[toStr - 1] : "Choose a Mod Directory"), str =>
99+
}, () => selectedModDir, toStr => (toStr.ToString(), toStr <= modPaths.Count && toStr > 0 ? modPaths.ToList()[toStr - 1] : "Choose a Mod Directory"), str =>
100100
{
101101
bool success = int.TryParse(str, out int val);
102102
return (val, success);
103-
}).SetMinimumMaximumAndIncrementValues(0, this.modPaths.Count, 1);
103+
}).SetMinimumMaximumAndIncrementValues(0, modPaths.Count, 1);
104104

105105
this.openModDirButton = settings.Button("openModDirButton", "xuiModManagerOpenModDirButton", () =>
106106
{
107-
if (selectedModDir > 0 && selectedModDir <= this.modPaths.Count)
108-
UnityEngine.Application.OpenURL(this.modPaths.ToList()[selectedModDir - 1]);
107+
if (selectedModDir > 0 && selectedModDir <= modPaths.Count)
108+
UnityEngine.Application.OpenURL(modPaths.ToList()[selectedModDir - 1]);
109109
},
110-
() => Localization.Get("xuiModManagerOpenModDirButtonText")).SetEnabled(() => this.modPaths.Count > 0 && selectedModDir > 0 && selectedModDir <= this.modPaths.Count);
110+
() => Localization.Get("xuiModManagerOpenModDirButtonText")).SetEnabled(() => modPaths.Count > 0 && selectedModDir > 0 && selectedModDir <= modPaths.Count);
111111

112112
/*
113113
settings.Category("startup", "Startup");

Source/UI/XUiC_ModsList.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CustomModManager.Mod;
22
using CustomModManager.Mod.Version;
33
using System.Collections.Generic;
4+
using System.Linq;
45

56
namespace CustomModManager.UI
67
{
@@ -21,10 +22,20 @@ public override void Init()
2122
{
2223
base.Init();
2324

24-
this.GetChildById("btnSort").ViewComponent.Controller.OnPress += new XUiEvent_OnPressEventHandler(SortButton_OnPressed);
25+
this.GetChildById("btnSort").ViewComponent.Controller.OnPress += SortButton_OnPress;
26+
this.GetChildById("btnRefresh").ViewComponent.Controller.OnPress += RefreshButton_OnPress;
2527
}
2628

27-
private void SortButton_OnPressed(XUiController _sender, int _mouseButton)
29+
private void RefreshButton_OnPress(XUiController _sender, int _mouseButton)
30+
{
31+
ModLoader.Instance.Load(ModManagerMod.modPaths.ToArray());
32+
33+
this.RebuildList(true);
34+
this.RefreshBindings(true);
35+
this.RefreshView(true);
36+
}
37+
38+
private void SortButton_OnPress(XUiController _sender, int _mouseButton)
2839
{
2940
this.sortingType = this.sortingType.CycleEnum();
3041
this.RefreshBindings(true);
@@ -38,7 +49,7 @@ private int Sort(ListEntry a, ListEntry b)
3849
switch(sortingType)
3950
{
4051
case SortingType.Alphanumerical:
41-
return a.modEntry.Info.Name.CompareTo(b.modEntry.Info.Name);
52+
return a.modEntry.Info.DisplayName.CompareTo(b.modEntry.Info.DisplayName);
4253
case SortingType.Author:
4354
return a.modEntry.Info.Author.CompareTo(b.modEntry.Info.Author);
4455
}
@@ -70,7 +81,7 @@ public override void RebuildList(bool _resetFilter = false)
7081
{
7182
this.allEntries.Clear();
7283
this.ScanMods();
73-
this.allEntries.Sort();
84+
this.allEntries.Sort((x, y) => Sort(x, y));
7485
base.RebuildList(_resetFilter);
7586
}
7687

@@ -92,6 +103,9 @@ public override bool GetBindingValue(ref string _value, string _bindingName)
92103
case "sortingTooltip":
93104
_value = string.Format(Localization.Get("xuiModsSort"), GetSortingNameUnlocalized());
94105
return true;
106+
case "refreshTooltip":
107+
_value = Localization.Get("xuiModsRefresh");
108+
return true;
95109
default:
96110
return base.GetBindingValue(ref _value, _bindingName);
97111
}
@@ -111,15 +125,15 @@ public override int CompareTo(object _otherEntry)
111125
if (!(_otherEntry is ListEntry))
112126
return 1;
113127

114-
return 1 * modEntry.Info.Name.CompareTo(((ListEntry)_otherEntry).modEntry.Info.Name);
128+
return 1 * modEntry.Info.DisplayName.CompareTo(((ListEntry)_otherEntry).modEntry.Info.DisplayName);
115129
}
116130

117131
public override bool GetBindingValue(ref string _value, string _bindingName)
118132
{
119133
switch(_bindingName)
120134
{
121135
case "modName":
122-
_value = modEntry.Info.Name;
136+
_value = modEntry.Info.DisplayName;
123137
return true;
124138
case "modVersion":
125139
_value = modEntry.Version.ToString() + (modEntry.Manifest != null && modEntry.Manifest.UpToDate() == EVersionStatus.Not_Up_To_Date ? "\u2191" : "");
@@ -215,7 +229,7 @@ private string GetModLoadedLocalization(bool value)
215229

216230
public override bool MatchesSearch(string _searchString)
217231
{
218-
return modEntry.Info.Name.ToLowerInvariant().StartsWith(_searchString.ToLowerInvariant());
232+
return modEntry.Info.DisplayName.ToLowerInvariant().StartsWith(_searchString.ToLowerInvariant());
219233
}
220234

221235
public static bool GetNullBindingValues(ref string _value, string _bindingName)

Source/UI/XUiC_ModsListModInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public override bool GetBindingValue(ref string _value, string _bindingName)
7474
switch (_bindingName)
7575
{
7676
case "modName":
77-
_value = currentModEntry != null ? currentModEntry.Info.Name : "";
77+
_value = currentModEntry != null ? currentModEntry.Info.DisplayName : "";
7878
return true;
7979
case "modAuthor":
8080
_value = currentModEntry != null ? currentModEntry.Info.Author : "";

0 commit comments

Comments
 (0)