Split Profiles into Profiles/Default and Profiles/Predefined

This commit is contained in:
Kamil Trzciński 2022-12-08 20:57:20 +01:00
parent 86b73001a2
commit bdcb70d685
9 changed files with 19 additions and 26 deletions

View file

@ -0,0 +1,76 @@
using WindowsInput;
namespace SteamController.Profiles.Predefined
{
public sealed class DesktopProfile : Default.BackPanelShortcutsProfile
{
private const String Consumed = "DesktopProfileOwner";
public DesktopProfile()
{
IsDesktop = true;
}
internal override ProfilesSettings.BackPanelSettings BackPanelSettings
{
get { return ProfilesSettings.DesktopPanelSettings.Default; }
}
public override bool Selected(Context context)
{
return context.Enabled;
}
public override Status Run(Context c)
{
if (base.Run(c).IsDone)
{
return Status.Done;
}
if (!c.KeyboardMouseValid)
{
// Failed to acquire secure context
// Enable emergency Lizard
c.Steam.LizardButtons = true;
c.Steam.LizardMouse = true;
}
else
{
c.Steam.LizardButtons = SettingsDebug.Default.LizardButtons;
c.Steam.LizardMouse = SettingsDebug.Default.LizardMouse;
}
EmulateScrollOnLPad(c);
EmulateScrollOnLStick(c);
EmulateMouseOnRPad(c);
EmulateMouseOnRStick(c);
EmulateDPadArrows(c);
c.Keyboard[VirtualKeyCode.RETURN] = c.Steam.BtnA;
c.Keyboard[VirtualKeyCode.BACK] = c.Steam.BtnB;
return Status.Continue;
}
private void EmulateScrollOnLStick(Context c)
{
if (c.Steam.LeftThumbX)
{
c.Mouse.HorizontalScroll(c.Steam.LeftThumbX.DeltaValue * Context.ThumbToWhellSensitivity);
}
if (c.Steam.LeftThumbY)
{
c.Mouse.VerticalScroll(c.Steam.LeftThumbY.DeltaValue * Context.ThumbToWhellSensitivity * (double)Settings.Default.ScrollDirection);
}
}
private void EmulateDPadArrows(Context c)
{
c.Keyboard[VirtualKeyCode.LEFT] = c.Steam.BtnDpadLeft;
c.Keyboard[VirtualKeyCode.RIGHT] = c.Steam.BtnDpadRight;
c.Keyboard[VirtualKeyCode.UP] = c.Steam.BtnDpadUp;
c.Keyboard[VirtualKeyCode.DOWN] = c.Steam.BtnDpadDown;
}
}
}

View file

@ -0,0 +1,28 @@
namespace SteamController.Profiles.Predefined
{
public sealed class SteamProfile : Default.ShortcutsProfile
{
public SteamProfile()
{
}
public override bool Selected(Context context)
{
return context.Enabled && context.State.SteamUsesSteamInput && Settings.Default.SteamControllerConfigs != Settings.SteamControllerConfigsMode.Overwrite;
}
public override Status Run(Context context)
{
// Steam does not use Lizard
context.Steam.LizardButtons = false;
context.Steam.LizardMouse = false;
if (base.Run(context).IsDone)
{
return Status.Done;
}
return Status.Continue;
}
}
}

View file

@ -0,0 +1,30 @@
using Nefarius.ViGEm.Client.Targets.Xbox360;
namespace SteamController.Profiles.Predefined
{
public sealed class SteamWithShorcutsProfile : Default.GuideShortcutsProfile
{
public SteamWithShorcutsProfile()
{
}
public override bool Selected(Context context)
{
return context.Enabled && context.State.SteamUsesSteamInput;
}
public override Status Run(Context context)
{
// Steam does not use Lizard
context.Steam.LizardButtons = false;
context.Steam.LizardMouse = false;
if (base.Run(context).IsDone)
{
return Status.Done;
}
return Status.Continue;
}
}
}

View file

