mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
abstract away string option code
and also make the behaviour in line with base game handling
This commit is contained in:
5 files changed
+161
-272
No files matched your search
@@ -39,7 +39,6 @@ public static class ModdedOptionsManager
|
||||
private static readonly Dictionary<Type, HarmonyMethod> ConcretisedSetters = [];
|
||||
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedPlayerOption> CreatedPlayerOptions = [];
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedStringOption> CreatedStringOptions = [];
|
||||
internal static readonly Dictionary<Type, List<AbstractOptionGroup>> GameModeOptionGroups = [];
|
||||
internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = [];
|
||||
internal static readonly List<AbstractOptionGroup> Groups = [];
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
/// <summary>
|
||||
/// A base class for modded options that utilize a string-based interface.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The underlying option type.</typeparam>
|
||||
/// <param name="groupPrefix">The translation ID prefix of the group containing this option.</param>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public abstract class ModdedBaseStringOption<T>(string groupPrefix, string title, T defaultValue, bool includeInPreset = true)
|
||||
: ModdedOption<T>(groupPrefix, title, defaultValue, includeInPreset)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the string values of the option.
|
||||
/// </summary>
|
||||
public string[] Values { get; protected set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the underlying values of the option.
|
||||
/// </summary>
|
||||
public T[] UnderlyingValues { get; protected set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the String Name values of the option.
|
||||
/// </summary>
|
||||
public StringNames[] StringNameValues { get; protected set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the option type name used for naming the generated GameObject.
|
||||
/// </summary>
|
||||
protected abstract string OptionTypeName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the common StringGameSetting data for this option.
|
||||
/// </summary>
|
||||
/// <param name="defaultIndex">The default index to assign.</param>
|
||||
protected void InitializeData(int defaultIndex)
|
||||
{
|
||||
var data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = StringNameValues;
|
||||
data.Index = defaultIndex;
|
||||
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of a specific value.
|
||||
/// </summary>
|
||||
/// <param name="value">The option's value.</param>
|
||||
/// <returns>The index of the value in the underlying array.</returns>
|
||||
public int GetIndex(T value)
|
||||
{
|
||||
var index = Array.IndexOf(UnderlyingValues, value);
|
||||
|
||||
if (index == -1)
|
||||
Info($"Cannot find a valid index for {value}. Returning -1 instead. Values: {string.Join(", ", Values)}");
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
stringOption.name = $"{ParentMod!.OptionsTitleText}.{OptionTypeName}.{Title}";
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// Changing the button text to make them more distinct from number options
|
||||
stringOption.MinusBtn.ChangeButtonText("<");
|
||||
stringOption.PlusBtn.ChangeButtonText(">");
|
||||
|
||||
// SetUpFromData method doesn't work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = StringNameValues;
|
||||
stringOption.Value = GetIndex(Value);
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
|
||||
return stringOption;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(T newValue)
|
||||
{
|
||||
if (OptionBehaviour && OptionBehaviour is StringOption opt)
|
||||
{
|
||||
opt.Value = GetIndex(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetDisplayValue()
|
||||
{
|
||||
var index = GetIndex(Value);
|
||||
return (uint)index < (uint)StringNameValues.Length
|
||||
? TranslationController.Instance.GetString(StringNameValues[index])
|
||||
: Value!.ToString()!;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetFloatData()
|
||||
{
|
||||
return GetIndex(Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override T GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
||||
{
|
||||
var index = optionBehaviour.GetInt();
|
||||
|
||||
if ((uint)index < (uint)UnderlyingValues.Length)
|
||||
return UnderlyingValues[index];
|
||||
|
||||
return UnderlyingValues.Length > 0 ? UnderlyingValues[0] : default!;
|
||||
}
|
||||
}
|
||||
@@ -4,29 +4,30 @@ using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Translation;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
/// <summary>
|
||||
/// The base class for enum options. Exists mainly to get rid of an abstract implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the value.</typeparam>
|
||||
/// <param name="groupPrefix">The translation ID prefix of the group containing this option.</param>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="defaultValue">The default value as an int.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public abstract class ModdedBaseEnumOption<T>(string groupPrefix, string title, T defaultValue, bool includeInPreset = true)
|
||||
: ModdedBaseStringOption<T>(groupPrefix, title, defaultValue, includeInPreset)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override string OptionTypeName => "EnumOption";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An option for selecting an <see langword="enum"/> value.
|
||||
/// </summary>
|
||||
[Obsolete("Use ModdedEnumOption<T> instead. This will be removed in a future version.")]
|
||||
public class ModdedEnumOption : ModdedOption<int>
|
||||
public class ModdedEnumOption : ModdedBaseEnumOption<int>
|
||||
{
|
||||
private readonly int[] underlyingValues;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string values of the enum.
|
||||
/// </summary>
|
||||
public string[] Values { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the String Name values of the option.
|
||||
/// </summary>
|
||||
public StringNames[] StringNameValues { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedEnumOption"/> class.
|
||||
/// </summary>
|
||||
@@ -41,22 +42,15 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
: base(groupPrefix, title, defaultValue, includeInPreset)
|
||||
{
|
||||
var rawValues = Enum.GetValues(enumType);
|
||||
underlyingValues = new int[rawValues.Length];
|
||||
UnderlyingValues = new int[rawValues.Length];
|
||||
|
||||
for (var i = 0; i < rawValues.Length; i++)
|
||||
underlyingValues[i] = Convert.ToInt32(rawValues.GetValue(i), NumberFormatInfo.InvariantInfo);
|
||||
UnderlyingValues[i] = Convert.ToInt32(rawValues.GetValue(i), NumberFormatInfo.InvariantInfo);
|
||||
|
||||
Values = values ?? Enum.GetNames(enumType);
|
||||
|
||||
StringNameValues = [.. Values.Select(x => MiraLocaleManager.GetOrCreateLocaleString($"{idPrefix}{x}"))];
|
||||
|
||||
var data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = StringNameValues;
|
||||
data.Index = Array.IndexOf(underlyingValues, defaultValue);
|
||||
|
||||
Data = data;
|
||||
InitializeData(GetIndex(defaultValue));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,39 +94,10 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
stringOption.name = $"{ParentMod!.OptionsTitleText}.EnumOption.{Title}";
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// Changing the button text to make them more distinct from number options
|
||||
stringOption.MinusBtn.ChangeButtonText("<");
|
||||
stringOption.PlusBtn.ChangeButtonText(">");
|
||||
|
||||
// SetUpFromData method doesn't work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = StringNameValues;
|
||||
stringOption.Value = Array.IndexOf(underlyingValues, Value);
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
|
||||
return stringOption;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetFloatData()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override NetData GetNetData()
|
||||
{
|
||||
return new NetData(Id, BitConverter.GetBytes(Value));
|
||||
return new(Id, BitConverter.GetBytes(Value));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -140,57 +105,15 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
{
|
||||
SetValue(BitConverter.ToInt32(data));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
||||
{
|
||||
var index = optionBehaviour.GetInt();
|
||||
|
||||
if (index >= 0 && index < underlyingValues.Length)
|
||||
return underlyingValues[index];
|
||||
|
||||
return underlyingValues.Length > 0 ? underlyingValues[0] : 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(int newValue)
|
||||
{
|
||||
if (OptionBehaviour && OptionBehaviour is StringOption opt)
|
||||
{
|
||||
opt.Value = Array.IndexOf(underlyingValues, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An option for selecting an <see langword="enum"/> value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The <see cref="Enum"/> type.</typeparam>
|
||||
public class ModdedEnumOption<T> : ModdedOption<T>
|
||||
public class ModdedEnumOption<T> : ModdedBaseEnumOption<T>
|
||||
where T : struct, Enum
|
||||
{
|
||||
private readonly T[] underlyingValues;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string values of the <see langword="enum"/>.
|
||||
/// </summary>
|
||||
public string[] Values { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the String Name values of the option.
|
||||
/// </summary>
|
||||
public StringNames[] StringNameValues { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedEnumOption{T}"/> class.
|
||||
/// </summary>
|
||||
@@ -203,18 +126,11 @@ public class ModdedEnumOption<T> : ModdedOption<T>
|
||||
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, string idPrefix, string[]? values = null, bool includeInPreset = true)
|
||||
: base(groupPrefix, title, defaultValue, includeInPreset)
|
||||
{
|
||||
underlyingValues = Enum.GetValues<T>();
|
||||
|
||||
UnderlyingValues = Enum.GetValues<T>();
|
||||
Values = values ?? Enum.GetNames<T>();
|
||||
StringNameValues = [.. Values.Select(x => MiraLocaleManager.GetOrCreateLocaleString($"{idPrefix}{x}"))];
|
||||
|
||||
var data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = StringNameValues;
|
||||
data.Index = Array.IndexOf(underlyingValues, defaultValue);
|
||||
|
||||
Data = data;
|
||||
InitializeData(GetIndex(defaultValue));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -255,41 +171,12 @@ public class ModdedEnumOption<T> : ModdedOption<T>
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
stringOption.name = $"{ParentMod!.OptionsTitleText}.EnumOption.{Title}";
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// Changing the button text to make them more distinct from number options
|
||||
stringOption.MinusBtn.ChangeButtonText("<");
|
||||
stringOption.PlusBtn.ChangeButtonText(">");
|
||||
|
||||
// SetUpFromData method doesn't work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = StringNameValues;
|
||||
stringOption.Value = Array.IndexOf(underlyingValues, Value);
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
|
||||
return stringOption;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetFloatData()
|
||||
{
|
||||
return Convert.ToSingle(Value, NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override NetData GetNetData()
|
||||
{
|
||||
var buffer = new byte[Unsafe.SizeOf<T>()];
|
||||
Unsafe.WriteUnaligned(ref buffer[0], Value);
|
||||
return new NetData(Id, buffer);
|
||||
return new(Id, buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -297,34 +184,4 @@ public class ModdedEnumOption<T> : ModdedOption<T>
|
||||
{
|
||||
SetValue(Unsafe.ReadUnaligned<T>(ref data[0]));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override T GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
||||
{
|
||||
var index = optionBehaviour.GetInt();
|
||||
|
||||
if (index >= 0 && index < underlyingValues.Length)
|
||||
return underlyingValues[index];
|
||||
|
||||
return underlyingValues.Length > 0 ? underlyingValues[0] : default;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(T newValue)
|
||||
{
|
||||
if (OptionBehaviour && OptionBehaviour is StringOption opt)
|
||||
{
|
||||
opt.Value = Array.IndexOf(underlyingValues, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetDisplayValue()
|
||||
{
|
||||
var index = Array.IndexOf(underlyingValues, Value);
|
||||
|
||||
return (uint)index >= (uint)StringNameValues.Length
|
||||
? TranslationController.Instance.GetString(StringNameValues[index])
|
||||
: Value.ToString();
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,18 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Translation;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
/// <summary>
|
||||
/// An option for selecting an enum value.
|
||||
/// An option for selecting a string value from a predefined list.
|
||||
/// </summary>
|
||||
public class ModdedStringOption : ModdedOption<string>
|
||||
public class ModdedStringOption : ModdedBaseStringOption<string>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the string values of the option.
|
||||
/// </summary>
|
||||
public string[] Values { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the String Name values of the option.
|
||||
/// </summary>
|
||||
public StringNames[] StringNameValues { get; set; }
|
||||
/// <inheritdoc />
|
||||
protected override string OptionTypeName => "StringOption";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModdedStringOption"/> class.
|
||||
@@ -37,15 +27,10 @@ public class ModdedStringOption : ModdedOption<string>
|
||||
: base(groupPrefix, title, defaultValue, includeInPreset)
|
||||
{
|
||||
Values = values;
|
||||
UnderlyingValues = values;
|
||||
StringNameValues = [.. values.Select(MiraLocaleManager.GetOrCreateLocaleString)];
|
||||
|
||||
var data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = StringNameValues;
|
||||
data.Index = GetIndex(Value);
|
||||
|
||||
Data = data;
|
||||
InitializeData(GetIndex(defaultValue));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,23 +46,7 @@ public class ModdedStringOption : ModdedOption<string>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string's index.
|
||||
/// </summary>
|
||||
/// <param name="value">The option's string value.</param>
|
||||
/// <returns>The option's value in the index.</returns>
|
||||
public int GetIndex(string value)
|
||||
{
|
||||
if (Values.Contains(value))
|
||||
{
|
||||
return Array.IndexOf(Values, value);
|
||||
}
|
||||
|
||||
Info($"Cannot find a valid index for {value}. Returning -1 instead. Values: {string.Join(", ", Values)}");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a value to the option.
|
||||
/// Adds a value to the option dynamically.
|
||||
/// </summary>
|
||||
/// <param name="value">The option's string value.</param>
|
||||
/// <param name="index">The additional value's index on the list.</param>
|
||||
@@ -91,6 +60,8 @@ public class ModdedStringOption : ModdedOption<string>
|
||||
var newVals = Values.ToList();
|
||||
newVals.Insert(index, value);
|
||||
Values = [.. newVals];
|
||||
UnderlyingValues = Values;
|
||||
|
||||
var newStrVals = StringNameValues.ToList();
|
||||
newStrVals.Insert(index, MiraLocaleManager.GetOrCreateLocaleString(value));
|
||||
StringNameValues = [.. newStrVals];
|
||||
@@ -98,7 +69,6 @@ public class ModdedStringOption : ModdedOption<string>
|
||||
|
||||
if (Data == null)
|
||||
{
|
||||
Error("Data is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,57 +76,20 @@ public class ModdedStringOption : ModdedOption<string>
|
||||
data.Values = StringNameValues;
|
||||
data.Index = GetIndex(Value);
|
||||
|
||||
Warning("Data is valid");
|
||||
|
||||
if (OptionBehaviour == null)
|
||||
{
|
||||
Error("OptionBehaviour is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
var strOpt = OptionBehaviour.TryCast<StringOption>();
|
||||
|
||||
Warning("OptionBehaviour is valid");
|
||||
|
||||
if (strOpt == null)
|
||||
{
|
||||
Error("StringOption is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
strOpt.Values = StringNameValues;
|
||||
strOpt.Value = GetIndex(Value);
|
||||
Warning("StringOption is valid");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var stringOption = Object.Instantiate(stringOpt, container);
|
||||
stringOption.name = $"{ParentMod!.OptionsTitleText}.StringOption.{Title}";
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// Changing the button text to make them more distinct from number options
|
||||
stringOption.MinusBtn.ChangeButtonText("<");
|
||||
stringOption.PlusBtn.ChangeButtonText(">");
|
||||
|
||||
// SetUpFromData method doesn't work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = (Data as StringGameSetting)?.Values ?? new Il2CppStructArray<StringNames>(0);
|
||||
stringOption.Value = GetIndex(Value);
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
ModdedOptionsManager.CreatedStringOptions.TryAdd(stringOption, this);
|
||||
|
||||
return stringOption;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override float GetFloatData()
|
||||
{
|
||||
return Array.IndexOf(Values, Value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -170,29 +103,4 @@ public class ModdedStringOption : ModdedOption<string>
|
||||
{
|
||||
SetValue(Encoding.Unicode.GetString(data));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
||||
{
|
||||
return Values[optionBehaviour.GetInt()];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnValueChanged(string newValue)
|
||||
{
|
||||
if (OptionBehaviour && OptionBehaviour is StringOption opt)
|
||||
{
|
||||
opt.Value = GetIndex(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string GetDisplayValue()
|
||||
{
|
||||
var index = Array.IndexOf(Values, Value);
|
||||
|
||||
return (uint)index >= (uint)StringNameValues.Length
|
||||
? TranslationController.Instance.GetString(StringNameValues[index])
|
||||
: Value;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
protected int TabIndex => LocalSettingsManager.Tabs.IndexOf(this) + 10;
|
||||
|
||||
private Scroller? scroller;
|
||||
private float MaxScroll { get; set; }
|
||||
private float maxScroll;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when an option value is changed.
|
||||
@@ -115,7 +115,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
return;
|
||||
}
|
||||
|
||||
scroller.SetBounds(new FloatRange(0, MaxScroll), new FloatRange(0, 0));
|
||||
scroller.SetBounds(new FloatRange(0, maxScroll), new FloatRange(0, 0));
|
||||
scroller.ScrollToTop();
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
const float extraPadding = 0.25f;
|
||||
var itemRange = (Settings.Count + Buttons.Count) * 0.5f - visibleHeight;
|
||||
var offsetRange = contentOffset - visibleHeight + extraPadding;
|
||||
MaxScroll = Mathf.Max(0f, itemRange, offsetRange);
|
||||
maxScroll = Mathf.Max(0f, itemRange, offsetRange);
|
||||
return tab;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user