fix: specify a fallback value for chat channel settings entry

This commit is contained in:
goat 2023-03-21 19:48:02 +01:00
parent ec0f52b7c3
commit ec4b5935d8
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
2 changed files with 13 additions and 2 deletions

View file

@ -27,7 +27,8 @@ public class SettingsTabGeneral : SettingsTab
return Loc.Localize("DalamudSettingsChannelNone", "Do not pick \"None\".");
return null;
}),
},
fallbackValue: XivChatType.Debug),
new GapSettingsEntry(5),

View file

@ -20,8 +20,10 @@ internal sealed class SettingsEntry<T> : SettingsEntry
private readonly Action<T?>? change;
private object? valueBacking;
private object? fallbackValue;
public SettingsEntry(string name, string description, LoadSettingDelegate load, SaveSettingDelegate save, Action<T?>? change = null, Func<T?, string?>? warning = null, Func<T?, string?>? validity = null, Func<bool>? visibility = null)
public SettingsEntry(string name, string description, LoadSettingDelegate load, SaveSettingDelegate save, Action<T?>? change = null, Func<T?, string?>? warning = null, Func<T?, string?>? validity = null, Func<bool>? visibility = null,
object? fallbackValue = null)
{
this.load = load;
this.save = save;
@ -31,6 +33,8 @@ internal sealed class SettingsEntry<T> : SettingsEntry
this.CheckWarning = warning;
this.CheckValidity = validity;
this.CheckVisibility = visibility;
this.fallbackValue = fallbackValue;
}
public delegate T? LoadSettingDelegate(DalamudConfiguration config);
@ -97,6 +101,12 @@ internal sealed class SettingsEntry<T> : SettingsEntry
var descriptions =
values.Cast<Enum>().ToDictionary(x => x, x => x.GetAttribute<SettingsAnnotationAttribute>() ?? new SettingsAnnotationAttribute(x.ToString(), string.Empty));
if (!descriptions.ContainsKey(idx))
{
idx = (Enum)this.fallbackValue ?? throw new Exception("No fallback value for enum");
this.valueBacking = idx;
}
if (ImGui.BeginCombo($"###{this.Id.ToString()}", descriptions[idx].FriendlyName))
{
foreach (Enum value in values)