Beispiel #1
0
        public void Map(RetroPadMapping mapping)
        {
            ClearMappings();
            if (mapping == null)
            {
                return;
            }

            foreach (var kvp in mapping.ButtonMappings)
            {
                DeviceInput deviceInput = kvp.Value;
                if (deviceInput.InputType == InputType.Button)
                {
                    ushort            button;
                    DirectionPadState directionPadState;
                    if (ushort.TryParse(deviceInput.Id, out button))
                    {
                        _buttonToButtonMappings.Add(kvp.Key, button);
                    }
                    else if (Enum.TryParse(deviceInput.Id, out directionPadState))
                    {
                        _directionPadToButtonMappings.Add(kvp.Key, directionPadState);
                    }
                }
                else if (deviceInput.InputType == InputType.Axis)
                {
                    ushort axis;
                    if (ushort.TryParse(deviceInput.Id, out axis))
                    {
                        _analogToButtonMappings.Add(kvp.Key, new HidAxis(axis, deviceInput.PositiveValues));
                    }
                }
            }

            foreach (var kvp in mapping.AnalogMappings)
            {
                DeviceInput deviceInput = kvp.Value;
                if (deviceInput.InputType == InputType.Button)
                {
                    ushort            button;
                    DirectionPadState directionPadState;
                    if (ushort.TryParse(deviceInput.Id, out button))
                    {
                        _buttonToAnalogMappings.Add(kvp.Key, button);
                    }
                    else if (Enum.TryParse(deviceInput.Id, out directionPadState))
                    {
                        _directionPadToAnalogMappings.Add(kvp.Key, directionPadState);
                    }
                }
                else if (deviceInput.InputType == InputType.Axis)
                {
                    ushort axis;
                    if (ushort.TryParse(deviceInput.Id, out axis))
                    {
                        _analogToAnalogMappings.Add(kvp.Key, new HidAxis(axis, deviceInput.PositiveValues));
                    }
                }
            }
        }
Beispiel #2
0
        public short GetAnalog(uint port, RETRO_DEVICE_INDEX_ANALOG index, RETRO_DEVICE_ID_ANALOG direction)
        {
            RetroAnalogDevice positive;
            RetroAnalogDevice negative;

            RetroPadMapping.GetAnalogEnums(index, direction, out positive, out negative);

            short positivePosition = 0;
            short negativePosition = 0;

            Keys key;

            if (_analogMappings.TryGetValue(positive, out key) && Keyboard.IsKeyDown(key))
            {
                positivePosition = short.MaxValue;
            }
            if (_analogMappings.TryGetValue(negative, out key) && Keyboard.IsKeyDown(key))
            {
                negativePosition = short.MinValue;
            }

            if (positivePosition != 0 && negativePosition == 0)
            {
                return(positivePosition);
            }
            if (positivePosition == 0 && negativePosition != 0)
            {
                return(negativePosition);
            }
            return(0);
        }
