aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Input/Controller/NpadController.cs
blob: b4304b8f3f72d1165bf7a0997ac9e36e3a84c740 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
namespace Ryujinx.HLE.Input
{
    public class NpadController : BaseController
    {
        private (NpadColor Left, NpadColor Right) _npadBodyColors;
        private (NpadColor Left, NpadColor Right) _npadButtonColors;

        private bool _isHalf;

        public NpadController(
            ControllerStatus       controllerStatus,
            Switch                 device,
            (NpadColor, NpadColor) npadBodyColors,
            (NpadColor, NpadColor) npadButtonColors) : base(device, controllerStatus)
        {
            _npadBodyColors   = npadBodyColors;
            _npadButtonColors = npadButtonColors;
        }

        public override void Connect(ControllerId controllerId)
        {
            if (HidControllerType != ControllerStatus.NpadLeft && HidControllerType != ControllerStatus.NpadRight)
            {
                _isHalf = false;
            }

            ConnectionState = ControllerConnectionState.ControllerStateConnected;

            if (controllerId == ControllerId.ControllerHandheld)
                ConnectionState |= ControllerConnectionState.ControllerStateWired;

            ControllerColorDescription singleColorDesc =
                ControllerColorDescription.ColorDescriptionColorsNonexistent;

            ControllerColorDescription splitColorDesc = 0;

            NpadColor singleBodyColor   = NpadColor.Black;
            NpadColor singleButtonColor = NpadColor.Black;

            Initialize(_isHalf,
                (_npadBodyColors.Left,   _npadBodyColors.Right),
                (_npadButtonColors.Left, _npadButtonColors.Right),
                singleColorDesc,
                splitColorDesc,
                singleBodyColor,
                singleButtonColor );

            base.Connect(controllerId);

            var _currentLayout = ControllerLayouts.HandheldJoined;

            switch (HidControllerType)
            {
                case ControllerStatus.NpadLeft:
                    _currentLayout = ControllerLayouts.Left;
                    break;
                case ControllerStatus.NpadRight:
                    _currentLayout = ControllerLayouts.Right;
                    break;
                case ControllerStatus.NpadPair:
                    _currentLayout = ControllerLayouts.Joined;
                    break;
            }

            SetLayout(_currentLayout);
        }
    }
}