NpadController.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. namespace Ryujinx.HLE.Input
  2. {
  3. public class NpadController : BaseController
  4. {
  5. private (NpadColor Left, NpadColor Right) _npadBodyColors;
  6. private (NpadColor Left, NpadColor Right) _npadButtonColors;
  7. private bool _isHalf;
  8. public NpadController(
  9. ControllerStatus controllerStatus,
  10. Switch device,
  11. (NpadColor, NpadColor) npadBodyColors,
  12. (NpadColor, NpadColor) npadButtonColors) : base(device, controllerStatus)
  13. {
  14. _npadBodyColors = npadBodyColors;
  15. _npadButtonColors = npadButtonColors;
  16. }
  17. public override void Connect(ControllerId controllerId)
  18. {
  19. if (HidControllerType != ControllerStatus.NpadLeft && HidControllerType != ControllerStatus.NpadRight)
  20. {
  21. _isHalf = false;
  22. }
  23. ConnectionState = ControllerConnectionState.ControllerStateConnected;
  24. if (controllerId == ControllerId.ControllerHandheld)
  25. ConnectionState |= ControllerConnectionState.ControllerStateWired;
  26. ControllerColorDescription singleColorDesc =
  27. ControllerColorDescription.ColorDescriptionColorsNonexistent;
  28. ControllerColorDescription splitColorDesc = 0;
  29. NpadColor singleBodyColor = NpadColor.Black;
  30. NpadColor singleButtonColor = NpadColor.Black;
  31. Initialize(_isHalf,
  32. (_npadBodyColors.Left, _npadBodyColors.Right),
  33. (_npadButtonColors.Left, _npadButtonColors.Right),
  34. singleColorDesc,
  35. splitColorDesc,
  36. singleBodyColor,
  37. singleButtonColor );
  38. base.Connect(controllerId);
  39. var _currentLayout = ControllerLayouts.HandheldJoined;
  40. switch (HidControllerType)
  41. {
  42. case ControllerStatus.NpadLeft:
  43. _currentLayout = ControllerLayouts.Left;
  44. break;
  45. case ControllerStatus.NpadRight:
  46. _currentLayout = ControllerLayouts.Right;
  47. break;
  48. case ControllerStatus.NpadPair:
  49. _currentLayout = ControllerLayouts.Joined;
  50. break;
  51. }
  52. SetLayout(_currentLayout);
  53. }
  54. }
  55. }