Beispiel #3
0
        public short GetAnalog(uint port, RETRO_DEVICE_INDEX_ANALOG index, RETRO_DEVICE_ID_ANALOG direction)
        {
            HidState state = _currentState;

            if (state == null)
            {
                return(0);
            }

            RetroAnalogDevice positive;
            RetroAnalogDevice negative;

            RetroPadMapping.GetAnalogEnums(index, direction, out positive, out negative);
            short positivePosition = 0;
            short negativePosition = 0;

            HidAxis           axis;
            ushort            button;
            DirectionPadState directionPadState;

            if (_analogToAnalogMappings.TryGetValue(positive, out axis))
            {
                positivePosition = GetAxisPositionMapped(axis, state, true);
            }
            else if (_directionPadToAnalogMappings.TryGetValue(positive, out directionPadState) && IsDirectionPadPressed(directionPadState, state))
            {
                positivePosition = short.MaxValue;
            }
            else if (_buttonToAnalogMappings.TryGetValue(positive, out button) && IsButtonPressed(button, state))
            {
                positivePosition = short.MaxValue;
            }

            if (_analogToAnalogMappings.TryGetValue(negative, out axis))
            {
                negativePosition = GetAxisPositionMapped(axis, state, false);
            }
            else if (_directionPadToAnalogMappings.TryGetValue(negative, out directionPadState) && IsDirectionPadPressed(directionPadState, state))
            {
                positivePosition = short.MinValue;
            }
            else if (_buttonToAnalogMappings.TryGetValue(negative, out button) && IsButtonPressed(button, state))
            {
                negativePosition = short.MinValue;
            }

            if (positivePosition != 0 && negativePosition == 0)
            {
                return(positivePosition);
            }
            if (positivePosition == 0 && negativePosition != 0)
            {
                return(negativePosition);
            }
            return(0);
        }
 public DeviceMapperProxy(IDeviceMapper deviceMapper, RetroPadMapping mapping)
 {
     _deviceMapper   = deviceMapper;
     _currentMapping = mapping;
     CreateInputList();
     if (deviceMapper.SupportsDeadZone)
     {
         SupportsDeadZone = true;
         CurrentDeadZone  = mapping.DeadZone;
     }
 }
        public short GetAnalog(uint port, RETRO_DEVICE_INDEX_ANALOG index, RETRO_DEVICE_ID_ANALOG direction)
        {
            if (port != _controllerIndex)
            {
                return(0);
            }
            Gamepad gamepad;

            if (!TryGetGamepad(out gamepad))
            {
                return(0);
            }

            RetroAnalogDevice positive;
            RetroAnalogDevice negative;

            RetroPadMapping.GetAnalogEnums(index, direction, out positive, out negative);
            short positivePosition = 0;
            short negativePosition = 0;

            XInputAxis         axis;
            GamepadButtonFlags buttonFlag;

            if (_analogToAnalogMappings.TryGetValue(positive, out axis))
            {
                positivePosition = GetAxisPositionMapped(axis, gamepad, true);
            }
            else if (_buttonToAnalogMappings.TryGetValue(positive, out buttonFlag) && IsButtonPressed(buttonFlag, gamepad))
            {
                positivePosition = short.MaxValue;
            }

            if (_analogToAnalogMappings.TryGetValue(negative, out axis))
            {
                negativePosition = GetAxisPositionMapped(axis, gamepad, false);
            }
            else if (_buttonToAnalogMappings.TryGetValue(negative, out buttonFlag) && IsButtonPressed(buttonFlag, gamepad))
            {
                negativePosition = short.MinValue;
            }

            if (positivePosition != 0 && negativePosition == 0)
            {
                return(positivePosition);
            }
            if (positivePosition == 0 && negativePosition != 0)
            {
                return(negativePosition);
            }
            return(0);
        }
