Exemplo n.º 1
0
        private List <GamepadButton> RetrieveButton(OpenTK.Input.ButtonState state)
        {
            List <GamepadButton> ans = new List <GamepadButton>();

            if (_newState.GamepadState.Buttons.A == state)
            {
                ans.Add(GamepadButton.A);
            }
            if (_newState.GamepadState.Buttons.B == state)
            {
                ans.Add(GamepadButton.B);
            }
            if (_newState.GamepadState.Buttons.X == state)
            {
                ans.Add(GamepadButton.X);
            }
            if (_newState.GamepadState.Buttons.Y == state)
            {
                ans.Add(GamepadButton.Y);
            }
            //Shoulder buttons
            if (_newState.GamepadState.Buttons.LeftShoulder == state)
            {
                ans.Add(GamepadButton.LB);
            }
            if (_newState.GamepadState.Buttons.RightShoulder == state)
            {
                ans.Add(GamepadButton.RB);
            }
            //Start/select/xbox button
            if (_newState.GamepadState.Buttons.Start == state)
            {
                ans.Add(GamepadButton.Start);
            }
            if (_newState.GamepadState.Buttons.Back == state)
            {
                ans.Add(GamepadButton.Back);
            }
            if (_newState.GamepadState.Buttons.BigButton == state)
            {
                ans.Add(GamepadButton.BigButton);
            }
            //Dpad
            if (_newState.GamepadState.DPad.IsUp)
            {
                ans.Add(GamepadButton.DPadUp);
            }
            if (_newState.GamepadState.DPad.IsDown)
            {
                ans.Add(GamepadButton.DPadDown);
            }
            if (_newState.GamepadState.DPad.IsLeft)
            {
                ans.Add(GamepadButton.DPadLeft);
            }
            if (_newState.GamepadState.DPad.IsRight)
            {
                ans.Add(GamepadButton.DPadRight);
            }
            //Joysticks buttons
            if (_newState.GamepadState.Buttons.LeftStick == state)
            {
                ans.Add(GamepadButton.JoystickLeft);
            }
            if (_newState.GamepadState.Buttons.RightStick == state)
            {
                ans.Add(GamepadButton.JoystickRight);
            }
            return(ans);
        }
