diff --git a/MiraAPI/GameOptions/Attributes/OptionList/ModdedEnumOptionListAttribute.cs b/MiraAPI/GameOptions/Attributes/OptionList/ModdedEnumOptionListAttribute.cs
index 5eff07a4..539e8732 100644
--- a/MiraAPI/GameOptions/Attributes/OptionList/ModdedEnumOptionListAttribute.cs
+++ b/MiraAPI/GameOptions/Attributes/OptionList/ModdedEnumOptionListAttribute.cs
@@ -10,26 +10,49 @@ namespace MiraAPI.GameOptions.Attributes;
///
/// The title of the option.
/// The type.
+/// The common translation ID prefix of all enum values.
/// An option list of string values to use in place of the name.
[AttributeUsage(AttributeTargets.Property)]
[Obsolete("Use ModdedEnumOptionListAttribute instead. This will be removed in a future version.")]
-public class ModdedEnumOptionListAttribute(string? title, Type enumType, string[]? values = null)
+public class ModdedEnumOptionListAttribute(string? title, Type enumType, string idPrefix, string[]? values = null)
: ModdedOptionListAttribute(title)
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The title of the option.
+ /// The type.
+ /// An option list of string values to use in place of the name.
+ public ModdedEnumOptionListAttribute(string? title, Type enumType, string[]? values = null)
+ : this(title, enumType, string.Empty, values)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The type.
+ /// The common translation ID prefix of all enum values.
+ /// An option list of string values to use in place of the name.
+ public ModdedEnumOptionListAttribute(Type enumType, string idPrefix, string[]? values = null)
+ : this(null, enumType, idPrefix, values)
+ {
+ }
+
///
/// Initializes a new instance of the class.
///
/// The type.
/// An option list of string values to use in place of the name.
public ModdedEnumOptionListAttribute(Type enumType, string[]? values = null)
- : this(null, enumType, values)
+ : this(null, enumType, string.Empty, values)
{
}
internal override IModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
{
var optList = new ModdedOptionList(
- list.Count, idx => new(group.GroupPrefix, GetFormattedTitle(idx, property), (int)(list[idx] ?? 0), enumType, values));
+ list.Count, idx => new(group.GroupPrefix, GetFormattedTitle(idx, property), (int)(list[idx] ?? 0), enumType, idPrefix, values));
return optList;
}
diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs
index 22171b13..6c71a313 100644
--- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs
+++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs
@@ -160,6 +160,16 @@ public class ModdedEnumOption : ModdedOption
opt.Value = Array.IndexOf(underlyingValues, newValue);
}
}
+
+ ///
+ public override string GetDisplayValue()
+ {
+ var index = Array.IndexOf(underlyingValues, Value);
+
+ return (uint)index >= (uint)StringNameValues.Length
+ ? TranslationController.Instance.GetString(StringNameValues[index])
+ : Value.ToString(CultureInfo.InvariantCulture);
+ }
}
///
@@ -291,7 +301,12 @@ public class ModdedEnumOption : ModdedOption
///
public override T GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
{
- return Enum.Parse(optionBehaviour.GetInt().ToString(NumberFormatInfo.InvariantInfo));
+ var index = optionBehaviour.GetInt();
+
+ if (index >= 0 && index < underlyingValues.Length)
+ return underlyingValues[index];
+
+ return underlyingValues.Length > 0 ? underlyingValues[0] : default;
}
///
@@ -299,7 +314,17 @@ public class ModdedEnumOption : ModdedOption
{
if (OptionBehaviour && OptionBehaviour is StringOption opt)
{
- opt.Value = Convert.ToInt32(newValue, NumberFormatInfo.InvariantInfo);
+ opt.Value = Array.IndexOf(underlyingValues, newValue);
}
}
+
+ ///
+ public override string GetDisplayValue()
+ {
+ var index = Array.IndexOf(underlyingValues, Value);
+
+ return (uint)index >= (uint)StringNameValues.Length
+ ? TranslationController.Instance.GetString(StringNameValues[index])
+ : Value.ToString();
+ }
}
diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs
index e5479199..60573127 100644
--- a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs
+++ b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs
@@ -151,4 +151,13 @@ public class ModdedPlayerOption : ModdedOption
opt.Value = newValue;
}
}
+
+ ///
+ public override string GetDisplayValue()
+ {
+ var player = GetPlayerValue();
+ return player
+ ? TranslationController.Instance.GetString(StringNames.None)
+ : player!.PlayerName;
+ }
}
diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs
index 10ca7aaf..9aa6cfc7 100644
--- a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs
+++ b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs
@@ -185,4 +185,14 @@ public class ModdedStringOption : ModdedOption
opt.Value = GetIndex(newValue);
}
}
+
+ ///
+ public override string GetDisplayValue()
+ {
+ var index = Array.IndexOf(Values, Value);
+
+ return (uint)index >= (uint)StringNameValues.Length
+ ? TranslationController.Instance.GetString(StringNameValues[index])
+ : Value;
+ }
}