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="min">The minimum value.</param>
|
||||||
/// <param name="max">The maximum value.</param>
|
/// <param name="max">The maximum value.</param>
|
||||||
/// <param name="increment">The increment.</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="suffixType">The suffix type.</param>
|
||||||
/// <param name="formatString">Optional format string for the option screen.</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)]
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
public class ModdedNumberOptionAttribute(
|
public class ModdedNumberOptionAttribute(
|
||||||
string title,
|
string title,
|
||||||
float min,
|
float min,
|
||||||
float max,
|
float max,
|
||||||
float increment = 1,
|
float increment,
|
||||||
|
string zeroBehavior,
|
||||||
|
string negativeBehavior,
|
||||||
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None,
|
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None,
|
||||||
string? formatString = null,
|
string? formatString = null,
|
||||||
bool zeroInfinity = false)
|
bool halfIncrements = false)
|
||||||
: ModdedOptionAttribute(title)
|
: 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)
|
internal override IModdedOption CreateOption(object? value, PropertyInfo property)
|
||||||
{
|
{
|
||||||
var final = value switch
|
var final = value switch
|
||||||
@@ -41,9 +67,11 @@ public class ModdedNumberOptionAttribute(
|
|||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
increment,
|
increment,
|
||||||
|
zeroBehavior,
|
||||||
|
negativeBehavior,
|
||||||
suffixType,
|
suffixType,
|
||||||
formatString,
|
formatString,
|
||||||
zeroInfinity);
|
halfIncrements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -8,12 +8,27 @@ namespace MiraAPI.GameOptions.Attributes;
|
|||||||
/// Attribute for a <see cref="ModdedToggleOption"/>.
|
/// Attribute for a <see cref="ModdedToggleOption"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="title">The option title.</param>
|
/// <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)]
|
[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)
|
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;
|
return toggleOpt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,20 +13,46 @@ namespace MiraAPI.GameOptions.Attributes;
|
|||||||
/// <param name="min">The minimum value.</param>
|
/// <param name="min">The minimum value.</param>
|
||||||
/// <param name="max">The maximum value.</param>
|
/// <param name="max">The maximum value.</param>
|
||||||
/// <param name="increment">The increment.</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="suffixType">The suffix type.</param>
|
||||||
/// <param name="formatString">Optional format string for the option screen.</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)]
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
public class ModdedNumberOptionListAttribute(
|
public class ModdedNumberOptionListAttribute(
|
||||||
string title,
|
string title,
|
||||||
float min,
|
float min,
|
||||||
float max,
|
float max,
|
||||||
float increment = 1,
|
float increment,
|
||||||
|
string zeroBehavior,
|
||||||
|
string negativeBehavior,
|
||||||
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None,
|
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None,
|
||||||
string? formatString = null,
|
string? formatString = null,
|
||||||
bool zeroInfinity = false)
|
bool halfIncrements = false)
|
||||||
: ModdedOptionListAttribute(title)
|
: 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)
|
internal override IModdedOptionList CreateOptionList(IList value, PropertyInfo property)
|
||||||
{
|
{
|
||||||
return new ModdedOptionList<ModdedNumberOption>(value.Count, idx =>
|
return new ModdedOptionList<ModdedNumberOption>(value.Count, idx =>
|
||||||
@@ -44,9 +70,11 @@ public class ModdedNumberOptionListAttribute(
|
|||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
increment,
|
increment,
|
||||||
|
zeroBehavior,
|
||||||
|
negativeBehavior,
|
||||||
suffixType,
|
suffixType,
|
||||||
formatString,
|
formatString,
|
||||||
zeroInfinity);
|
halfIncrements);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,28 @@ namespace MiraAPI.GameOptions.Attributes;
|
|||||||
/// Attribute for a list of toggle options.
|
/// Attribute for a list of toggle options.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="title">The option's title.</param>
|
/// <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)]
|
[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)
|
internal override IModdedOptionList CreateOptionList(IList value, PropertyInfo property)
|
||||||
{
|
{
|
||||||
var optList = new ModdedOptionList<ModdedToggleOption>(
|
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;
|
return optList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,35 @@ namespace MiraAPI.GameOptions.OptionTypes;
|
|||||||
public class ModdedToggleOption : ModdedOption<bool>
|
public class ModdedToggleOption : ModdedOption<bool>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ModdedToggleOption"/> class.
|
/// 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="defaultValue">The default value.</param>
|
||||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||||
public ModdedToggleOption(string title, bool defaultValue, bool includeInPreset = true)
|
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 />
|
/// <inheritdoc />
|
||||||
@@ -81,7 +102,7 @@ public class ModdedToggleOption : ModdedOption<bool>
|
|||||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||||
HudManager.Instance.Notifier,
|
HudManager.Instance.Notifier,
|
||||||
StringName,
|
StringName,
|
||||||
DisplayValue(newValue).Translate(),
|
(newValue ? OnValue : OffValue).Translate(),
|
||||||
Configuration.PopUpTextColor,
|
Configuration.PopUpTextColor,
|
||||||
Configuration.PopUpIconTmp,
|
Configuration.PopUpIconTmp,
|
||||||
false);
|
false);
|
||||||
|
|||||||
@@ -66,4 +66,12 @@ Outlive the timer or eliminate the crew.</string>
|
|||||||
<string name="MiraApi.Wiki.PreviousPage">Previous</string>
|
<string name="MiraApi.Wiki.PreviousPage">Previous</string>
|
||||||
<string name="MiraApi.Wiki.NextPage">Next</string>
|
<string name="MiraApi.Wiki.NextPage">Next</string>
|
||||||
<string name="MiraApi.Wiki.NoResultsFound">No Results Found</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>
|
</resources>
|
||||||
Reference in new issue
Block a user