Beispiel #1
0
        private static void ImportDirectInputButton(GameProfile userProfile, InputConfig c, InputKey key, InputMapping[] mapping)
        {
            var start = userProfile.JoystickButtons.FirstOrDefault(j => !j.HideWithDirectInput && mapping.Contains(j.InputMapping));

            bool reverseAxis = false;

            if (c[key] == null && key == InputKey.leftanalogdown)
            {
                reverseAxis = true;
                key         = InputKey.leftanalogup;
            }
            if (c[key] == null && key == InputKey.leftanalogright)
            {
                reverseAxis = true;
                key         = InputKey.leftanalogleft;
            }

            var info = c.GetDirectInputInfo();

            if (start != null && c[key] != null && info != null)
            {
                var ss = c[key];

                start.DirectInputButton = new JoystickButton();
                start.DirectInputButton.JoystickGuid  = info.InstanceGuid;
                start.DirectInputButton.IsAxis        = false;
                start.DirectInputButton.IsAxisMinus   = false;
                start.DirectInputButton.IsFullAxis    = false;
                start.DirectInputButton.IsReverseAxis = false;
                start.DirectInputButton.PovDirection  = 0;
                start.DirectInputButton.IsReverseAxis = false;
                start.DirectInputButton.Button        = 0;

                if (ss.Type == "button")
                {
                    start.DirectInputButton.Button = (int)ss.Id + 48;
                }
                else if (ss.Type == "hat")
                {
                    start.DirectInputButton.Button = 32;
                    if (ss.Value == 1) // Top
                    {
                        start.DirectInputButton.PovDirection = 0;
                    }
                    else if (ss.Value == 4) // Down
                    {
                        start.DirectInputButton.PovDirection = 18000;
                    }
                    else if (ss.Value == 8) // Left
                    {
                        start.DirectInputButton.PovDirection = 27000;
                    }
                    else if (ss.Value == 2) // Right
                    {
                        start.DirectInputButton.PovDirection = 9000;
                    }
                }
                else if (ss.Type == "axis")
                {
                    start.DirectInputButton.Button      = (int)ss.Id * 4;
                    start.DirectInputButton.IsAxis      = true;
                    start.DirectInputButton.IsAxisMinus = reverseAxis ? ss.Value > 0 : ss.Value < 0;
                }
            }
        }