From 5049d16ac9658b8abc6206311d651859757eb3aa Mon Sep 17 00:00:00 2001 From: Atony <75191600+AtonyGit@users.noreply.github.com> Date: Sun, 26 Oct 2025 14:17:11 -0500 Subject: [PATCH] Fix errors --- MiraAPI/GameOptions/IModdedOption.cs | 5 ++ .../OptionTypes/ModdedMultiSelectOption.cs | 7 +- .../GameOptions/OptionTypes/ModdedOption.cs | 17 ++++ .../OptionTypes/ModdedPlayerOption.cs | 21 +++++ MiraAPI/MiraApiPlugin.cs | 4 + .../Patches/Options/GameOptionsMenuPatch.cs | 3 +- .../Patches/Options/RoleSettingMenuPatches.cs | 1 - MiraAPI/Utilities/Helpers.cs | 77 ++++++++++++++++++- MiraAPI/Utilities/MiraNumberSuffixes.cs | 5 ++ 9 files changed, 136 insertions(+), 4 deletions(-) diff --git a/MiraAPI/GameOptions/IModdedOption.cs b/MiraAPI/GameOptions/IModdedOption.cs index 947b6ff..334edd6 100644 --- a/MiraAPI/GameOptions/IModdedOption.cs +++ b/MiraAPI/GameOptions/IModdedOption.cs @@ -92,6 +92,11 @@ public interface IModdedOption /// Indicates whether to save the default value instead of the current value. void SaveToPreset(ConfigFile presetConfig, bool saveDefault = false); + /// + /// Changes the scales and positions of the option if it's attached to the game options menu. + /// + void ChangeGameSetting(); + /// /// Binds the option to a configuration file. /// diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedMultiSelectOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedMultiSelectOption.cs index fd4de5f..7c86ade 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedMultiSelectOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedMultiSelectOption.cs @@ -71,7 +71,12 @@ public class ModdedMultiSelectOption : ModdedOption where T : struct, Enum } /// - public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container) + public override OptionBehaviour CreateOption( + ToggleOption toggleOpt, + NumberOption numberOpt, + StringOption stringOpt, + PlayerOption playerOpt, + Transform container) { var stringOption = Object.Instantiate(stringOpt, container); diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 392c76f..842ee7d 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -181,6 +181,23 @@ public abstract class ModdedOption : IModdedOption PlayerOption playerOpt, Transform container); + /// + /// Visually adjust the game option as needed. + /// + public abstract void ChangeGameSetting(); + + /// + /// Binds the option to the configuration file of the parent mod, if available. + /// + public virtual void BindConfig() + { + var entry = ParentMod?.GetConfigFile().Bind(ConfigDefinition, DefaultValue); + if (entry != null) + { + Value = entry.Value; + } + } + /// /// Implicitly converts the option to type of . /// diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs index dd2f772..397a91a 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs @@ -28,6 +28,27 @@ public class ModdedPlayerOption : ModdedOption /// public bool AllowNone { get; set; } + /// + public override void ChangeGameSetting() + { + var numberOption = OptionBehaviour as PlayerOption; + + numberOption!.PlusBtn.transform.localPosition += new Vector3(0.6f, 0f, 0f); + numberOption.MinusBtn.transform.localPosition += new Vector3(1.5f, 0f, 0f); + + var background = numberOption.transform.GetChild(0); + background.localPosition += new Vector3(-0.8f, 0f, 0f); + background.localScale += new Vector3(1f, 0f, 0f); + + var title = numberOption.TitleText; + title.transform.localPosition = new(-2.0466f, 0f, -2.9968f); + title.GetComponent().sizeDelta = new(5.8f, 0.458f); + + var valueBox = numberOption.transform.GetChild(5); + valueBox.localPosition += new Vector3(1.05f, 0f, 0f); + valueBox.localScale += new Vector3(0.2f, 0f, 0f); + } + /// /// Initializes a new instance of the class. /// diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index 469ffd2..2e6f965 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -1,5 +1,6 @@ global using static Reactor.Utilities.Logger; using BepInEx; +using BepInEx.Configuration; using BepInEx.Unity.IL2CPP; using HarmonyLib; using MiraAPI.PluginLoading; @@ -31,6 +32,7 @@ public partial class MiraApiPlugin : BasePlugin /// public static Color DefaultHeaderColor { get; } = new Color32(77, 77, 77, 255); + internal static ConfigEntry? DistanceSuffix { get; private set; } private static MiraPluginManager? PluginManager { get; set; } internal Harmony Harmony { get; } = new(Id); @@ -41,6 +43,8 @@ public partial class MiraApiPlugin : BasePlugin ReactorCredits.Register("Mira API", Version, true, ReactorCredits.AlwaysShow); + DistanceSuffix = Config.Bind("Display", "Distance", "unit(s)", "Dictates how a distance is shown in numeric option displays"); + PluginManager = new MiraPluginManager(); PluginManager.Initialize(); } diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index b6dc5fd..0583521 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -284,7 +284,8 @@ internal static class GameOptionsMenuPatch menu.playerOptionOrigin, menu.settingsContainer)); - group.Options.ForEach(x => x.ChangeGameSetting()); + // TODO: Reimplement this without breaking the menu. + // group.Options.ForEach(x => x.ChangeGameSetting()); foreach (var newOpt in options) { diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 25aedcd..78e720c 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -439,7 +439,6 @@ public static class RoleSettingMenuPatches __instance.AdvancedRolesSettings.transform); newOpt.SetClickMask(__instance.ButtonClickMask); - option.ChangeRoleSetting(); SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren(true); foreach (var renderer in componentsInChildren) diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index 3b007a6..e3fa3c2 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -12,6 +13,7 @@ using TMPro; using UnityEngine; using MethodBase = System.Reflection.MethodBase; using Object = UnityEngine.Object; +using Random = UnityEngine.Random; namespace MiraAPI.Utilities; @@ -522,6 +524,79 @@ public static class Helpers (Il2CppSystem.Object[])[value.ToString(formatString, CultureInfo.InvariantCulture)]), }; } + /// + /// Shorthand for that removes empty entries and trims leading and ending spaces. + /// + /// The string to split. + /// The separator. + /// An array of substrings. + public static string[] TrueSplit(this string value, char separator) => value.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + /// + /// Joins a collection of items that are separated by a character. + /// + /// The separator. + /// The collection of items to string together. + /// The type of the items. + /// A string formed by concatenating the ToString results of each item, each separated by a separator. + public static string Join(char separator, IEnumerable items) => Join(separator.ToString(), items); + + /// + public static string Join(string separator, IEnumerable items) + { + if (!items.Any()) + return string.Empty; + + var result = string.Empty; + items.Do(x => result += $"{separator}{x}"); + return result[separator.Length..]; + } + + /// + /// Shorthand helper for overriding the on click listeners for PassiveButton. + /// + /// The PassiveButton being modified. + /// The action that's replacing the original listeners. + public static void OverrideOnClickListeners(this PassiveButton passive, Action action) + { + if (!passive) + return; + + passive.OnClick?.RemoveAllListeners(); + passive.OnClick = new(); + passive.OnClick.AddListener(action); + passive.enabled = true; + } + + /// + /// Shorthand helper for overriding the on mouse over listeners for PassiveButton. + /// + /// + public static void OverrideOnMouseOverListeners(this PassiveButton passive, Action action) + { + if (!passive) + return; + + passive.OnMouseOver?.RemoveAllListeners(); + passive.OnMouseOver = new(); + passive.OnMouseOver.AddListener(action); + passive.enabled = true; + } + + /// + /// Shorthand helper for overriding the on mouse out listeners for PassiveButton. + /// + /// + public static void OverrideOnMouseOutListeners(this PassiveButton passive, Action action) + { + if (!passive) + return; + + passive.OnMouseOut?.RemoveAllListeners(); + passive.OnMouseOut = new(); + passive.OnMouseOut.AddListener(action); + passive.enabled = true; + } /// /// Returns the string of a role. diff --git a/MiraAPI/Utilities/MiraNumberSuffixes.cs b/MiraAPI/Utilities/MiraNumberSuffixes.cs index 2f55226..c49f13c 100644 --- a/MiraAPI/Utilities/MiraNumberSuffixes.cs +++ b/MiraAPI/Utilities/MiraNumberSuffixes.cs @@ -24,4 +24,9 @@ public enum MiraNumberSuffixes /// Percentage suffix (%). /// Percent, + + /// + /// Display in units. + /// + Distance, }