Beispiel #6
0
        public static RetroPadMapping GetDefaultMapping(string subDeviceId, bool mapAnalogToDPad)
        {
            RetroPadMapping mapping = new RetroPadMapping()
            {
                DeviceId    = XInputController.DEVICE_ID,
                SubDeviceId = subDeviceId,
                DeviceName  = XInputController.DEVICE_NAME
            };

            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.LEFT, DPAD_LEFT);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.RIGHT, DPAD_RIGHT);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.UP, DPAD_UP);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.DOWN, DPAD_DOWN);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.SELECT, BACK);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.START, START);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.A, B);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.B, A);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.X, Y);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.Y, X);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.L, LEFT_SHOULDER);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.R, RIGHT_SHOULDER);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.L2, LEFT_TRIGGER);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.R2, RIGHT_TRIGGER);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.L3, LEFT_THUMB);
            mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.R3, RIGHT_THUMB);

            mapping.MapAnalog(RetroAnalogDevice.RightThumbLeft, RIGHT_THUMB_LEFT);
            mapping.MapAnalog(RetroAnalogDevice.RightThumbRight, RIGHT_THUMB_RIGHT);
            mapping.MapAnalog(RetroAnalogDevice.RightThumbUp, RIGHT_THUMB_UP);
            mapping.MapAnalog(RetroAnalogDevice.RightThumbDown, RIGHT_THUMB_DOWN);

            if (mapAnalogToDPad)
            {
                mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.LEFT, LEFT_THUMB_LEFT);
                mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.RIGHT, LEFT_THUMB_RIGHT);
                mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.UP, LEFT_THUMB_UP);
                mapping.MapButton(SharpRetro.LibRetro.RETRO_DEVICE_ID_JOYPAD.DOWN, LEFT_THUMB_DOWN);
            }
            else
            {
                mapping.MapAnalog(RetroAnalogDevice.LeftThumbLeft, LEFT_THUMB_LEFT);
                mapping.MapAnalog(RetroAnalogDevice.LeftThumbRight, LEFT_THUMB_RIGHT);
                mapping.MapAnalog(RetroAnalogDevice.LeftThumbUp, LEFT_THUMB_UP);
                mapping.MapAnalog(RetroAnalogDevice.LeftThumbDown, LEFT_THUMB_DOWN);
            }

            return(mapping);
        }
 protected void UpdateMappings()
 {
     ResetMapper();
     _inputList.Clear();
     if (_currentDevice != null)
     {
         IDeviceMapper   mapper  = _currentDevice.CreateMapper();
         RetroPadMapping mapping = _mappingProxy.GetDeviceMapping(_currentDevice);
         if (mapper != null && mapping != null)
         {
             DeviceMapperProxy deviceMapper = new DeviceMapperProxy(mapper, mapping);
             deviceMapper.SelectedInputProperty.Attach(OnSelectedInputChanged);
             CollectionUtils.AddAll(_inputList, deviceMapper.Inputs);
             DeviceMapper = deviceMapper;
         }
     }
     _inputList.FireChange();
 }
        protected void InitializeControllerWrapper()
        {
            _controllerWrapper = new ControllerWrapper(_settings.MaxPlayers);
            DeviceProxy            deviceProxy  = new DeviceProxy();
            List <IMappableDevice> deviceList   = deviceProxy.GetDevices(false);
            MappingProxy           mappingProxy = new MappingProxy();

            foreach (PortMapping port in mappingProxy.PortMappings)
            {
                IMappableDevice device = deviceProxy.GetDevice(port.DeviceId, port.SubDeviceId, deviceList);
                if (device != null)
                {
                    RetroPadMapping mapping = mappingProxy.GetDeviceMapping(device);
                    device.Map(mapping);
                    _controllerWrapper.AddController(device, port.Port);
                    Logger.Debug("LibRetroFrontend: Mapped controller {0} to port {1}", device.DeviceName, port.Port);
                }
            }
        }
