Skip to content

Commit

Permalink
Completely fix dropdowns and sliders again
Browse files Browse the repository at this point in the history
  • Loading branch information
cheese3660 committed Jan 4, 2024
1 parent 26df719 commit 99b2e46
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/SpaceWarp.Core/API/Configuration/BepInExConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public IConfigEntry Bind<T>(
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);
}

/// <inheritdoc />
Expand Down
4 changes: 2 additions & 2 deletions src/SpaceWarp.Core/API/Configuration/IValueConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<>))
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/SpaceWarp.UI/API/UI/Settings/ModsPropertyDrawers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,15 @@ private static Func<string, IConfigEntry, GameObject> 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<>) &&
t.GenericTypeArguments[0] == entrySettingType)
{
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);
Expand Down Expand Up @@ -753,6 +753,10 @@ private static GameObject CreateStringConfig(ConfigEntryBase entryBase)

private static GameObject CreateStringConfigAbstracted(string name, IConfigEntry entry)
{
if (entry.Constraint is ListConstraint<string> constraint)
{
return CreateFromListConstraint(name, entry, constraint);
}
var inputFieldCopy = UnityObject.Instantiate(InputFieldPrefab);
var lab = inputFieldCopy.GetChild("Label");
lab.GetComponent<Localize>().SetTerm(name);
Expand Down

0 comments on commit 99b2e46

Please sign in to comment.