Allow to select default profile

This commit is contained in:
Kamil Trzciński 2022-12-04 20:32:23 +01:00
parent f4431105e3
commit 271cb5d94e
4 changed files with 92 additions and 6 deletions

View file

@ -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)

View file

@ -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();

View file

@ -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);
}
}
}

View file

@ -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