From 99b2e46530a1ceb56f84c06934393142ef838de1 Mon Sep 17 00:00:00 2001 From: Lexi Date: Thu, 4 Jan 2024 09:39:17 -0500 Subject: [PATCH] Completely fix dropdowns and sliders again --- src/SpaceWarp.Core/API/Configuration/BepInExConfigFile.cs | 4 ++-- src/SpaceWarp.Core/API/Configuration/IValueConstraint.cs | 4 ++-- src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/SpaceWarp.Core/API/Configuration/BepInExConfigFile.cs b/src/SpaceWarp.Core/API/Configuration/BepInExConfigFile.cs index 64e9360..f519af3 100644 --- a/src/SpaceWarp.Core/API/Configuration/BepInExConfigFile.cs +++ b/src/SpaceWarp.Core/API/Configuration/BepInExConfigFile.cs @@ -61,8 +61,8 @@ public IConfigEntry Bind( IValueConstraint valueConstraint ) { - return new BepInExConfigEntry(AdaptedConfigFile.Bind(new ConfigDefinition(section, key), defaultValue, - new ConfigDescription(description, valueConstraint.ToAcceptableValueBase()))); + return _storedEntries[(section, key)] = new BepInExConfigEntry(AdaptedConfigFile.Bind(new ConfigDefinition(section, key), defaultValue, + new ConfigDescription(description, valueConstraint.ToAcceptableValueBase())),valueConstraint); } /// diff --git a/src/SpaceWarp.Core/API/Configuration/IValueConstraint.cs b/src/SpaceWarp.Core/API/Configuration/IValueConstraint.cs index f6f111e..b6f7882 100644 --- a/src/SpaceWarp.Core/API/Configuration/IValueConstraint.cs +++ b/src/SpaceWarp.Core/API/Configuration/IValueConstraint.cs @@ -36,7 +36,7 @@ public static IValueConstraint FromAcceptableValueBase(AcceptableValueBase accep .GetProperty("AcceptableValues", BindingFlags.Instance | BindingFlags.Public) ?.GetMethod; var values = valuesMethod?.Invoke(acceptableValueBase,[]); - return Activator.CreateInstance(typeof(ListConstraint<>).MakeGenericType(type), [values]) as IValueConstraint; + return (IValueConstraint)Activator.CreateInstance(typeof(ListConstraint<>).MakeGenericType(type), [values]); } if (acceptableValueBase.GetType().GetGenericTypeDefinition() == typeof(AcceptableValueRange<>)) @@ -48,7 +48,7 @@ public static IValueConstraint FromAcceptableValueBase(AcceptableValueBase accep .GetProperty("MaxValue", BindingFlags.Instance | BindingFlags.Public)?.GetMethod; var min = minMethod?.Invoke(acceptableValueBase, []); var max = maxMethod?.Invoke(acceptableValueBase, []); - return Activator.CreateInstance(typeof(RangeConstraint<>).MakeGenericType(type),[min,max]) as IValueConstraint; + return (IValueConstraint)Activator.CreateInstance(typeof(RangeConstraint<>).MakeGenericType(type),[min,max]); } return null; diff --git a/src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs b/src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs index 2132023..7a1ed44 100644 --- a/src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs +++ b/src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs @@ -383,7 +383,7 @@ private static Func GenerateAbstractGenericDra t.GenericTypeArguments[0] == entrySettingType) { if (valueListMethod != null) - return (GameObject)valueListMethod.Invoke(null, new object[] { name, entry, entry.Constraint }); + return (GameObject)valueListMethod.Invoke(null, [name, entry, entry.Constraint]); } if (t?.GetGenericTypeDefinition() == typeof(RangeConstraint<>) && @@ -391,7 +391,7 @@ private static Func GenerateAbstractGenericDra { if (valueRangeMethod != null) { - return (GameObject)valueRangeMethod.Invoke(null, new object[] { name, entry, entry.Constraint }); + return (GameObject)valueRangeMethod.Invoke(null, [name, entry, entry.Constraint]); } } var inputFieldCopy = UnityObject.Instantiate(InputFieldPrefab); @@ -753,6 +753,10 @@ private static GameObject CreateStringConfig(ConfigEntryBase entryBase) private static GameObject CreateStringConfigAbstracted(string name, IConfigEntry entry) { + if (entry.Constraint is ListConstraint constraint) + { + return CreateFromListConstraint(name, entry, constraint); + } var inputFieldCopy = UnityObject.Instantiate(InputFieldPrefab); var lab = inputFieldCopy.GetChild("Label"); lab.GetComponent().SetTerm(name);