protected override void Disconnected()
 {
     base.Disconnected();
     Triggers    = new XboxGamepadTriggers();
     ThumbSticks = new XboxGamepadThumbSticks();
     Buttons     = new XboxGamepadButtons();
 }
示例#2
0
 /// <summary>
 /// Returns whether the given buttons are pressed.
 /// </summary>
 /// <param name="buttons">The buttons to check.</param>
 /// <returns>True if all the given buttons are pressed.</returns>
 public bool AreButtonsPressed(XboxGamepadButtons buttons)
 {
     return((this.State.Buttons & buttons) == buttons);
 }
        public override void Update(int delta)
        {
            base.Update(delta);

            if (!RawState.HasValue || !IsConnected)
            {
                return;
            }

            bool hasReceivedInput = false;

            // buttons
            XboxInputLabel.Buttons buttons = XboxInputLabel.Buttons.None;

            if (RawState.HasValue)
            {
                if (RawState.Value.Buttons.A == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.A;
                }

                if (RawState.Value.Buttons.B == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.B;
                }

                if (RawState.Value.Buttons.X == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.X;
                }

                if (RawState.Value.Buttons.Y == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.Y;
                }

                if (RawState.Value.Buttons.LeftShoulder == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.LB;
                }

                if (RawState.Value.Buttons.RightShoulder == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.RB;
                }

                if (RawState.Value.Buttons.LeftStick == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.LeftStick;
                }

                if (RawState.Value.Buttons.RightStick == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.RightStick;
                }

                if (RawState.Value.Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.Back;
                }

                if (RawState.Value.Buttons.Start == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.Start;
                }

                if (RawState.Value.Buttons.BigButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.BigButton;
                }

                if (RawState.Value.DPad.Up == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.DUp;
                }

                if (RawState.Value.DPad.Right == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.DRight;
                }

                if (RawState.Value.DPad.Down == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.DDown;
                }

                if (RawState.Value.DPad.Left == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    buttons |= XboxInputLabel.Buttons.DLeft;
                }

                if ((ulong)buttons != 0UL)
                {
                    hasReceivedInput = true;
                }

                // triggers
                Triggers = new XboxGamepadTriggers(RawState.Value.Triggers);

                // thumbsticks
                ThumbSticks = new XboxGamepadThumbSticks(RawState.Value.ThumbSticks);
            }
            else
            {
                // triggers
                Triggers = new XboxGamepadTriggers();

                // thumbsticks
                ThumbSticks = new XboxGamepadThumbSticks();
            }

            Buttons = new XboxGamepadButtons(buttons);

            if (hasReceivedInput)
            {
                ReceiveAnyInput();
            }
        }