Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Celeste.Mod.mm/Mod/Module/EverestModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,16 @@ TextMenu.Item CreateItem(PropertyInfo prop, string name = null, object settingsO
);
});
}
else if (propType.IsEnum)
{
else if (propType.IsEnum) {
Array enumValues = Enum.GetValues(propType);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we .distinct() it first?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on how we want to handle that case. I'd say it is not really beneficial to eliminate duplicate values since having indistinguishable enum values does not make much sense in an enum for configuration. Thus we shouldn't handle that case.

Array.Sort((int[]) enumValues);
Array.Sort(enumValues);
int valueIndex = 0; // Default to the first option if the value is not found
for (int i = 0; i < enumValues.Length; i++) {
if (enumValues.GetValue(i).Equals(value)) {
valueIndex = i;
Comment thread
Wartori54 marked this conversation as resolved.
break;
}
}
string enumNamePrefix = $"{nameDefaultPrefix}{prop.Name.ToLowerInvariant()}_";
item =
new TextMenu.Slider(name, (i) => {
Expand All @@ -758,8 +764,8 @@ TextMenu.Item CreateItem(PropertyInfo prop, string name = null, object settingsO
$"{enumNamePrefix}{enumName.ToLowerInvariant()}".DialogCleanOrNull() ??
$"modoptions_{propType.Name.ToLowerInvariant()}_{enumName.ToLowerInvariant()}".DialogCleanOrNull() ??
enumName;
}, 0, enumValues.Length - 1, (int) value)
.Change(v => prop.SetValue(settingsObject, v));
}, 0, enumValues.Length - 1, valueIndex)
.Change(v => prop.SetValue(settingsObject, enumValues.GetValue(v)));
}
else if (propType == typeof(string))
{
Expand Down
Loading