From 6364f8eae69d3600d8f454d1e7a3872f3672dfc2 Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:27:24 -0400 Subject: [PATCH] constructor parity + scrap toggle display delegate --- .../Attributes/ModdedNumberOptionAttribute.cs | 36 +++++++++++++++-- .../Attributes/ModdedToggleOptionAttribute.cs | 19 ++++++++- .../ModdedNumberOptionListAttribute.cs | 36 +++++++++++++++-- .../ModdedToggleOptionListAttribute.cs | 19 ++++++++- .../OptionTypes/ModdedToggleOption.cs | 39 ++++++++++++++----- MiraAPI/Resources/Locale/en_US.xml | 8 ++++ 6 files changed, 136 insertions(+), 21 deletions(-) diff --git a/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs index 9de15ee..f43773e 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs @@ -12,20 +12,46 @@ namespace MiraAPI.GameOptions.Attributes; /// The minimum value. /// The maximum value. /// The increment. +/// Determines what is shown for zero. +/// Determines what is shown for negative 1. /// The suffix type. /// Optional format string for the option screen. -/// Flag indicating whether 0 means infinity. +/// Whether increments can be split in half (using Shift). [AttributeUsage(AttributeTargets.Property)] public class ModdedNumberOptionAttribute( string title, float min, float max, - float increment = 1, + float increment, + string zeroBehavior, + string negativeBehavior, MiraNumberSuffixes suffixType = MiraNumberSuffixes.None, string? formatString = null, - bool zeroInfinity = false) + bool halfIncrements = false) : ModdedOptionAttribute(title) { + /// + /// Initializes a new instance of the class. + /// + /// The title of the option. + /// The minimum value. + /// The maximum value. + /// The increment. + /// The suffix type. + /// Whether zero is infinity or not. + /// Optional format string for the option screen. + public ModdedNumberOptionAttribute( + string title, + float min, + float max, + float increment = 1, + MiraNumberSuffixes suffixType = MiraNumberSuffixes.None, + string? formatString = null, + bool zeroInfinity = false) + : this(title, min, max, increment, zeroInfinity ? "∞" : "#", "#", suffixType, formatString, increment == 1f) + { + } + internal override IModdedOption CreateOption(object? value, PropertyInfo property) { var final = value switch @@ -41,9 +67,11 @@ public class ModdedNumberOptionAttribute( min, max, increment, + zeroBehavior, + negativeBehavior, suffixType, formatString, - zeroInfinity); + halfIncrements); } /// diff --git a/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs index 2a2ac2f..042c1f3 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs @@ -8,12 +8,27 @@ namespace MiraAPI.GameOptions.Attributes; /// Attribute for a . /// /// The option title. +/// What the option displays when toggled on. +/// What the option displays when toggled off. [AttributeUsage(AttributeTargets.Property)] -public class ModdedToggleOptionAttribute(string title) : ModdedOptionAttribute(title) +public class ModdedToggleOptionAttribute( + string title, + string on, + string off) + : ModdedOptionAttribute(title) { + /// + /// Initializes a new instance of the class. + /// + /// The option title. + public ModdedToggleOptionAttribute(string title) + : this(title, "On", "Off") + { + } + internal override IModdedOption CreateOption(object? value, PropertyInfo property) { - var toggleOpt = new ModdedToggleOption(Title, (bool)(value ?? false)); + var toggleOpt = new ModdedToggleOption(Title, (bool)(value ?? false), on, off); return toggleOpt; } diff --git a/MiraAPI/GameOptions/Attributes/OptionList/ModdedNumberOptionListAttribute.cs b/MiraAPI/GameOptions/Attributes/OptionList/ModdedNumberOptionListAttribute.cs index 088883e..c393db3 100644 --- a/MiraAPI/GameOptions/Attributes/OptionList/ModdedNumberOptionListAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/OptionList/ModdedNumberOptionListAttribute.cs @@ -13,20 +13,46 @@ namespace MiraAPI.GameOptions.Attributes; /// The minimum value. /// The maximum value. /// The increment. +/// Determines what is shown for zero. +/// Determines what is shown for negative 1. /// The suffix type. /// Optional format string for the option screen. -/// Flag indicating whether 0 means infinity. +/// Whether increments can be split in half (using Shift). [AttributeUsage(AttributeTargets.Property)] public class ModdedNumberOptionListAttribute( string title, float min, float max, - float increment = 1, + float increment, + string zeroBehavior, + string negativeBehavior, MiraNumberSuffixes suffixType = MiraNumberSuffixes.None, string? formatString = null, - bool zeroInfinity = false) + bool halfIncrements = false) : ModdedOptionListAttribute(title) { + /// + /// Initializes a new instance of the class. + /// + /// The title of the option. + /// The minimum value. + /// The maximum value. + /// The increment. + /// The suffix type. + /// Whether zero is infinity or not. + /// Optional format string for the option screen. + public ModdedNumberOptionListAttribute( + string title, + float min, + float max, + float increment = 1, + MiraNumberSuffixes suffixType = MiraNumberSuffixes.None, + string? formatString = null, + bool zeroInfinity = false) + : this(title, min, max, increment, zeroInfinity ? "∞" : "#", "#", suffixType, formatString, increment == 1f) + { + } + internal override IModdedOptionList CreateOptionList(IList value, PropertyInfo property) { return new ModdedOptionList(value.Count, idx => @@ -44,9 +70,11 @@ public class ModdedNumberOptionListAttribute( min, max, increment, + zeroBehavior, + negativeBehavior, suffixType, formatString, - zeroInfinity); + halfIncrements); }); } diff --git a/MiraAPI/GameOptions/Attributes/OptionList/ModdedToggleOptionListAttribute.cs b/MiraAPI/GameOptions/Attributes/OptionList/ModdedToggleOptionListAttribute.cs index 4e01069..9dab9a4 100644 --- a/MiraAPI/GameOptions/Attributes/OptionList/ModdedToggleOptionListAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/OptionList/ModdedToggleOptionListAttribute.cs @@ -9,13 +9,28 @@ namespace MiraAPI.GameOptions.Attributes; /// Attribute for a list of toggle options. /// /// The option's title. +/// What the option displays when toggled on. +/// What the option displays when toggled off. [AttributeUsage(AttributeTargets.Property)] -public class ModdedToggleOptionListAttribute(string title) : ModdedOptionListAttribute(title) +public class ModdedToggleOptionListAttribute( + string title, + string on, + string off) + : ModdedOptionListAttribute(title) { + /// + /// Initializes a new instance of the class. + /// + /// The option's title. + public ModdedToggleOptionListAttribute(string title) + : this(title, "On", "Off") + { + } + internal override IModdedOptionList CreateOptionList(IList value, PropertyInfo property) { var optList = new ModdedOptionList( - value.Count, idx => new(GetFormattedTitle(idx), (bool)(value[idx] ?? false))); + value.Count, idx => new(GetFormattedTitle(idx), (bool)(value[idx] ?? false), on, off)); return optList; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index 627245a..a0759c6 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -12,9 +12,35 @@ namespace MiraAPI.GameOptions.OptionTypes; public class ModdedToggleOption : ModdedOption { /// - /// Gets or sets the delegate that dictates how a toggle option's value is displayed. + /// Gets or sets the display value when the option is toggled on. /// - public Func DisplayValue { get; set; } = value => value ? "On" : "Off"; + public string OnValue { get; set; } + + /// + /// Gets or sets the display value when the option is toggled off. + /// + public string OffValue { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The option title. + /// The default value. + /// What the option displays when toggled on. + /// What the option displays when toggled off. + /// Whether to include this option in the preset or not. + public ModdedToggleOption(string title, bool defaultValue, string on, string off, bool includeInPreset = true) + : base(title, defaultValue, includeInPreset) + { + OnValue = on; + OffValue = off; + + var data = ScriptableObject.CreateInstance(); + data.Title = StringName; + data.Type = global::OptionTypes.Checkbox; + + Data = data; + } /// /// Initializes a new instance of the class. @@ -23,13 +49,8 @@ public class ModdedToggleOption : ModdedOption /// The default value. /// Whether to include this option in the preset or not. public ModdedToggleOption(string title, bool defaultValue, bool includeInPreset = true) - : base(title, defaultValue, includeInPreset) + : this(title, defaultValue, "On", "Off", includeInPreset) { - var data = ScriptableObject.CreateInstance(); - data.Title = StringName; - data.Type = global::OptionTypes.Checkbox; - - Data = data; } /// @@ -81,7 +102,7 @@ public class ModdedToggleOption : ModdedOption ModdedOptionsManager.AddSettingsChangeMessage( HudManager.Instance.Notifier, StringName, - DisplayValue(newValue).Translate(), + (newValue ? OnValue : OffValue).Translate(), Configuration.PopUpTextColor, Configuration.PopUpIconTmp, false); diff --git a/MiraAPI/Resources/Locale/en_US.xml b/MiraAPI/Resources/Locale/en_US.xml index 3cff5f4..ed67fd2 100644 --- a/MiraAPI/Resources/Locale/en_US.xml +++ b/MiraAPI/Resources/Locale/en_US.xml @@ -66,4 +66,12 @@ Outlive the timer or eliminate the crew. Previous Next No Results Found + On + Off + Enabled + Disabled + Active + Inactive + Activated + Deactivated