Exemple #1
0
 public SystemJoystickValue( JoystickPOVs pov, JoystickPOVDirections povDirection )
 {
     type = Types.POV;
     this.pov = pov;
     this.povDirection = povDirection;
 }
Exemple #2
0
            void UpdatePOVControls()
            {
                PageControl.Controls[ "POVs" ].ColorMultiplier =
                    ( selectedJoystick != null && selectedJoystick.POVs.Length > 0 ) ?
                    enabledColor : disabledColor;

                for( int n = 0; n < 3; n++ )
                {
                    JoystickInputDevice.POV pov = null;
                    if( selectedJoystick != null && n < selectedJoystick.POVs.Length )
                        pov = selectedJoystick.POVs[ n ];

                    string labelName = string.Format( "POV{0}Name", n + 1 );
                    string name = string.Format( "POV{0}", n + 1 );
                    Control labelControl = PageControl.Controls[ labelName ];
                    Control control = PageControl.Controls[ name ];
                    labelControl.ColorMultiplier = pov != null ? enabledColor : disabledColor;
                    control.ColorMultiplier = pov != null ? enabledColor : disabledColor;

                    //update POV buttons
                    {
                        JoystickPOVDirections[] directions = new JoystickPOVDirections[]
                        {
                            JoystickPOVDirections.North,
                            JoystickPOVDirections.South,
                            JoystickPOVDirections.East,
                            JoystickPOVDirections.West
                        };

                        foreach( JoystickPOVDirections direction in directions )
                        {
                            bool pressed = pov != null && ( pov.Value & direction ) > 0;

                            string buttonName = string.Format( "Button{0}", direction );
                            Control buttonControl = control.Controls[ buttonName ];
                            buttonControl.ColorMultiplier = pressed ? pressedColor : new ColorValue( 1, 1, 1 );
                        }
                    }
                }
            }
 public SystemJoystickValue(JoystickPOVs pov, JoystickPOVDirections povDirection, float strength)
 {
     type = Types.POV;
     this.pov = pov;
     this.povDirection = povDirection;
     this.strength = strength;
 }
Exemple #4
0
 public DefaultJoystickValueAttribute( JoystickPOVs pov, JoystickPOVDirections direction )
 {
     value = new GameControlsManager.SystemJoystickValue( pov, direction );
 }
 public SystemJoystickValue(SystemJoystickValue source)
 {
     type = source.Type;
     button = source.Button;
     axis = source.Axis;
     axisFilter = source.AxisFilter;
     pov = source.POV;
     povDirection = source.POVDirection;
     _parent = source.Parent;
     strength = source.strength;
 }
 /// <summary>
 /// Check if the Given Input is Binded. Return the currently binded control to the input
 /// </summary>
 public bool IsAlreadyBinded(JoystickPOVs pov, JoystickPOVDirections dir, out SystemJoystickValue control)
 {
     control = null;
     foreach (GameControlItem item in Items)
     {
         if (item.BindedJoystickValues.Count <= 0)
             continue;
         foreach (SystemJoystickValue value in item.BindedJoystickValues)
         {
             if (value.Type == SystemJoystickValue.Types.POV && value.POV == pov && value.POVDirection == dir)
             {
                 control = value;
                 return true;
             }
         }
     }
     return false;
 }
Exemple #7
0
 public DefaultJoystickValueAttribute(JoystickPOVs pov, JoystickPOVDirections direction)
 {
     value = new GameControlsManager.SystemJoystickValue(pov, direction);
 }