Beispiel #9
0
        public void Map(RetroPadMapping mapping)
        {
            foreach (var kvp in mapping.ButtonMappings)
            {
                Keys key;
                if (Enum.TryParse(kvp.Value.Id, out key))
                {
                    _buttonMappings[kvp.Key] = key;
                }
            }

            foreach (var kvp in mapping.AnalogMappings)
            {
                Keys key;
                if (Enum.TryParse(kvp.Value.Id, out key))
                {
                    _analogMappings[kvp.Key] = key;
                }
            }
        }
        static XBox360HidMapping()
        {
            RetroPadMapping mapping = new RetroPadMapping()
            {
                DeviceId = HidGameControl.DEVICE_ID, DeviceName = DEVICE_NAME
            };

            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.LEFT, new DeviceInput("Left", DirectionPadState.Left.ToString(), InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.RIGHT, new DeviceInput("Right", DirectionPadState.Right.ToString(), InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.UP, new DeviceInput("Up", DirectionPadState.Up.ToString(), InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.DOWN, new DeviceInput("Down", DirectionPadState.Down.ToString(), InputType.Button));

            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.A, new DeviceInput("2", "2", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.B, new DeviceInput("1", "1", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.X, new DeviceInput("4", "4", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.Y, new DeviceInput("3", "3", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.SELECT, new DeviceInput("7", "7", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.START, new DeviceInput("8", "8", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.L, new DeviceInput("5", "5", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.R, new DeviceInput("6", "6", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.L3, new DeviceInput("9", "9", InputType.Button));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.R3, new DeviceInput("10", "10", InputType.Button));

            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.L2, new DeviceInput("Z", "50", InputType.Axis, true));
            mapping.MapButton(RETRO_DEVICE_ID_JOYPAD.R2, new DeviceInput("Z", "50", InputType.Axis, false));

            mapping.MapAnalog(RetroAnalogDevice.LeftThumbLeft, new DeviceInput("X", "48", InputType.Axis, false));
            mapping.MapAnalog(RetroAnalogDevice.LeftThumbRight, new DeviceInput("X", "48", InputType.Axis, true));
            mapping.MapAnalog(RetroAnalogDevice.LeftThumbUp, new DeviceInput("Y", "49", InputType.Axis, false));
            mapping.MapAnalog(RetroAnalogDevice.LeftThumbDown, new DeviceInput("Y", "49", InputType.Axis, true));

            mapping.MapAnalog(RetroAnalogDevice.RightThumbLeft, new DeviceInput("Rx", "51", InputType.Axis, false));
            mapping.MapAnalog(RetroAnalogDevice.RightThumbRight, new DeviceInput("Rx", "51", InputType.Axis, true));
            mapping.MapAnalog(RetroAnalogDevice.RightThumbUp, new DeviceInput("Ry", "52", InputType.Axis, false));
            mapping.MapAnalog(RetroAnalogDevice.RightThumbDown, new DeviceInput("Ry", "52", InputType.Axis, true));

            DefaultMapping = mapping;
        }
        public void Map(RetroPadMapping mapping)
        {
            if (mapping == null)
            {
                mapping = DefaultMapping;
            }
            ClearMappings();

            int percent = mapping.DeadZone;

            if (percent < 0)
            {
                _thumbDeadZone   = DEFAULT_THUMB_DEADZONE;
                _triggerDeadZone = DEFAULT_TRIGGER_DEADZONE;
            }
            else
            {
                short deadZone = percent < 100 ? (short)(short.MaxValue * 100 / percent) : short.MaxValue;
                _thumbDeadZone   = deadZone;
                _triggerDeadZone = deadZone;
            }

            foreach (var kvp in mapping.ButtonMappings)
            {
                DeviceInput deviceInput = kvp.Value;
                if (deviceInput.InputType == InputType.Button)
                {
                    GamepadButtonFlags button;
                    if (Enum.TryParse(deviceInput.Id, out button))
                    {
                        _buttonToButtonMappings[kvp.Key] = button;
                    }
                }
                else if (deviceInput.InputType == InputType.Axis)
                {
                    XInputAxisType analogInput;
                    if (Enum.TryParse(deviceInput.Id, out analogInput))
                    {
                        _analogToButtonMappings[kvp.Key] = new XInputAxis(analogInput, deviceInput.PositiveValues);
                    }
                }
            }

            foreach (var kvp in mapping.AnalogMappings)
            {
                DeviceInput deviceInput = kvp.Value;
                if (deviceInput.InputType == InputType.Button)
                {
                    GamepadButtonFlags button;
                    if (Enum.TryParse(deviceInput.Id, out button))
                    {
                        _buttonToAnalogMappings[kvp.Key] = button;
                    }
                }
                else if (deviceInput.InputType == InputType.Axis)
                {
                    XInputAxisType analogInput;
                    if (Enum.TryParse(deviceInput.Id, out analogInput))
                    {
                        _analogToAnalogMappings[kvp.Key] = new XInputAxis(analogInput, deviceInput.PositiveValues);
                    }
                }
            }
        }