diff --git a/MiraAPI.Example/Options/ExampleOptions.cs b/MiraAPI.Example/Options/ExampleOptions.cs index 9e9fa59..53bc9eb 100644 --- a/MiraAPI.Example/Options/ExampleOptions.cs +++ b/MiraAPI.Example/Options/ExampleOptions.cs @@ -16,7 +16,7 @@ public class ExampleOptions : AbstractOptionGroup [ModdedToggleOption("Toggle Opt 2")] public bool ToggleOpt2 { get; set; } = true; - [ModdedNumberOption("Number Opt", min: 0, max: 10, suffixType: MiraNumberSuffixes.Percent)] + [ModdedNumberOption("Number Opt", min: 0, max: 10, increment: .25f, formatString: "0.00", suffixType: MiraNumberSuffixes.Percent)] public float NumberOpt { get; set; } = 4f; [ModdedEnumOption("Best API", typeof(BestApi), ["Mira API", "Mitochondria", "Reactor"])] diff --git a/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs index 2bd4438..b7b85c2 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedNumberOptionAttribute.cs @@ -15,13 +15,14 @@ public class ModdedNumberOptionAttribute( float max, float increment = 1, MiraNumberSuffixes suffixType = MiraNumberSuffixes.None, + string? formatString = null, bool zeroInfinity = false, Type? roleType = null) : ModdedOptionAttribute(title, roleType) { internal override IModdedOption CreateOption(object? value, PropertyInfo property) { - return new ModdedNumberOption(Title, (float)(value ?? min+increment), min, max, increment, suffixType, zeroInfinity, RoleType); + return new ModdedNumberOption(Title, (float)(value ?? min+increment), min, max, increment, suffixType, formatString, zeroInfinity, RoleType); } /// diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index 24cd346..deb8052 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -46,6 +46,7 @@ public class ModdedNumberOption : ModdedOption /// The maximum value. /// The increment. /// The suffix type. + /// Optional format string for the option screen. /// Whether zero is infinity or not. /// An optional role type. public ModdedNumberOption( @@ -55,6 +56,7 @@ public class ModdedNumberOption : ModdedOption float max, float increment, MiraNumberSuffixes suffixType, + string? formatString = null, bool zeroInfinity = false, Type? roleType = null) : base(title, defaultValue, roleType) { @@ -74,7 +76,13 @@ public class ModdedNumberOption : ModdedOption data.Value = Value; data.Increment = Increment; data.ValidRange = new FloatRange(Min, Max); - data.FormatString = Increment % 1 == 0 && Value % 1 == 0 && Min % 1 == 0 && Max % 1 == 0 ? "0" : "0.0"; // not sure if the == checks will work since this is floats but we'll find out + data.FormatString = formatString ?? + (!Mathf.Approximately(defaultValue, 0) || + !Mathf.Approximately(Increment % 1, 0) || + !Mathf.Approximately(Value % 1, 0) || + !Mathf.Approximately(Min % 1, 0) || + !Mathf.Approximately(Max % 1, 0) ? "0.0" : "0"); + data.ZeroIsInfinity = ZeroInfinity; data.SuffixType = (NumberSuffixes)SuffixType; data.OptionName = FloatOptionNames.Invalid;