@ -0,0 +1,40 @@
using SteamController.ProfilesSettings;
using HapticPad = SteamController.Devices.SteamController.HapticPad;
namespace SteamController.Profiles.Predefined
{
public class X360HapticProfile : X360Profile
{
private ProfilesSettings.X360HapticSettings HapticSettings
{
get { return ProfilesSettings.X360HapticSettings.Default; }
}
public override Status Run(Context context)
{
if (base.Run(context).IsDone)
return Status.Done;
if (GetHapticIntensity(context.X360.FeedbackLargeMotor, HapticSettings.LeftIntensity, out var leftIntensity))
context.Steam.SendHaptic(HapticPad.Right, HapticSettings.HapticStyle, leftIntensity);
if (GetHapticIntensity(context.X360.FeedbackSmallMotor, HapticSettings.RightIntensity, out var rightIntensity))
context.Steam.SendHaptic(HapticPad.Left, HapticSettings.HapticStyle, rightIntensity);
context.X360.ResetFeedback();
return Status.Continue;
}
private bool GetHapticIntensity(byte? input, sbyte maxIntensity, out sbyte output)
{
output = default;
if (input is null || input.Value == 0)
return false;
int value = X360HapticSettings.MinIntensity + (maxIntensity - X360HapticSettings.MinIntensity) * input.Value / 255;
output = (sbyte)value;
return true;
}
}
}

View file

@ -0,0 +1,79 @@
using Nefarius.ViGEm.Client.Targets.Xbox360;
using SteamController.ProfilesSettings;
namespace SteamController.Profiles.Predefined
{
public class X360Profile : Default.BackPanelShortcutsProfile
{
public override bool Selected(Context context)
{
return context.Enabled && context.X360.Valid && context.KeyboardMouseValid && !context.State.SteamUsesSteamInput;
}
internal override ProfilesSettings.BackPanelSettings BackPanelSettings
{
get { return ProfilesSettings.X360BackPanelSettings.Default; }
}
public override Status Run(Context context)
{
context.Steam.LizardButtons = false;
context.Steam.LizardMouse = SettingsDebug.Default.LizardMouse;
context.X360.Connected = true;
// Controls
context.X360[Xbox360Button.Guide] = context.Steam.BtnSteam.Pressed();
context.X360[Xbox360Button.Back] = context.Steam.BtnMenu;
context.X360[Xbox360Button.Start] = context.Steam.BtnOptions;
if (base.Run(context).IsDone)
{
return Status.Done;
}
// Default emulation
EmulateScrollOnLPad(context);
EmulateMouseOnRPad(context, false);
// DPad
context.X360[Xbox360Button.Up] = context.Steam.BtnDpadUp;
context.X360[Xbox360Button.Down] = context.Steam.BtnDpadDown;
context.X360[Xbox360Button.Left] = context.Steam.BtnDpadLeft;
context.X360[Xbox360Button.Right] = context.Steam.BtnDpadRight;
// Buttons
context.X360[Xbox360Button.A] = context.Steam.BtnA;
context.X360[Xbox360Button.B] = context.Steam.BtnB;
context.X360[Xbox360Button.X] = context.Steam.BtnX;
context.X360[Xbox360Button.Y] = context.Steam.BtnY;
// Sticks
context.X360[Xbox360Axis.LeftThumbX] = context.Steam.LeftThumbX;
context.X360[Xbox360Axis.LeftThumbY] = context.Steam.LeftThumbY;
context.X360[Xbox360Axis.RightThumbX] = context.Steam.RightThumbX;
context.X360[Xbox360Axis.RightThumbY] = context.Steam.RightThumbY;
context.X360[Xbox360Button.LeftThumb] = context.Steam.BtnLeftStickPress;
context.X360[Xbox360Button.RightThumb] = context.Steam.BtnRightStickPress;
// Triggers
context.X360[Xbox360Slider.LeftTrigger] = context.Steam.LeftTrigger;
context.X360[Xbox360Slider.RightTrigger] = context.Steam.RightTrigger;
context.X360[Xbox360Button.LeftShoulder] = context.Steam.BtnL1;
context.X360[Xbox360Button.RightShoulder] = context.Steam.BtnR1;
return Status.Continue;
}
protected override void BackPanelShortcuts(Context c)
{
base.BackPanelShortcuts(c);
var settings = ProfilesSettings.X360BackPanelSettings.Default;
c.X360[settings.L4_X360.ToViGEm()] = c.Steam.BtnL4;
c.X360[settings.L5_X360.ToViGEm()] = c.Steam.BtnL5;
c.X360[settings.R4_X360.ToViGEm()] = c.Steam.BtnR4;
c.X360[settings.R5_X360.ToViGEm()] = c.Steam.BtnR5;
}
}
}