mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-08-03 00:17:09 +02:00
Support other switch controller types (#487)
* Make controllers modular, support changing controller type * return readable events * signal hid events * fix style
This commit is contained in:
parent
c6de4b43f8
commit
0975f80081
24 changed files with 574 additions and 409 deletions
|
@ -142,25 +142,24 @@ namespace Ryujinx
|
|||
{
|
||||
KeyboardState keyboard = _keyboard.Value;
|
||||
|
||||
currentButton = Config.JoyConKeyboard.GetButtons(keyboard);
|
||||
currentButton = Config.NpadKeyboard.GetButtons(keyboard);
|
||||
|
||||
(leftJoystickDx, leftJoystickDy) = Config.JoyConKeyboard.GetLeftStick(keyboard);
|
||||
(leftJoystickDx, leftJoystickDy) = Config.NpadKeyboard.GetLeftStick(keyboard);
|
||||
|
||||
(rightJoystickDx, rightJoystickDy) = Config.JoyConKeyboard.GetRightStick(keyboard);
|
||||
(rightJoystickDx, rightJoystickDy) = Config.NpadKeyboard.GetRightStick(keyboard);
|
||||
}
|
||||
|
||||
//Controller Input
|
||||
currentButton |= Config.JoyConController.GetButtons();
|
||||
|
||||
currentButton |= Config.NpadController.GetButtons();
|
||||
|
||||
//Keyboard has priority stick-wise
|
||||
if (leftJoystickDx == 0 && leftJoystickDy == 0)
|
||||
{
|
||||
(leftJoystickDx, leftJoystickDy) = Config.JoyConController.GetLeftStick();
|
||||
(leftJoystickDx, leftJoystickDy) = Config.NpadController.GetLeftStick();
|
||||
}
|
||||
|
||||
if (rightJoystickDx == 0 && rightJoystickDy == 0)
|
||||
{
|
||||
(rightJoystickDx, rightJoystickDy) = Config.JoyConController.GetRightStick();
|
||||
(rightJoystickDx, rightJoystickDy) = Config.NpadController.GetRightStick();
|
||||
}
|
||||
|
||||
leftJoystick = new HidJoystickPosition
|
||||
|
@ -234,19 +233,9 @@ namespace Ryujinx
|
|||
_device.Hid.SetTouchPoints();
|
||||
}
|
||||
|
||||
_device.Hid.SetJoyconButton(
|
||||
HidControllerId.CONTROLLER_HANDHELD,
|
||||
HidControllerLayouts.Handheld_Joined,
|
||||
currentButton,
|
||||
leftJoystick,
|
||||
rightJoystick);
|
||||
HidControllerBase controller = _device.Hid.PrimaryController;
|
||||
|
||||
_device.Hid.SetJoyconButton(
|
||||
HidControllerId.CONTROLLER_HANDHELD,
|
||||
HidControllerLayouts.Main,
|
||||
currentButton,
|
||||
leftJoystick,
|
||||
rightJoystick);
|
||||
controller.SendInput(currentButton, leftJoystick, rightJoystick);
|
||||
}
|
||||
|
||||
private new void RenderFrame()
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Ryujinx.UI.Input
|
|||
RJoystick
|
||||
}
|
||||
|
||||
public struct JoyConControllerLeft
|
||||
public struct NpadControllerLeft
|
||||
{
|
||||
public ControllerInputId Stick;
|
||||
public ControllerInputId StickButton;
|
||||
|
@ -45,7 +45,7 @@ namespace Ryujinx.UI.Input
|
|||
public ControllerInputId ButtonZl;
|
||||
}
|
||||
|
||||
public struct JoyConControllerRight
|
||||
public struct NpadControllerRight
|
||||
{
|
||||
public ControllerInputId Stick;
|
||||
public ControllerInputId StickButton;
|
||||
|
@ -58,23 +58,23 @@ namespace Ryujinx.UI.Input
|
|||
public ControllerInputId ButtonZr;
|
||||
}
|
||||
|
||||
public class JoyConController
|
||||
public class NpadController
|
||||
{
|
||||
public bool Enabled { private set; get; }
|
||||
public int Index { private set; get; }
|
||||
public float Deadzone { private set; get; }
|
||||
public float TriggerThreshold { private set; get; }
|
||||
|
||||
public JoyConControllerLeft Left { private set; get; }
|
||||
public JoyConControllerRight Right { private set; get; }
|
||||
public NpadControllerLeft Left { private set; get; }
|
||||
public NpadControllerRight Right { private set; get; }
|
||||
|
||||
public JoyConController(
|
||||
public NpadController(
|
||||
bool enabled,
|
||||
int index,
|
||||
float deadzone,
|
||||
float triggerThreshold,
|
||||
JoyConControllerLeft left,
|
||||
JoyConControllerRight right)
|
||||
NpadControllerLeft left,
|
||||
NpadControllerRight right)
|
||||
{
|
||||
Enabled = enabled;
|
||||
Index = index;
|
||||
|
@ -101,23 +101,23 @@ namespace Ryujinx.UI.Input
|
|||
|
||||
HidControllerButtons buttons = 0;
|
||||
|
||||
if (IsPressed(gpState, Left.DPadUp)) buttons |= HidControllerButtons.KEY_DUP;
|
||||
if (IsPressed(gpState, Left.DPadDown)) buttons |= HidControllerButtons.KEY_DDOWN;
|
||||
if (IsPressed(gpState, Left.DPadLeft)) buttons |= HidControllerButtons.KEY_DLEFT;
|
||||
if (IsPressed(gpState, Left.DPadRight)) buttons |= HidControllerButtons.KEY_DRIGHT;
|
||||
if (IsPressed(gpState, Left.StickButton)) buttons |= HidControllerButtons.KEY_LSTICK;
|
||||
if (IsPressed(gpState, Left.ButtonMinus)) buttons |= HidControllerButtons.KEY_MINUS;
|
||||
if (IsPressed(gpState, Left.ButtonL)) buttons |= HidControllerButtons.KEY_L;
|
||||
if (IsPressed(gpState, Left.ButtonZl)) buttons |= HidControllerButtons.KEY_ZL;
|
||||
if (IsPressed(gpState, Left.DPadUp)) buttons |= HidControllerButtons.DpadUp;
|
||||
if (IsPressed(gpState, Left.DPadDown)) buttons |= HidControllerButtons.DpadDown;
|
||||
if (IsPressed(gpState, Left.DPadLeft)) buttons |= HidControllerButtons.DpadLeft;
|
||||
if (IsPressed(gpState, Left.DPadRight)) buttons |= HidControllerButtons.DPadRight;
|
||||
if (IsPressed(gpState, Left.StickButton)) buttons |= HidControllerButtons.StickLeft;
|
||||
if (IsPressed(gpState, Left.ButtonMinus)) buttons |= HidControllerButtons.Minus;
|
||||
if (IsPressed(gpState, Left.ButtonL)) buttons |= HidControllerButtons.L;
|
||||
if (IsPressed(gpState, Left.ButtonZl)) buttons |= HidControllerButtons.Zl;
|
||||
|
||||
if (IsPressed(gpState, Right.ButtonA)) buttons |= HidControllerButtons.KEY_A;
|
||||
if (IsPressed(gpState, Right.ButtonB)) buttons |= HidControllerButtons.KEY_B;
|
||||
if (IsPressed(gpState, Right.ButtonX)) buttons |= HidControllerButtons.KEY_X;
|
||||
if (IsPressed(gpState, Right.ButtonY)) buttons |= HidControllerButtons.KEY_Y;
|
||||
if (IsPressed(gpState, Right.StickButton)) buttons |= HidControllerButtons.KEY_RSTICK;
|
||||
if (IsPressed(gpState, Right.ButtonPlus)) buttons |= HidControllerButtons.KEY_PLUS;
|
||||
if (IsPressed(gpState, Right.ButtonR)) buttons |= HidControllerButtons.KEY_R;
|
||||
if (IsPressed(gpState, Right.ButtonZr)) buttons |= HidControllerButtons.KEY_ZR;
|
||||
if (IsPressed(gpState, Right.ButtonA)) buttons |= HidControllerButtons.A;
|
||||
if (IsPressed(gpState, Right.ButtonB)) buttons |= HidControllerButtons.B;
|
||||
if (IsPressed(gpState, Right.ButtonX)) buttons |= HidControllerButtons.X;
|
||||
if (IsPressed(gpState, Right.ButtonY)) buttons |= HidControllerButtons.Y;
|
||||
if (IsPressed(gpState, Right.StickButton)) buttons |= HidControllerButtons.StickRight;
|
||||
if (IsPressed(gpState, Right.ButtonPlus)) buttons |= HidControllerButtons.Plus;
|
||||
if (IsPressed(gpState, Right.ButtonR)) buttons |= HidControllerButtons.R;
|
||||
if (IsPressed(gpState, Right.ButtonZr)) buttons |= HidControllerButtons.Zr;
|
||||
|
||||
return buttons;
|
||||
}
|
|
@ -3,7 +3,7 @@ using Ryujinx.HLE.Input;
|
|||
|
||||
namespace Ryujinx.UI.Input
|
||||
{
|
||||
public struct JoyConKeyboardLeft
|
||||
public struct NpadKeyboardLeft
|
||||
{
|
||||
public int StickUp;
|
||||
public int StickDown;
|
||||
|
@ -19,7 +19,7 @@ namespace Ryujinx.UI.Input
|
|||
public int ButtonZl;
|
||||
}
|
||||
|
||||
public struct JoyConKeyboardRight
|
||||
public struct NpadKeyboardRight
|
||||
{
|
||||
public int StickUp;
|
||||
public int StickDown;
|
||||
|
@ -35,14 +35,14 @@ namespace Ryujinx.UI.Input
|
|||
public int ButtonZr;
|
||||
}
|
||||
|
||||
public class JoyConKeyboard
|
||||
public class NpadKeyboard
|
||||
{
|
||||
public JoyConKeyboardLeft Left;
|
||||
public JoyConKeyboardRight Right;
|
||||
public NpadKeyboardLeft Left;
|
||||
public NpadKeyboardRight Right;
|
||||
|
||||
public JoyConKeyboard(
|
||||
JoyConKeyboardLeft left,
|
||||
JoyConKeyboardRight right)
|
||||
public NpadKeyboard(
|
||||
NpadKeyboardLeft left,
|
||||
NpadKeyboardRight right)
|
||||
{
|
||||
Left = left;
|
||||
Right = right;
|
||||
|
@ -52,23 +52,23 @@ namespace Ryujinx.UI.Input
|
|||
{
|
||||
HidControllerButtons buttons = 0;
|
||||
|
||||
if (keyboard[(Key)Left.StickButton]) buttons |= HidControllerButtons.KEY_LSTICK;
|
||||
if (keyboard[(Key)Left.DPadUp]) buttons |= HidControllerButtons.KEY_DUP;
|
||||
if (keyboard[(Key)Left.DPadDown]) buttons |= HidControllerButtons.KEY_DDOWN;
|
||||
if (keyboard[(Key)Left.DPadLeft]) buttons |= HidControllerButtons.KEY_DLEFT;
|
||||
if (keyboard[(Key)Left.DPadRight]) buttons |= HidControllerButtons.KEY_DRIGHT;
|
||||
if (keyboard[(Key)Left.ButtonMinus]) buttons |= HidControllerButtons.KEY_MINUS;
|
||||
if (keyboard[(Key)Left.ButtonL]) buttons |= HidControllerButtons.KEY_L;
|
||||
if (keyboard[(Key)Left.ButtonZl]) buttons |= HidControllerButtons.KEY_ZL;
|
||||
if (keyboard[(Key)Left.StickButton]) buttons |= HidControllerButtons.StickLeft;
|
||||
if (keyboard[(Key)Left.DPadUp]) buttons |= HidControllerButtons.DpadUp;
|
||||
if (keyboard[(Key)Left.DPadDown]) buttons |= HidControllerButtons.DpadDown;
|
||||
if (keyboard[(Key)Left.DPadLeft]) buttons |= HidControllerButtons.DpadLeft;
|
||||
if (keyboard[(Key)Left.DPadRight]) buttons |= HidControllerButtons.DPadRight;
|
||||
if (keyboard[(Key)Left.ButtonMinus]) buttons |= HidControllerButtons.Minus;
|
||||
if (keyboard[(Key)Left.ButtonL]) buttons |= HidControllerButtons.L;
|
||||
if (keyboard[(Key)Left.ButtonZl]) buttons |= HidControllerButtons.Zl;
|
||||
|
||||
if (keyboard[(Key)Right.StickButton]) buttons |= HidControllerButtons.KEY_RSTICK;
|
||||
if (keyboard[(Key)Right.ButtonA]) buttons |= HidControllerButtons.KEY_A;
|
||||
if (keyboard[(Key)Right.ButtonB]) buttons |= HidControllerButtons.KEY_B;
|
||||
if (keyboard[(Key)Right.ButtonX]) buttons |= HidControllerButtons.KEY_X;
|
||||
if (keyboard[(Key)Right.ButtonY]) buttons |= HidControllerButtons.KEY_Y;
|
||||
if (keyboard[(Key)Right.ButtonPlus]) buttons |= HidControllerButtons.KEY_PLUS;
|
||||
if (keyboard[(Key)Right.ButtonR]) buttons |= HidControllerButtons.KEY_R;
|
||||
if (keyboard[(Key)Right.ButtonZr]) buttons |= HidControllerButtons.KEY_ZR;
|
||||
if (keyboard[(Key)Right.StickButton]) buttons |= HidControllerButtons.StickRight;
|
||||
if (keyboard[(Key)Right.ButtonA]) buttons |= HidControllerButtons.A;
|
||||
if (keyboard[(Key)Right.ButtonB]) buttons |= HidControllerButtons.B;
|
||||
if (keyboard[(Key)Right.ButtonX]) buttons |= HidControllerButtons.X;
|
||||
if (keyboard[(Key)Right.ButtonY]) buttons |= HidControllerButtons.Y;
|
||||
if (keyboard[(Key)Right.ButtonPlus]) buttons |= HidControllerButtons.Plus;
|
||||
if (keyboard[(Key)Right.ButtonR]) buttons |= HidControllerButtons.R;
|
||||
if (keyboard[(Key)Right.ButtonZr]) buttons |= HidControllerButtons.Zr;
|
||||
|
||||
return buttons;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue