mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
make number options accept floats
This commit is contained in:
1 parent
ac113b6a7f
commit
ebdb4a09ca
4 files changed
+18
-16
No files matched your search
@@ -2,7 +2,6 @@
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.LocalSettings.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
@@ -30,8 +29,11 @@ public class ExampleLocalSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
[LocalSliderSetting(suffixType: MiraNumberSuffixes.Percent, formatString: "0", roundValue: true)]
|
||||
public ConfigEntry<float> ExampleSlider { get; private set; } = config.Bind("General", "Slider", 50f);
|
||||
|
||||
[LocalNumberSetting(suffixType: MiraNumberSuffixes.Seconds)]
|
||||
public ConfigEntry<int> ExampleNumber { get; private set; } = config.Bind("General", "Example Number", 4);
|
||||
[LocalNumberSetting]
|
||||
public ConfigEntry<float> ExampleNumber { get; private set; } = config.Bind("General", "Example Number", 4f);
|
||||
|
||||
[LocalNumberSetting(min: 0.1f, max: 2.5f, increment: 0.1f, formatString: "0.0", suffixType: MiraNumberSuffixes.Multiplier)]
|
||||
public ConfigEntry<float> ExampleFloatNumber { get; private set; } = config.Bind("General", "Example Multplier", 1f);
|
||||
|
||||
[LocalEnumSetting]
|
||||
public ConfigEntry<ExampleEnumSetting> ExampleEnum { get; private set; } = config.Bind("General", "Example Enum", ExampleEnumSetting.Fries);
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace MiraAPI.LocalSettings.Attributes;
|
||||
public class LocalNumberSettingAttribute(
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
int min = 1,
|
||||
int max = 5,
|
||||
int increment = 1,
|
||||
float min = 1,
|
||||
float max = 5,
|
||||
float increment = 1,
|
||||
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None,
|
||||
string? formatString = null
|
||||
) : LocalSettingAttribute(name, description)
|
||||
@@ -28,6 +28,6 @@ public class LocalNumberSettingAttribute(
|
||||
/// <inheritdoc/>
|
||||
internal override LocalNumberSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase)
|
||||
{
|
||||
return new LocalNumberSetting(tab, configEntryBase, name, description, new IntRange(min, max), increment, suffixType, formatString);
|
||||
return new LocalNumberSetting(tab, configEntryBase, name, description, new FloatRange(min, max), increment, suffixType, formatString);
|
||||
}
|
||||
}
|
||||
@@ -12,17 +12,17 @@ namespace MiraAPI.LocalSettings.SettingTypes;
|
||||
/// <summary>
|
||||
/// Local setting class for numbers.
|
||||
/// </summary>
|
||||
public class LocalNumberSetting : LocalSettingBase<int>
|
||||
public class LocalNumberSetting : LocalSettingBase<float>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the range of the button.
|
||||
/// </summary>
|
||||
public IntRange NumberRange { get; }
|
||||
public FloatRange NumberRange { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the increment of the value when button is pressed.
|
||||
/// </summary>
|
||||
public int Increment { get; }
|
||||
public float Increment { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a format for the text to use to format the number.
|
||||
@@ -47,14 +47,14 @@ public class LocalNumberSetting : LocalSettingBase<int>
|
||||
ConfigEntryBase configEntry,
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
IntRange? numberRange = null,
|
||||
int? increment = null,
|
||||
FloatRange? numberRange = null,
|
||||
float? increment = null,
|
||||
MiraNumberSuffixes? suffixType = null,
|
||||
string? formatString = null)
|
||||
: base(tab, configEntry, name, description)
|
||||
{
|
||||
SuffixType = suffixType ?? MiraNumberSuffixes.None;
|
||||
NumberRange = numberRange ?? new IntRange(1, 5);
|
||||
NumberRange = numberRange ?? new FloatRange(1, 5);
|
||||
Increment = increment ?? 1;
|
||||
FormatString = formatString ?? "0";
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class LocalNumberSetting : LocalSettingBase<int>
|
||||
|
||||
button.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
int value = GetValue();
|
||||
float value = GetValue();
|
||||
value += Increment;
|
||||
if (value > NumberRange.max)
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ public abstract class LocalSettingBase<T> : ILocalSetting
|
||||
/// Gets the value of the config entry, casted to the setting type.
|
||||
/// </summary>
|
||||
/// <returns>The value.</returns>
|
||||
public T GetValue()
|
||||
public virtual T GetValue()
|
||||
{
|
||||
return (T)ConfigEntry.BoxedValue;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public abstract class LocalSettingBase<T> : ILocalSetting
|
||||
/// Sets the value of the config entry.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to set to.</param>
|
||||
public void SetValue(T value)
|
||||
public virtual void SetValue(T value)
|
||||
{
|
||||
ConfigEntry.BoxedValue = value;
|
||||
Tab?.OnOptionChanged(ConfigEntry);
|
||||
|
||||
Reference in new issue
Block a user