mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
constructor parity + scrap toggle display delegate
This commit is contained in:
6 files changed
+136
-21
No files matched your search
@@ -12,20 +12,46 @@ namespace MiraAPI.GameOptions.Attributes;
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <param name="increment">The increment.</param>
|
||||
/// <param name="zeroBehavior">Determines what is shown for zero.</param>
|
||||
/// <param name="negativeBehavior">Determines what is shown for negative 1.</param>
|
||||
/// <param name="suffixType">The suffix type.</param>
|
||||
/// <param name="formatString">Optional format string for the option screen.</param>
|
||||
/// <param name="zeroInfinity">Flag indicating whether 0 means infinity.</param>
|
||||
/// <param name="halfIncrements">Whether increments can be split in half (using Shift).</param>
|
||||
[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)
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedNumberOptionAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <param name="increment">The increment.</param>
|
||||
/// <param name="suffixType">The suffix type.</param>
|
||||
/// <param name="zeroInfinity">Whether zero is infinity or not.</param>
|
||||
/// <param name="formatString">Optional format string for the option screen.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -8,12 +8,27 @@ namespace MiraAPI.GameOptions.Attributes;
|
||||
/// Attribute for a <see cref="ModdedToggleOption"/>.
|
||||
/// </summary>
|
||||
/// <param name="title">The option title.</param>
|
||||
/// <param name="on">What the option displays when toggled on.</param>
|
||||
/// <param name="off">What the option displays when toggled off.</param>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ModdedToggleOptionAttribute(string title) : ModdedOptionAttribute(title)
|
||||
public class ModdedToggleOptionAttribute(
|
||||
string title,
|
||||
string on,
|
||||
string off)
|
||||
: ModdedOptionAttribute(title)
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedToggleOptionAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The option title.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,20 +13,46 @@ namespace MiraAPI.GameOptions.Attributes;
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <param name="increment">The increment.</param>
|
||||
/// <param name="zeroBehavior">Determines what is shown for zero.</param>
|
||||
/// <param name="negativeBehavior">Determines what is shown for negative 1.</param>
|
||||
/// <param name="suffixType">The suffix type.</param>
|
||||
/// <param name="formatString">Optional format string for the option screen.</param>
|
||||
/// <param name="zeroInfinity">Flag indicating whether 0 means infinity.</param>
|
||||
/// <param name="halfIncrements">Whether increments can be split in half (using Shift).</param>
|
||||
[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)
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedNumberOptionListAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="min">The minimum value.</param>
|
||||
/// <param name="max">The maximum value.</param>
|
||||
/// <param name="increment">The increment.</param>
|
||||
/// <param name="suffixType">The suffix type.</param>
|
||||
/// <param name="zeroInfinity">Whether zero is infinity or not.</param>
|
||||
/// <param name="formatString">Optional format string for the option screen.</param>
|
||||
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<ModdedNumberOption>(value.Count, idx =>
|
||||
@@ -44,9 +70,11 @@ public class ModdedNumberOptionListAttribute(
|
||||
min,
|
||||
max,
|
||||
increment,
|
||||
zeroBehavior,
|
||||
negativeBehavior,
|
||||
suffixType,
|
||||
formatString,
|
||||
zeroInfinity);
|
||||
halfIncrements);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,28 @@ namespace MiraAPI.GameOptions.Attributes;
|
||||
/// Attribute for a list of toggle options.
|
||||
/// </summary>
|
||||
/// <param name="title">The option's title.</param>
|
||||
/// <param name="on">What the option displays when toggled on.</param>
|
||||
/// <param name="off">What the option displays when toggled off.</param>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ModdedToggleOptionListAttribute(string title) : ModdedOptionListAttribute(title)
|
||||
public class ModdedToggleOptionListAttribute(
|
||||
string title,
|
||||
string on,
|
||||
string off)
|
||||
: ModdedOptionListAttribute(title)
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedToggleOptionListAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The option's title.</param>
|
||||
public ModdedToggleOptionListAttribute(string title)
|
||||
: this(title, "On", "Off")
|
||||
{
|
||||
}
|
||||
|
||||
internal override IModdedOptionList CreateOptionList(IList value, PropertyInfo property)
|
||||
{
|
||||
var optList = new ModdedOptionList<ModdedToggleOption>(
|
||||
value.Count, idx => new(GetFormattedTitle(idx), (bool)(value[idx] ?? false)));
|
||||
value.Count, idx => new(GetFormattedTitle(idx), (bool)(value[idx] ?? false), on, off));
|
||||
return optList;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,35 @@ namespace MiraAPI.GameOptions.OptionTypes;
|
||||
public class ModdedToggleOption : ModdedOption<bool>
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public Func<bool, string> DisplayValue { get; set; } = value => value ? "On" : "Off";
|
||||
public string OnValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the display value when the option is toggled off.
|
||||
/// </summary>
|
||||
public string OffValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedToggleOption"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The option title.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <param name="on">What the option displays when toggled on.</param>
|
||||
/// <param name="off">What the option displays when toggled off.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
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<CheckboxGameSetting>();
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.Checkbox;
|
||||
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedToggleOption"/> class.
|
||||
@@ -23,13 +49,8 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedToggleOption(string title, bool defaultValue, bool includeInPreset = true)
|
||||
: base(title, defaultValue, includeInPreset)
|
||||
: this(title, defaultValue, "On", "Off", includeInPreset)
|
||||
{
|
||||
var data = ScriptableObject.CreateInstance<CheckboxGameSetting>();
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.Checkbox;
|
||||
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -81,7 +102,7 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||
HudManager.Instance.Notifier,
|
||||
StringName,
|
||||
DisplayValue(newValue).Translate(),
|
||||
(newValue ? OnValue : OffValue).Translate(),
|
||||
Configuration.PopUpTextColor,
|
||||
Configuration.PopUpIconTmp,
|
||||
false);
|
||||
|
||||
@@ -66,4 +66,12 @@ Outlive the timer or eliminate the crew.</string>
|
||||
<string name="MiraApi.Wiki.PreviousPage">Previous</string>
|
||||
<string name="MiraApi.Wiki.NextPage">Next</string>
|
||||
<string name="MiraApi.Wiki.NoResultsFound">No Results Found</string>
|
||||
<string name="On">On</string>
|
||||
<string name="Off">Off</string>
|
||||
<string name="Enabled">Enabled</string>
|
||||
<string name="Disabled">Disabled</string>
|
||||
<string name="Active">Active</string>
|
||||
<string name="Inactive">Inactive</string>
|
||||
<string name="Activated">Activated</string>
|
||||
<string name="Deactivated">Deactivated</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user