Fix role option visibility & shift 5 increments on chance

This commit is contained in:
ang-xd committed 2025-06-27 19:16:56 -04:00
1 parent 56d4e399d9
commit f43191c4f2
2 files changed
+43 -11

No files matched your search

+8 -2
View File
@@ -2,6 +2,8 @@
using Il2CppSystem;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using UnityEngine;
using Object = Il2CppSystem.Object;
namespace MiraAPI.Patches.Options;
@@ -22,7 +24,9 @@ public static class OptionsPatches
__instance.roleMaxCount = 1;
}
__instance.roleChance += 10;
var increment = Input.GetKey(KeyCode.LeftShift) ? 5 : 10;
__instance.roleChance += increment;
if (__instance.roleChance > 100)
{
__instance.roleChance = 0;
@@ -46,7 +50,9 @@ public static class OptionsPatches
__instance.roleMaxCount = 1;
}
__instance.roleChance -= 10;
var increment = Input.GetKey(KeyCode.LeftShift) ? 5 : 10;
__instance.roleChance -= increment;
if (__instance.roleChance < 0)
{
__instance.roleChance = 100;
@@ -30,6 +30,8 @@ public static class RoleSettingMenuPatches
private static float ScrollerNum { get; set; } = 0.522f;
private static RoleBehaviour? CurrentRole { get; set; }
[HarmonyPostfix]
[HarmonyPatch(nameof(RolesSettingsMenu.SetQuotaTab))]
public static void SetQuotaTabPostfix(RolesSettingsMenu __instance)
@@ -45,6 +47,7 @@ public static class RoleSettingMenuPatches
RoleOptionSettings.ForEach(Object.Destroy);
Headers.Clear();
RoleOptionSettings.Clear();
CurrentRole = null;
__instance.roleChances = new Il2CppSystem.Collections.Generic.List<RoleOptionSetting>();
__instance.advancedSettingChildren = new Il2CppSystem.Collections.Generic.List<OptionBehaviour>();
@@ -262,9 +265,36 @@ public static class RoleSettingMenuPatches
[HarmonyPrefix]
[HarmonyPatch(nameof(RolesSettingsMenu.Update))]
public static bool UpdatePatch()
public static bool UpdatePatch(RolesSettingsMenu __instance)
{
return GameSettingMenuPatches.SelectedModIdx == 0;
if (GameSettingMenuPatches.SelectedModIdx == 0) return true;
if (CurrentRole == null) return false;
var filteredOptions = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.GroupVisible() && x.OptionableType == CurrentRole.GetType())
.SelectMany(x => x.Options)
.ToList() ?? [];
var hasImage = CurrentRole.RoleScreenshot != null;
var num = hasImage ? -0.872f : -1;
foreach (var opt in filteredOptions)
{
if (opt.OptionBehaviour == null) continue;
if (!opt.Visible.Invoke())
{
opt.OptionBehaviour.gameObject.SetActive(false);
continue;
}
opt.OptionBehaviour.transform.localPosition = new Vector3(hasImage ? 2.17f : 1.1f, num, -2f);
opt.OptionBehaviour.gameObject.SetActive(true);
num += -0.45f;
}
__instance.scrollBar.SetYBoundsMax(-num - 3);
return false;
}
[HarmonyPostfix]
@@ -328,16 +358,14 @@ public static class RoleSettingMenuPatches
optBehaviour.gameObject.DestroyImmediate();
}
CurrentRole = role;
__instance.advancedSettingChildren.Clear();
var hasImage = role.RoleScreenshot != null;
var num = hasImage ? -0.872f : -1;
// TODO: create sub groups under the role settings.
var filteredOptions = GameSettingMenuPatches.SelectedMod?.InternalOptionGroups
.Where(x => x.GroupVisible() && x.OptionableType == role.GetType())
.SelectMany(x => x.Options)
.Where(x => x.Visible())
.ToList() ?? [];
foreach (var option in filteredOptions)
@@ -348,7 +376,6 @@ public static class RoleSettingMenuPatches
__instance.stringOptionOrigin,
__instance.AdvancedRolesSettings.transform);
newOpt.transform.localPosition = new Vector3(hasImage ? 2.17f : 1.1f, num, -2f);
newOpt.SetClickMask(__instance.ButtonClickMask);
SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren<SpriteRenderer>(true);
@@ -366,11 +393,10 @@ public static class RoleSettingMenuPatches
newOpt.LabelBackground.enabled = false;
__instance.advancedSettingChildren.Add(newOpt);
num += -0.45f;
newOpt.gameObject.SetActive(false);
newOpt.Initialize();
}
__instance.scrollBar.SetYBoundsMax(-num - 3);
__instance.scrollBar.ScrollToTop();
}
@@ -506,7 +532,7 @@ public static class RoleSettingMenuPatches
if (GameSettingMenuPatches.SelectedMod is null ||
GameSettingMenuPatches.SelectedMod.InternalOptionGroups
.Exists(x => x.OptionableType == role.GetType()))
.Exists(x => x.GroupVisible() && x.OptionableType == role.GetType() && x.Options.Any(y => y.Visible())))
{
var newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
newButton.name = "ConfigButton";