Exemplo n.º 2
0
 protected bool IsUniqueClick(MouseState state, OpenTK.Input.ButtonState buttonState,
                              OpenTK.Input.ButtonState lastButtonState)
 {
     return(buttonState == OpenTK.Input.ButtonState.Pressed &&
            !(lastButtonState == OpenTK.Input.ButtonState.Pressed));
 }
        public void OpenTKGamePadInputRoll()
        {
            var State        = OpenTK.Input.GamePad.GetState(0);
            var Capabilities = controller.CapabilitiesGamePad;

            foreach (PropertyInfo buttonProperty in AvailableOTKButtonProperties)
            {
                OpenTK.Input.ButtonState CurrentButtonState = (OpenTK.Input.ButtonState)buttonProperty.GetValue(State.Buttons);
                OpenTK.Input.ButtonState OldButtonState     = (OpenTK.Input.ButtonState)buttonProperty.GetValue(State.Buttons);
                if (!Object.ReferenceEquals(OTKOldState, null))
                {
                    OldButtonState = (OpenTK.Input.ButtonState)buttonProperty.GetValue(OTKOldState.Buttons);
                }

                if (CurrentButtonState == OpenTK.Input.ButtonState.Pressed &&
                    (Object.ReferenceEquals(OTKOldState, null) || OldButtonState == OpenTK.Input.ButtonState.Released))
                {
                    CallButtonMapping(buttonProperty.Name, true);
                    System.Diagnostics.Debug.WriteLine($"{buttonProperty.Name} Pressed");
                }
                if (CurrentButtonState == OpenTK.Input.ButtonState.Released &&
                    (!Object.ReferenceEquals(OTKOldState, null) && OldButtonState == OpenTK.Input.ButtonState.Pressed))
                {
                    CallButtonMapping(buttonProperty.Name, false);
                    System.Diagnostics.Debug.WriteLine($"{buttonProperty.Name} Released");
                }
            }

            foreach (PropertyInfo buttonProperty in AvailableOTKDPadProperties)
            {
                Boolean CurrentDPadState = (Boolean)buttonProperty.GetValue(State.DPad);
                Boolean OldDPadState     = (Boolean)buttonProperty.GetValue(State.DPad);
                if (!Object.ReferenceEquals(OTKOldState, null))
                {
                    OldDPadState = (Boolean)buttonProperty.GetValue(OTKOldState.DPad);
                }

                if (CurrentDPadState == true &&
                    (Object.ReferenceEquals(OTKOldState, null) || OldDPadState == false))
                {
                    CallButtonMapping(buttonProperty.Name, true);
                    System.Diagnostics.Debug.WriteLine($"{buttonProperty.Name} Pressed");
                }
                if (CurrentDPadState == false &&
                    (!Object.ReferenceEquals(OTKOldState, null) && OldDPadState == true))
                {
                    CallButtonMapping(buttonProperty.Name, false);
                    System.Diagnostics.Debug.WriteLine($"{buttonProperty.Name} Released");
                }
            }

            PropertyInfo[] AvailableOTKTriggerProperties = typeof(OpenTK.Input.GamePadTriggers).GetProperties().ToArray();

            foreach (PropertyInfo buttonProperty in AvailableOTKTriggerProperties)
            {
                float CurrentTriggerState = (float)buttonProperty.GetValue(State.Triggers);
                float OldTriggerState     = (float)buttonProperty.GetValue(State.Triggers);
                if (!Object.ReferenceEquals(OTKOldState, null))
                {
                    OldTriggerState = (float)buttonProperty.GetValue(OTKOldState.Triggers);
                }

                if (CurrentTriggerState == 1 &&
                    (Object.ReferenceEquals(OTKOldState, null) || OldTriggerState == 0))
                {
                    CallButtonMapping(buttonProperty.Name, true);
                    System.Diagnostics.Debug.WriteLine($"{buttonProperty.Name} Trigger Pressed");
                }
                if (CurrentTriggerState == 0 &&
                    (!Object.ReferenceEquals(OTKOldState, null) && OldTriggerState == 1))
                {
                    CallButtonMapping(buttonProperty.Name, false);
                    System.Diagnostics.Debug.WriteLine($"{buttonProperty.Name} Trigger Released");
                }
            }

            var oldLeftX = Math.Round(OTKOldState.ThumbSticks.Left.X);
            var oldLeftY = Math.Round(OTKOldState.ThumbSticks.Left.Y);

            var newLeftX = Math.Round(State.ThumbSticks.Left.X);
            var newLeftY = Math.Round(State.ThumbSticks.Left.Y);

            if (oldLeftX == 0 && newLeftX == 1)
            {
                System.Diagnostics.Debug.WriteLine("Right Pushed");
                CallButtonMapping("IsRight", true);
            }

            if (oldLeftX == 1 && newLeftX == 0)
            {
                System.Diagnostics.Debug.WriteLine("Right Released");
                CallButtonMapping("IsRight", false);
            }

            if (oldLeftX == 0 && newLeftX == -1)
            {
                System.Diagnostics.Debug.WriteLine("Left Pushed");
                CallButtonMapping("IsLeft", true);
            }

            if (oldLeftX == -1 && newLeftX == 0)
            {
                System.Diagnostics.Debug.WriteLine("Left Released");
                CallButtonMapping("IsLeft", false);
            }

            if (oldLeftY == 0 && newLeftY == 1)
            {
                System.Diagnostics.Debug.WriteLine("Up Pushed");
                CallButtonMapping("IsUp", true);
            }

            if (oldLeftY == 1 && newLeftY == 0)
            {
                System.Diagnostics.Debug.WriteLine("Up Released");
                CallButtonMapping("IsUp", false);
            }

            if (oldLeftY == 0 && newLeftY == -1)
            {
                System.Diagnostics.Debug.WriteLine("Down Pushed");
                CallButtonMapping("IsDown", true);
            }

            if (oldLeftY == -1 && newLeftY == 0)
            {
                System.Diagnostics.Debug.WriteLine("Down Released");
                CallButtonMapping("IsDown", false);
            }

            OTKOldState = State;
        }