diff --git a/RELEASE.md b/RELEASE.md index 6278e67..4c88dbc 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -15,3 +15,4 @@ It does help this project on being supported. - The X360 has Haptics enabled by default - Detect GamePad UI open temporarily for controller layout - Automatically manage steam controller configs when using Steam Input +- Allow to assign BackPanel keys to X360 controller (breaks all current configs to set mappings) diff --git a/SteamController/Controller.cs b/SteamController/Controller.cs index a2fc066..0333db8 100644 --- a/SteamController/Controller.cs +++ b/SteamController/Controller.cs @@ -312,8 +312,8 @@ namespace SteamController LargeButtons = true, SelectedObject = new { - Desktop = ProfilesSettings.BackPanelSettings.Desktop, - X360 = ProfilesSettings.BackPanelSettings.X360, + Desktop = ProfilesSettings.DesktopPanelSettings.Default, + X360 = ProfilesSettings.X360BackPanelSettings.Default, X360Haptic = ProfilesSettings.X360HapticSettings.Default, Application = Settings.Default } diff --git a/SteamController/Devices/Xbox360Controller.cs b/SteamController/Devices/Xbox360Controller.cs index 698d0cd..774bb32 100644 --- a/SteamController/Devices/Xbox360Controller.cs +++ b/SteamController/Devices/Xbox360Controller.cs @@ -2,6 +2,7 @@ using Nefarius.ViGEm.Client; using Nefarius.ViGEm.Client.Exceptions; using Nefarius.ViGEm.Client.Targets; using Nefarius.ViGEm.Client.Targets.Xbox360; +using SteamController.ProfilesSettings; using static CommonHelpers.Log; namespace SteamController.Devices @@ -12,6 +13,24 @@ namespace SteamController.Devices public const ushort VendorID = 0x045E; public const ushort ProductID = 0x028E; + public static readonly Dictionary codeToButton = new Dictionary() + { + { VirtualX360Code.X360_UP, Xbox360Button.Up }, + { VirtualX360Code.X360_DOWN, Xbox360Button.Down }, + { VirtualX360Code.X360_LEFT, Xbox360Button.Left }, + { VirtualX360Code.X360_RIGHT, Xbox360Button.Right }, + { VirtualX360Code.X360_BACK, Xbox360Button.Back }, + { VirtualX360Code.X360_START, Xbox360Button.Start }, + { VirtualX360Code.X360_A, Xbox360Button.A }, + { VirtualX360Code.X360_B, Xbox360Button.B }, + { VirtualX360Code.X360_X, Xbox360Button.X }, + { VirtualX360Code.X360_Y, Xbox360Button.Y }, + { VirtualX360Code.X360_LB, Xbox360Button.LeftShoulder }, + { VirtualX360Code.X360_RB, Xbox360Button.RightShoulder }, + { VirtualX360Code.X360_LS, Xbox360Button.LeftThumb }, + { VirtualX360Code.X360_RS, Xbox360Button.RightThumb } + }; + private ViGEmClient? client; private IXbox360Controller? device; private bool isConnected; @@ -137,6 +156,17 @@ namespace SteamController.Devices public byte LedNumber { get; private set; } public DateTime? FeedbackReceived { get; private set; } + public bool this[VirtualX360Code code] + { + set + { + if (codeToButton.TryGetValue(code, out var button)) + { + this[button] = value; + } + } + } + public bool this[Xbox360Button button] { set diff --git a/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs b/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs index f6decda..8793bd9 100644 --- a/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs +++ b/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs @@ -16,14 +16,14 @@ namespace SteamController.Profiles return Status.Continue; } - private void BackPanelShortcuts(Context c) + protected virtual void BackPanelShortcuts(Context c) { var settings = BackPanelSettings; - c.Keyboard[settings.L4] = c.Steam.BtnL4; - c.Keyboard[settings.L5] = c.Steam.BtnL5; - c.Keyboard[settings.R4] = c.Steam.BtnR4; - c.Keyboard[settings.R5] = c.Steam.BtnR5; + c.Keyboard[settings.L4_KEY] = c.Steam.BtnL4; + c.Keyboard[settings.L5_KEY] = c.Steam.BtnL5; + c.Keyboard[settings.R4_KEY] = c.Steam.BtnR4; + c.Keyboard[settings.R5_KEY] = c.Steam.BtnR5; } } } diff --git a/SteamController/Profiles/DesktopProfile.cs b/SteamController/Profiles/DesktopProfile.cs index dfb8648..00c9b08 100644 --- a/SteamController/Profiles/DesktopProfile.cs +++ b/SteamController/Profiles/DesktopProfile.cs @@ -13,7 +13,7 @@ namespace SteamController.Profiles internal override ProfilesSettings.BackPanelSettings BackPanelSettings { - get { return ProfilesSettings.BackPanelSettings.Desktop; } + get { return ProfilesSettings.DesktopPanelSettings.Default; } } public override bool Selected(Context context) diff --git a/SteamController/Profiles/X360Profile.cs b/SteamController/Profiles/X360Profile.cs index c60bdda..3b5ea40 100644 --- a/SteamController/Profiles/X360Profile.cs +++ b/SteamController/Profiles/X360Profile.cs @@ -11,7 +11,7 @@ namespace SteamController.Profiles internal override ProfilesSettings.BackPanelSettings BackPanelSettings { - get { return ProfilesSettings.BackPanelSettings.X360; } + get { return ProfilesSettings.X360BackPanelSettings.Default; } } public override Status Run(Context context) @@ -62,5 +62,17 @@ namespace SteamController.Profiles return Status.Continue; } + + protected override void BackPanelShortcuts(Context c) + { + base.BackPanelShortcuts(c); + + var settings = ProfilesSettings.X360BackPanelSettings.Default; + + c.X360[settings.L4_X360] = c.Steam.BtnL4; + c.X360[settings.L5_X360] = c.Steam.BtnL5; + c.X360[settings.R4_X360] = c.Steam.BtnR4; + c.X360[settings.R5_X360] = c.Steam.BtnR5; + } } } diff --git a/SteamController/ProfilesSettings/BackPanelSettings.cs b/SteamController/ProfilesSettings/BackPanelSettings.cs index 0026b25..1b425c2 100644 --- a/SteamController/ProfilesSettings/BackPanelSettings.cs +++ b/SteamController/ProfilesSettings/BackPanelSettings.cs @@ -4,15 +4,10 @@ using System.Configuration; namespace SteamController.ProfilesSettings { [Category("Mappings")] - internal sealed class BackPanelSettings : BaseSettings + internal abstract class BackPanelSettings : BaseSettings { private const String MappingsDescription = @"Only some of those keys do work. Allowed mappings are to be changed in future release."; - public static BackPanelSettings X360 { get; } = (BackPanelSettings)ApplicationSettingsBase.Synchronized( - new BackPanelSettings("X360BackPanelSettings")); - public static BackPanelSettings Desktop { get; } = (BackPanelSettings)ApplicationSettingsBase.Synchronized( - new BackPanelSettings("DesktopBackPanelSettings")); - public BackPanelSettings(String settingsKey) : base(settingsKey) { } @@ -20,37 +15,37 @@ namespace SteamController.ProfilesSettings [UserScopedSettingAttribute()] [DefaultSettingValueAttribute("None")] [Description(MappingsDescription)] - public VirtualKeyCode L4 + public VirtualKeyCode L4_KEY { - get { return ((VirtualKeyCode)(this["L4"])); } - set { this["L4"] = value; } + get { return ((VirtualKeyCode)(this["L4_KEY"])); } + set { this["L4_KEY"] = value; } } [UserScopedSettingAttribute()] [DefaultSettingValueAttribute("None")] [Description(MappingsDescription)] - public VirtualKeyCode L5 + public VirtualKeyCode L5_KEY { - get { return ((VirtualKeyCode)(this["L5"])); } - set { this["L5"] = value; } + get { return ((VirtualKeyCode)(this["L5_KEY"])); } + set { this["L5_KEY"] = value; } } [UserScopedSettingAttribute()] [DefaultSettingValueAttribute("None")] [Description(MappingsDescription)] - public VirtualKeyCode R4 + public VirtualKeyCode R4_KEY { - get { return ((VirtualKeyCode)(this["R4"])); } - set { this["R4"] = value; } + get { return ((VirtualKeyCode)(this["R4_KEY"])); } + set { this["R4_KEY"] = value; } } [UserScopedSettingAttribute()] [DefaultSettingValueAttribute("None")] [Description(MappingsDescription)] - public VirtualKeyCode R5 + public VirtualKeyCode R5_KEY { - get { return ((VirtualKeyCode)(this["R5"])); } - set { this["R5"] = value; } + get { return ((VirtualKeyCode)(this["R5_KEY"])); } + set { this["R5_KEY"] = value; } } } -} \ No newline at end of file +} diff --git a/SteamController/ProfilesSettings/DesktopPanelSettings.cs b/SteamController/ProfilesSettings/DesktopPanelSettings.cs new file mode 100644 index 0000000..25b714b --- /dev/null +++ b/SteamController/ProfilesSettings/DesktopPanelSettings.cs @@ -0,0 +1,15 @@ +using System.ComponentModel; +using System.Configuration; + +namespace SteamController.ProfilesSettings +{ + internal class DesktopPanelSettings : BackPanelSettings + { + public static DesktopPanelSettings Default { get; } = (DesktopPanelSettings)ApplicationSettingsBase.Synchronized( + new DesktopPanelSettings("DesktopPanelSettings")); + + public DesktopPanelSettings(String settingsKey) : base(settingsKey) + { + } + } +} \ No newline at end of file diff --git a/SteamController/ProfilesSettings/VirtualX360Code.cs b/SteamController/ProfilesSettings/VirtualX360Code.cs new file mode 100644 index 0000000..57b9dff --- /dev/null +++ b/SteamController/ProfilesSettings/VirtualX360Code.cs @@ -0,0 +1,24 @@ +namespace SteamController.ProfilesSettings +{ + public enum VirtualX360Code + { + None = 0, + + X360_UP, + X360_DOWN, + X360_LEFT, + X360_RIGHT, + X360_BACK, + X360_START, + + X360_A, + X360_B, + X360_X, + X360_Y, + + X360_LB, + X360_RB, + X360_LS, + X360_RS + } +} diff --git a/SteamController/ProfilesSettings/X360BackPanelSettings.cs b/SteamController/ProfilesSettings/X360BackPanelSettings.cs new file mode 100644 index 0000000..c6deda0 --- /dev/null +++ b/SteamController/ProfilesSettings/X360BackPanelSettings.cs @@ -0,0 +1,53 @@ +using System.ComponentModel; +using System.Configuration; + +namespace SteamController.ProfilesSettings +{ + internal class X360BackPanelSettings : BackPanelSettings + { + private const String MappingsDescription = @"Mappings are to be changed in future release."; + + public static X360BackPanelSettings Default { get; } = (X360BackPanelSettings)ApplicationSettingsBase.Synchronized( + new X360BackPanelSettings("X360BackPanelSettings")); + + public X360BackPanelSettings(String settingsKey) : base(settingsKey) + { + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("None")] + [Description(MappingsDescription)] + public VirtualX360Code L4_X360 + { + get { return ((VirtualX360Code)(this["L4_X360"])); } + set { this["L4_X360"] = value; } + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("None")] + [Description(MappingsDescription)] + public VirtualX360Code L5_X360 + { + get { return ((VirtualX360Code)(this["L5_X360"])); } + set { this["L5_X360"] = value; } + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("None")] + [Description(MappingsDescription)] + public VirtualX360Code R4_X360 + { + get { return ((VirtualX360Code)(this["R4_X360"])); } + set { this["R4_X360"] = value; } + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("None")] + [Description(MappingsDescription)] + public VirtualX360Code R5_X360 + { + get { return ((VirtualX360Code)(this["R5_X360"])); } + set { this["R5_X360"] = value; } + } + } +} \ No newline at end of file