From d689fb3840f4a99042d1a069be06b6b7bd6f899a Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Wed, 12 Nov 2025 16:00:37 +0100 Subject: [PATCH] Update AppSettingsForm to work with enum values --- PCK-Studio/Forms/AppSettingsForm.cs | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/PCK-Studio/Forms/AppSettingsForm.cs b/PCK-Studio/Forms/AppSettingsForm.cs index 3bbd5509..81fa8cf3 100644 --- a/PCK-Studio/Forms/AppSettingsForm.cs +++ b/PCK-Studio/Forms/AppSettingsForm.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Windows.Forms; using MetroFramework.Controls; using MetroFramework.Forms; +using PckStudio.Core; using PckStudio.Core.App; using PckStudio.Internal.App; using PckStudio.Properties; @@ -75,11 +76,42 @@ namespace PckStudio.Forms return control; } + static Control CreateEnumComboBox(SettingsPropertyValue propertyValue, SettingsBase settings) + { + Type type = propertyValue.PropertyValue.GetType(); + var control = new MetroComboBox + { + Name = ContextTryGetKeyToString(settings.Context, propertyValue.Name, out string name) ? name : propertyValue.Name, + Tag = propertyValue.Name, + + AutoSize = false, + Theme = MetroFramework.MetroThemeStyle.Dark, + Style = MetroFramework.MetroColorStyle.Silver, + }; + object[] values = Enum.GetNames(type); + control.Items.AddRange(values); + control.Text = propertyValue.PropertyValue.ToString(); + control.SelectedItem = propertyValue.PropertyValue; + + void ComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + if (sender is ComboBox comboBox && comboBox.Tag is string settingsKey && settings[settingsKey].GetType() == type) + { + settings[settingsKey] = Enum.Parse(type, (string)comboBox.SelectedItem, true); + } + } + + control.SelectedIndexChanged += ComboBox_SelectedIndexChanged; + return control; + } + delegate Control ControlCreateDelegate(SettingsPropertyValue propertyValue, SettingsBase settings); Dictionary _typeToControl = new Dictionary() { [typeof(bool)] = CreateCheckBox, + [typeof(ConsolePlatform)] = CreateEnumComboBox, + [typeof(AppLanguage)] = CreateEnumComboBox, }; private void LoadSettings()