Skip to content

Commit ccd92b3

Browse files
committed
moved options into separated header
1 parent e12d45c commit ccd92b3

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

Diff for: kg_LastEpoch_Improvements/Utils.cs

+21-6
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,43 @@ public static void set<T>(this Il2CppSystem.Collections.Generic.List<T> list, in
3636
method.Invoke(list, new object[] { index, value });
3737
}
3838
//adds an option to vanilla last epoch UI settings
39-
public static void CreateNewOption(this SettingsPanelTabNavigable settings, string Name, MelonPreferences_Entry<bool> option, Action<bool> a)
39+
private static int CreateCategoryIfNeeded(SettingsPanelTabNavigable settings, string Category)
40+
{
41+
Transform findExisting = settings.transform.GetChild(0).GetChild(0).Find($"ModsCategory - {Category}");
42+
if (findExisting) return findExisting.GetSiblingIndex();
43+
Transform headerInterface = settings.transform.GetChild(0).GetChild(0).Find("Header-Interface");
44+
if (!headerInterface) return 0;
45+
Transform newCategory = UnityEngine.Object.Instantiate(headerInterface, headerInterface.parent);
46+
newCategory.name = $"ModsCategory - {Category}";
47+
newCategory.GetChild(0).GetChild(0).GetComponent<TMP_Text>().text = Category;
48+
newCategory.GetChild(0).GetChild(0).GetComponent<TMP_Text>().color = Color.green;
49+
UnityEngine.Object.DestroyImmediate(newCategory.GetChild(0).GetChild(0).GetComponent<LocalizeStringEvent>());
50+
newCategory.transform.SetSiblingIndex(headerInterface.GetSiblingIndex());
51+
return newCategory.GetSiblingIndex();
52+
}
53+
public static void CreateNewOption(this SettingsPanelTabNavigable settings, string Category, string Name, MelonPreferences_Entry<bool> option, Action<bool> a)
4054
{
4155
Transform optionsTransform = settings.transform.GetChild(0).GetChild(0).Find("Option - Minion Health Bars");
4256
if (!optionsTransform) return;
57+
int orderIndex = CreateCategoryIfNeeded(settings, Category);
4358
Transform newButton = UnityEngine.Object.Instantiate(optionsTransform, optionsTransform.parent);
4459
newButton.name = Name;
45-
newButton.SetSiblingIndex(optionsTransform.GetSiblingIndex() + 1);
60+
newButton.SetSiblingIndex(orderIndex + 1);
4661
newButton.GetChild(0).GetComponent<Toggle>().isOn = option.Value;
4762
newButton.GetChild(0).GetComponent<Toggle>().onValueChanged.AddListener(a);
4863
UnityEngine.Object.DestroyImmediate(newButton.GetChild(1).GetChild(0).GetComponent<LocalizeStringEvent>());
4964
newButton.GetChild(1).GetChild(0).GetComponent<TMP_Text>().text = Name;
5065
}
51-
public static void CreateNewOption_EnumDropdown<T>(this SettingsPanelTabNavigable settings, string Name, string Description, MelonPreferences_Entry<T> option, Action<int> a) where T : Enum
66+
public static void CreateNewOption_EnumDropdown<T>(this SettingsPanelTabNavigable settings, string Category, string Name, string Description, MelonPreferences_Entry<T> option, Action<int> a) where T : Enum
5267
{
5368
Transform optionsTransform = settings.transform.GetChild(0).GetChild(0).Find("Dropdown - Language Selection");
54-
Transform orderTransform = settings.transform.GetChild(0).GetChild(0).Find("Option - Minion Health Bars");
55-
if (!optionsTransform || !orderTransform) return;
69+
if (!optionsTransform) return;
70+
int orderIndex = CreateCategoryIfNeeded(settings, Category);
5671
Transform newDropdown = UnityEngine.Object.Instantiate(optionsTransform, optionsTransform.parent);
5772
UnityEngine.Object.DestroyImmediate(newDropdown.GetComponent<LocalizationSettingsPanelUI>());
5873
UnityEngine.Object.DestroyImmediate(newDropdown.GetComponent<LootFilterSettingsPanelUI>());
5974
newDropdown.name = Name;
60-
newDropdown.SetSiblingIndex(orderTransform.GetSiblingIndex() + 1);
75+
newDropdown.SetSiblingIndex(orderIndex + 1);
6176

6277
newDropdown.GetChild(0).GetComponent<TMP_Text>().text = Name;
6378
UnityEngine.Object.DestroyImmediate(newDropdown.GetChild(0).GetComponent<LocalizeStringEvent>());

Diff for: kg_LastEpoch_Improvements/kg_LastEpoch_Improvements.cs

+9-11
Original file line numberDiff line numberDiff line change
@@ -285,35 +285,36 @@ private static class SettingsPanelTabNavigable_Awake_Patch
285285
{
286286
private static void Postfix(SettingsPanelTabNavigable __instance)
287287
{
288+
const string CategoryName = "KG Improvements";
288289
#if CHEATVERSION
289-
__instance.CreateNewOption("<color=green>[Cheat] Clear fog on map on start</color>", Cheat_FogOfWar, (tf) =>
290+
__instance.CreateNewOption(CategoryName, "<color=green>[Cheat] Clear fog on map on start</color>", Cheat_FogOfWar, (tf) =>
290291
{
291292
Cheat_FogOfWar.Value = tf;
292293
ImprovementsModCategory.SaveToFile();
293294
});
294-
__instance.CreateNewOption("<color=green>[Cheat] Enhanced camera</color>", Cheat_EnhancedCamera, (tf) =>
295+
__instance.CreateNewOption(CategoryName, "<color=green>[Cheat] Enhanced camera</color>", Cheat_EnhancedCamera, (tf) =>
295296
{
296297
Cheat_EnhancedCamera.Value = tf;
297298
ImprovementsModCategory.SaveToFile();
298299
CameraManager_Start_Patch.Switch();
299300
});
300301
#endif
301-
__instance.CreateNewOption_EnumDropdown("<color=green>Affix Show Roll (Tooltip)</color>", "Show affix roll on tooltip text", AffixShowRoll, (i) =>
302+
__instance.CreateNewOption_EnumDropdown(CategoryName, "<color=green>Affix Show Roll (Tooltip)</color>", "Show affix roll on tooltip text", AffixShowRoll, (i) =>
302303
{
303304
AffixShowRoll.Value = (DisplayAffixType)i;
304305
ImprovementsModCategory.SaveToFile();
305306
});
306-
__instance.CreateNewOption_EnumDropdown("<color=green>Affix Show Roll (Ground)", "Show affix roll on ground text", ShowAffixOnLabel, (i) =>
307+
__instance.CreateNewOption_EnumDropdown(CategoryName, "<color=green>Affix Show Roll (Ground)</color>", "Show affix roll on ground text", ShowAffixOnLabel, (i) =>
307308
{
308309
ShowAffixOnLabel.Value = (DisplayAffixType_GroundLabel)i;
309310
ImprovementsModCategory.SaveToFile();
310311
});
311-
__instance.CreateNewOption("<color=green>Map Filter Show All</color>", ShowAll, (tf) =>
312+
__instance.CreateNewOption(CategoryName, "<color=green>Map Filter Show All</color>", ShowAll, (tf) =>
312313
{
313314
ShowAll.Value = tf;
314315
ImprovementsModCategory.SaveToFile();
315316
});
316-
__instance.CreateNewOption("<color=green>Auto storage craft materials</color>", AutoStoreCraftMaterials, (ascm) =>
317+
__instance.CreateNewOption(CategoryName, "<color=green>Auto storage craft materials</color>", AutoStoreCraftMaterials, (ascm) =>
317318
{
318319
AutoStoreCraftMaterials.Value = ascm;
319320
ImprovementsModCategory.SaveToFile();
@@ -326,7 +327,7 @@ private static void Postfix(SettingsPanelTabNavigable __instance)
326327
private static class MinimapFogOfWar_Initialize_Patch
327328
{
328329
private const float cheatDiscovery = 10000f;
329-
private static void Prefix(MinimapFogOfWar __instance, out float __state)
330+
private static void Prefix(MinimapFogOfWar __instance, out float __state)
330331
{
331332
__state = __instance.discoveryDistance;
332333
if (Cheat_FogOfWar.Value) __instance.discoveryDistance = cheatDiscovery;
@@ -372,13 +373,10 @@ private static void Postfix(CameraManager __instance)
372373
Switch();
373374
}
374375
}
375-
376-
377-
378376
#endif
379377

380378

381-
//OpenInvneotryPanel invokes at loadingscreen after InventoryPanelUI.Awake, we cannot call StoreMaterialsButtonPress() at this moment
379+
//OpenInventoryPanel invokes at loadingscreen after InventoryPanelUI.Awake, we cannot call StoreMaterialsButtonPress() at this moment
382380
//cause it throws an exception (probably some stuff didn't load yet)
383381
[HarmonyPatch(typeof(InventoryPanelUI),nameof(InventoryPanelUI.Awake))]
384382
private static class InventoryPanelUI_Awake_Patch

0 commit comments

Comments
 (0)