Exemple #8
0
 public SystemJoystickValue(JoystickPOVs pov, JoystickPOVDirections povDirection)
 {
     type              = Types.POV;
     this.pov          = pov;
     this.povDirection = povDirection;
 }
        protected override void OnUpdateState()
        {
            XINPUT_STATE state = new XINPUT_STATE();

            int result = XInput.GetState(controllerIndex, ref state);

            if (XInputNativeWrapper.Wrapper.FAILED(result))
            {
                return;
            }

            ////////////////////////////////////////

            if (state.Gamepad.sThumbLX < XInput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE &&
                state.Gamepad.sThumbLX > -XInput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
            {
                state.Gamepad.sThumbLX = 0;
            }

            if (state.Gamepad.sThumbLY < XInput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE &&
                state.Gamepad.sThumbLY > -XInput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
            {
                state.Gamepad.sThumbLY = 0;
            }

            if (state.Gamepad.sThumbRX < XInput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
                state.Gamepad.sThumbRX > -XInput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
            {
                state.Gamepad.sThumbRX = 0;
            }

            if (state.Gamepad.sThumbRY < XInput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
                state.Gamepad.sThumbRY > -XInput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
            {
                state.Gamepad.sThumbRY = 0;
            }

            if (state.Gamepad.bLeftTrigger < XInput.XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
            {
                state.Gamepad.bLeftTrigger = 0;
            }

            if (state.Gamepad.bRightTrigger < XInput.XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
            {
                state.Gamepad.bRightTrigger = 0;
            }

            ////////////////////////////////////////

            JoystickPOVDirections direction = JoystickPOVDirections.Centered;

            if ((state.Gamepad.wButtons & XInput.XINPUT_GAMEPAD_DPAD_DOWN) != 0)
            {
                direction |= JoystickPOVDirections.South;
            }
            if ((state.Gamepad.wButtons & XInput.XINPUT_GAMEPAD_DPAD_UP) != 0)
            {
                direction |= JoystickPOVDirections.North;
            }
            if ((state.Gamepad.wButtons & XInput.XINPUT_GAMEPAD_DPAD_RIGHT) != 0)
            {
                direction |= JoystickPOVDirections.East;
            }
            if ((state.Gamepad.wButtons & XInput.XINPUT_GAMEPAD_DPAD_LEFT) != 0)
            {
                direction |= JoystickPOVDirections.West;
            }

            if (POVs[0].Value != direction)
            {
                POVs[0].Value = direction;

                InputDeviceManager.Instance.SendEvent(
                    new JoystickPOVChangedEvent(this, POVs[0]));
            }

            ////////////////////////////////////////

            for (int n = 0; n < 10; n++)
            {
                uint bits = 0;

                switch (n)
                {
                case 0: bits = XInput.XINPUT_GAMEPAD_A; break;

                case 1: bits = XInput.XINPUT_GAMEPAD_B; break;

                case 2: bits = XInput.XINPUT_GAMEPAD_X; break;

                case 3: bits = XInput.XINPUT_GAMEPAD_Y; break;

                case 4: bits = XInput.XINPUT_GAMEPAD_LEFT_SHOULDER; break;

                case 5: bits = XInput.XINPUT_GAMEPAD_RIGHT_SHOULDER; break;

                case 6: bits = XInput.XINPUT_GAMEPAD_BACK; break;

                case 7: bits = XInput.XINPUT_GAMEPAD_START; break;

                case 8: bits = XInput.XINPUT_GAMEPAD_LEFT_THUMB; break;

                case 9: bits = XInput.XINPUT_GAMEPAD_RIGHT_THUMB; break;
                }

                bool pressed = (state.Gamepad.wButtons & bits) != 0;

                if (Buttons[n].Pressed != pressed)
                {
                    Buttons[n].Pressed = pressed;

                    if (pressed)
                    {
                        InputDeviceManager.Instance.SendEvent(
                            new JoystickButtonDownEvent(this, Buttons[n]));
                    }
                    else
                    {
                        InputDeviceManager.Instance.SendEvent(
                            new JoystickButtonUpEvent(this, Buttons[n]));
                    }
                }
            }

            ////////////////////////////////////////

            {
                float value = (float)state.Gamepad.sThumbLX;
                value /= (value > 0) ? 32767.0f : 32768.0f;

                if (Axes[0].Value != value)
                {
                    Axes[0].Value = value;
                    InputDeviceManager.Instance.SendEvent(
                        new JoystickAxisChangedEvent(this, Axes[0]));
                }
            }

            {
                float value = (float)state.Gamepad.sThumbLY;
                value /= (value > 0) ? 32767.0f : 32768.0f;

                if (Axes[1].Value != value)
                {
                    Axes[1].Value = value;
                    InputDeviceManager.Instance.SendEvent(
                        new JoystickAxisChangedEvent(this, Axes[1]));
                }
            }

            {
                float value = (float)state.Gamepad.sThumbRX;
                value /= (value > 0) ? 32767.0f : 32768.0f;

                if (Axes[2].Value != value)
                {
                    Axes[2].Value = value;
                    InputDeviceManager.Instance.SendEvent(
                        new JoystickAxisChangedEvent(this, Axes[2]));
                }
            }

            {
                float value = (float)state.Gamepad.sThumbRY;
                value /= (value > 0) ? 32767.0f : 32768.0f;

                if (Axes[3].Value != value)
                {
                    Axes[3].Value = value;
                    InputDeviceManager.Instance.SendEvent(
                        new JoystickAxisChangedEvent(this, Axes[3]));
                }
            }

            {
                float value = (float)state.Gamepad.bLeftTrigger / 255.0f;

                if (Axes[4].Value != value)
                {
                    Axes[4].Value = value;
                    InputDeviceManager.Instance.SendEvent(
                        new JoystickAxisChangedEvent(this, Axes[4]));
                }
            }

            {
                float value = (float)state.Gamepad.bRightTrigger / 255.0f;

                if (Axes[5].Value != value)
                {
                    Axes[5].Value = value;
                    InputDeviceManager.Instance.SendEvent(
                        new JoystickAxisChangedEvent(this, Axes[5]));
                }
            }
        }