diff --git a/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs index 07b5cfcd..63dc82fe 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs @@ -21,7 +21,15 @@ public class ModdedNumberOptionAttribute( { internal override IModdedOption CreateOption(object? value, PropertyInfo property) { - return new ModdedNumberOption(Title, (float)(value ?? min+increment), min, max, increment, suffixType, formatString, zeroInfinity); + return new ModdedNumberOption( + Title, + (float)(value ?? min + increment), + min, + max, + increment, + suffixType, + formatString, + zeroInfinity); } /// diff --git a/MiraAPI/GameOptions/MiraNumberOptionComponent.cs b/MiraAPI/GameOptions/MiraNumberOptionComponent.cs new file mode 100644 index 00000000..a00274fe --- /dev/null +++ b/MiraAPI/GameOptions/MiraNumberOptionComponent.cs @@ -0,0 +1,28 @@ +using System; +using MiraAPI.GameOptions.OptionTypes; +using Reactor.Utilities.Attributes; +using UnityEngine; + +namespace MiraAPI.GameOptions; + +/// +/// Component added onto options generated via MiraAPI. This allows developers to hook patches onto options in general, without using a list. +/// +[RegisterInIl2Cpp] +public class MiraNumberOptionComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr) +{ + /// + /// Gets or sets the modded option associated with the object. + /// + public ModdedNumberOption NumberOption { get; set; } + + /// + /// Gets or sets the default increment. + /// + public float DefaultIncrement { get; set; } + + /// + /// Gets or sets the value of whether or not holding shift will split the increment in half. + /// + public bool ShiftIncrementToggle { get; set; } +} diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs index 0bec22fd..48f74513 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs @@ -47,6 +47,8 @@ public class ModdedEnumOption : ModdedOption public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container) { var stringOption = Object.Instantiate(stringOpt, container); + stringOption.name = + $"{ParentMod!.OptionsTitleText}.EnumOption.{TranslationController.Instance.GetString(StringName)}"; stringOption.SetUpFromData(Data, 20); stringOption.OnValueChanged = (Il2CppSystem.Action)ValueChanged; @@ -138,6 +140,8 @@ public class ModdedEnumOption : ModdedOption where T : Enum public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container) { var stringOption = Object.Instantiate(stringOpt, container); + stringOption.name = + $"{ParentMod!.OptionsTitleText}.EnumOption.{TranslationController.Instance.GetString(StringName)}"; stringOption.SetUpFromData(Data, 20); stringOption.OnValueChanged = (Il2CppSystem.Action)ValueChanged; diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index 53378e1e..0cca2067 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -37,6 +37,11 @@ public class ModdedNumberOption : ModdedOption /// public bool ZeroInfinity { get; } + /// + /// Gets a value indicating whether holding shift will divide the increment. + /// + public bool ShiftIncrement { get; } + /// /// Initializes a new instance of the class. /// @@ -49,6 +54,7 @@ public class ModdedNumberOption : ModdedOption /// Optional format string for the option screen. /// Whether zero is infinity or not. /// Whether to include this option in the preset or not. + /// Whether holding shift will divide the increment or not. public ModdedNumberOption( string title, float defaultValue, @@ -65,6 +71,7 @@ public class ModdedNumberOption : ModdedOption Increment = increment; SuffixType = suffixType; ZeroInfinity = zeroInfinity; + ShiftIncrement = increment != 1f; Value = Mathf.Clamp(defaultValue, min, max); @@ -97,6 +104,12 @@ public class ModdedNumberOption : ModdedOption Transform container) { var numberOption = Object.Instantiate(numberOpt, Vector3.zero, Quaternion.identity, container); + numberOption.name = + $"{ParentMod!.OptionsTitleText}.NumberOption.{TranslationController.Instance.GetString(StringName)}"; + var optionComponent = numberOption.gameObject.AddComponent(); + optionComponent.NumberOption = this; + optionComponent.DefaultIncrement = Increment; + optionComponent.ShiftIncrementToggle = ShiftIncrement; numberOption.SetUpFromData(Data, 20); numberOption.OnValueChanged = (Il2CppSystem.Action)ValueChanged; diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs index 6069a2cb..dd2f7720 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs @@ -55,6 +55,8 @@ public class ModdedPlayerOption : ModdedOption Transform container) { var playerOption = Object.Instantiate(playerOpt, container); + playerOption.name = + $"{ParentMod!.OptionsTitleText}.PlayerOption.{TranslationController.Instance.GetString(StringName)}"; var filteredList = GetFilteredPlayers(); Values = filteredList.ToIl2CppList(); diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index 2cdd0e1e..0b13f97a 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -29,6 +29,8 @@ public class ModdedToggleOption : ModdedOption public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container) { var toggleOption = Object.Instantiate(toggleOpt, Vector3.zero, Quaternion.identity, container); + toggleOption.name = + $"{ParentMod!.OptionsTitleText}.ToggleOption.{TranslationController.Instance.GetString(StringName)}"; toggleOption.SetUpFromData(Data, 20); diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index 3e4bd9d9..5d6b3572 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -494,7 +494,7 @@ public abstract class CustomActionButton if (Keybind != null && KeybindText != null) { KeybindText.text = Keybind.CurrentKey.ToString(); - KeybindIcon?.SetActive(ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard && + KeybindIcon?.SetActive(ActiveInputManager.currentControlType is ActiveInputManager.InputType.Keyboard && LocalSettingsTabSingleton.Instance.ShowKeybinds.Value && Keybind.CurrentKey != KeyboardKeyCode.None); } diff --git a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs index bec12817..273cef22 100644 --- a/MiraAPI/Patches/Options/GameSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/GameSettingMenuPatches.cs @@ -38,6 +38,8 @@ internal static class GameSettingMenuPatches private static PassiveButton? _customOneButton; private static GameOptionsMenu? _customTwoTab; private static PassiveButton? _customTwoButton; + private static GameObject? _nextModButton; + private static GameObject? _previousModButton; private static Dictionary OptionsPositions { get; } = []; private static Dictionary ModifiersPositions { get; } = []; @@ -178,16 +180,16 @@ internal static class GameSettingMenuPatches _text.alignment = TextAlignmentOptions.Center; - var nextButton = Object.Instantiate(__instance.BackButton, __instance.BackButton.transform.parent).gameObject; - nextButton.transform.localPosition = new Vector3(-2.2663f, 1.5272f, -25f); - nextButton.name = "RightArrowButton"; - nextButton.transform.FindChild("Inactive").gameObject.GetComponent().sprite = + _nextModButton = Object.Instantiate(__instance.BackButton, __instance.BackButton.transform.parent).gameObject; + _nextModButton.transform.localPosition = new Vector3(-2.2663f, 1.5272f, -25f); + _nextModButton.name = "RightArrowButton"; + _nextModButton.transform.FindChild("Inactive").gameObject.GetComponent().sprite = MiraAssets.NextButton.LoadAsset(); - nextButton.transform.FindChild("Active").gameObject.GetComponent().sprite = + _nextModButton.transform.FindChild("Active").gameObject.GetComponent().sprite = MiraAssets.NextButtonActive.LoadAsset(); - nextButton.gameObject.GetComponent().DestroyImmediate(); + _nextModButton.gameObject.GetComponent().DestroyImmediate(); - var passiveButton = nextButton.gameObject.GetComponent(); + var passiveButton = _nextModButton.gameObject.GetComponent(); passiveButton.OnClick = new ButtonClickedEvent(); passiveButton.OnClick.AddListener( (UnityAction)(() => @@ -202,13 +204,13 @@ internal static class GameSettingMenuPatches UpdateText(__instance, __instance.GameSettingsTab, __instance.RoleSettingsTab); })); - var backButton = Object.Instantiate(nextButton, __instance.BackButton.transform.parent).gameObject; - backButton.transform.localPosition = new Vector3(-4.4209f, 1.5272f, -25f); - backButton.name = "LeftArrowButton"; - backButton.gameObject.GetComponent().Destroy(); - backButton.transform.FindChild("Active").gameObject.GetComponent().flipX = - backButton.transform.FindChild("Inactive").gameObject.GetComponent().flipX = true; - backButton.gameObject.GetComponent().OnClick.AddListener( + _previousModButton = Object.Instantiate(_nextModButton, __instance.BackButton.transform.parent).gameObject; + _previousModButton.transform.localPosition = new Vector3(-4.4209f, 1.5272f, -25f); + _previousModButton.name = "LeftArrowButton"; + _previousModButton.gameObject.GetComponent().Destroy(); + _previousModButton.transform.FindChild("Active").gameObject.GetComponent().flipX = + _previousModButton.transform.FindChild("Inactive").gameObject.GetComponent().flipX = true; + _previousModButton.gameObject.GetComponent().OnClick.AddListener( (UnityAction)(() => { SaveScrollPositions(__instance); diff --git a/MiraAPI/Patches/Options/OptionsPatches.cs b/MiraAPI/Patches/Options/OptionsPatches.cs index 469a053b..2cdb35fe 100644 --- a/MiraAPI/Patches/Options/OptionsPatches.cs +++ b/MiraAPI/Patches/Options/OptionsPatches.cs @@ -14,6 +14,25 @@ namespace MiraAPI.Patches.Options; [HarmonyPatch] public static class OptionsPatches { + [HarmonyPrefix] + [HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Increment), MethodType.Getter)] + public static bool FloatIncrementPatch(NumberOption __instance, ref float __result) + { + if (!__instance.TryGetComponent(out var miraNumber) || !miraNumber.ShiftIncrementToggle) + { + return true; + } + + var increment = miraNumber.DefaultIncrement; + + if (Input.GetKey(KeyCode.LeftShift)) + { + increment /= 2; + } + + __result = increment; + return false; + } [HarmonyPrefix] [HarmonyPatch(typeof(RoleOptionSetting), nameof(RoleOptionSetting.IncreaseChance))] public static bool RoleIncreaseChancePrefix(RoleOptionSetting __instance)