diff --git a/RELEASE.md b/RELEASE.md index 3ffad55..40d2d9e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -21,3 +21,4 @@ It does help this project on being supported. - Manage Steam default controller configs to prevent double inputs (in DEBUG, change Settings) - Fix bug with unable to select controller profile from OSD - Skip repeated haptic requests +- Allow to select Default profile (Desktop-mode profile) diff --git a/SteamController/Controller.cs b/SteamController/Controller.cs index 900725b..142b50d 100644 --- a/SteamController/Controller.cs +++ b/SteamController/Controller.cs @@ -38,6 +38,11 @@ namespace SteamController public Controller() { + // Set available profiles + ProfilesSettings.Helpers.ProfileNameConverter.Profiles = context.Profiles. + Where((profile) => profile.Visible). + Select((profile) => profile.Name).ToArray(); + Instance.RunOnce(TitleWithVersion, "Global\\SteamController"); var contextMenu = new ContextMenuStrip(components); @@ -114,7 +119,8 @@ namespace SteamController context.SelectDefault = () => { - context.SelectProfile(Settings.Default.StartupProfile); + if (!context.SelectProfile(Settings.Default.DefaultProfile)) + context.SelectProfile(context.Profiles.First().Name); }; context.BackToDefault(); diff --git a/SteamController/ProfilesSettings/Helpers/ProfilesStringConverter.cs b/SteamController/ProfilesSettings/Helpers/ProfilesStringConverter.cs new file mode 100644 index 0000000..96963cc --- /dev/null +++ b/SteamController/ProfilesSettings/Helpers/ProfilesStringConverter.cs @@ -0,0 +1,77 @@ +using System.ComponentModel; +using System.Globalization; + +namespace SteamController.ProfilesSettings.Helpers +{ + [TypeConverter(typeof(ProfileNameConverter))] + public class ProfileName + { + public String Name { get; set; } = ""; + + public ProfileName(string name) + { + this.Name = name; + } + + public static implicit operator string(ProfileName name) + { + return name.Name; + } + + public override string ToString() + { + return this.Name; + } + } + + internal class ProfileNameConverter : TypeConverter + { + public static string[] Profiles = new string[0]; + + private volatile StandardValuesCollection? collection; + + public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context) + { + return collection ??= new StandardValuesCollection(Profiles.ToArray()); + } + + public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) + { + return true; + } + + public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) + { + return true; + } + + public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + public override object? ConvertFrom(ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) + { + if (value is string) + return new ProfileName(value?.ToString() ?? ""); + return base.ConvertFrom(context, culture, value); + } + + public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) + { + return destinationType == typeof(string) || base.CanConvertTo(context, destinationType); + } + + public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) + { + if (destinationType == typeof(string)) + return value?.ToString(); + return base.ConvertTo(context, culture, value, destinationType); + } + + public override bool IsValid(ITypeDescriptorContext? context, object? value) + { + return Profiles.Contains(value?.ToString()) || base.IsValid(context, value); + } + } +} \ No newline at end of file diff --git a/SteamController/Settings.cs b/SteamController/Settings.cs index 0aabb09..c46f714 100644 --- a/SteamController/Settings.cs +++ b/SteamController/Settings.cs @@ -3,6 +3,7 @@ using System.Configuration; namespace SteamController { + [Category("Settings")] [TypeConverter(typeof(ExpandableObjectConverter))] internal sealed partial class Settings : ApplicationSettingsBase @@ -26,13 +27,14 @@ namespace SteamController set { this["EnableSteamDetection"] = value; } } - [ApplicationScopedSetting] + [UserScopedSetting] [DefaultSettingValue("Desktop")] - [BrowsableAttribute(false)] - public string StartupProfile + [Description("Default profile used when going back to Desktop mode")] + [BrowsableAttribute(true)] + public ProfilesSettings.Helpers.ProfileName DefaultProfile { - get { return ((string)(this["StartupProfile"])); } - set { this["StartupProfile"] = value; } + get { return ((ProfilesSettings.Helpers.ProfileName)(this["DefaultProfile"])); } + set { this["DefaultProfile"] = value; } } #if DEBUG