Allow to assign BackPanel keys to X360 controller (breaks all current configs to set mappings)

This commit is contained in:
Kamil Trzciński 2022-12-08 01:48:14 +01:00
parent 476ca5a5e9
commit 9adb25be21
10 changed files with 158 additions and 28 deletions

View file

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

View file

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

View file

@ -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<VirtualX360Code, Xbox360Button> codeToButton = new Dictionary<VirtualX360Code, Xbox360Button>()
{
{ 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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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