Exemplo n.º 1
0
        /// <summary>
        /// Sends a message meant to tell listeners to that a trigger has been recently released.
        /// </summary>
        /// <param name="triggerType">Type of trigger</param>
        /// <param name="player">Index of player's controller (1-4)</param>
        /// <param name="gameTime">Snapshot of game's timing state</param>
        private void SendTriggerReleaseMessage(GamePadInputSide triggerType, PlayerIndex player, GameTime gameTime)
        {
            MsgGamePadTriggerReleased triggerMessage = ObjectPool.Aquire <MsgGamePadTriggerReleased>();

            triggerMessage.GamePadInputSide = triggerType;
            triggerMessage.PlayerIndex      = player;
            triggerMessage.Time             = gameTime;
            this.Game.SendMessage(triggerMessage);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Message handler for the input polling handler.
        /// </summary>
        /// <param name="message">Incoming message</param>
        private void Game_GameMessage(IMessage message)
        {
            switch (message.Type)
            {
            case MessageType.KeyDown:
                MsgKeyPressed keyDownMessage = message as MsgKeyPressed;
                message.TypeCheck(keyDownMessage);

                Press(keyDownMessage.Key);
                break;

            case MessageType.KeyUp:
                MsgKeyReleased keyUpMessage = message as MsgKeyReleased;
                message.TypeCheck(keyUpMessage);

                Release(keyUpMessage.Key);
                break;

            case MessageType.KeyHeld:
                MsgKeyHeld keyPressMessage = message as MsgKeyHeld;
                message.TypeCheck(keyPressMessage);

                SetHeld(keyPressMessage.Key, true);
                break;

            case MessageType.MouseDown:
                MsgMouseButtonPressed mouseDownMessage = message as MsgMouseButtonPressed;
                message.TypeCheck(mouseDownMessage);

                Press(mouseDownMessage.Button);
                break;

            case MessageType.MouseUp:
                MsgMouseButtonReleased mouseUpMessage = message as MsgMouseButtonReleased;
                message.TypeCheck(mouseUpMessage);

                Release(mouseUpMessage.Button);
                break;

            case MessageType.MouseHeld:
                MsgMouseButtonHeld mousePressMessage = message as MsgMouseButtonHeld;
                message.TypeCheck(mousePressMessage);

                SetHeld(mousePressMessage.Button, true);
                break;

            case MessageType.Thumbstick:
                MsgGamePadThumbstick thumbstickMessage = message as MsgGamePadThumbstick;
                message.TypeCheck(thumbstickMessage);

                // Store previous state
                this.previousThumbsticks[(int)thumbstickMessage.PlayerIndex, (int)thumbstickMessage.StickType] =
                    this.thumbsticks[(int)thumbstickMessage.PlayerIndex, (int)thumbstickMessage.StickType];

                this.thumbsticks[(int)thumbstickMessage.PlayerIndex, (int)thumbstickMessage.StickType] =
                    thumbstickMessage.StickValues;
                break;

            case MessageType.ThumbstickRelease:
                MsgGamePadThumbstickReleased thumbstickReleaseMessage = message as MsgGamePadThumbstickReleased;
                message.TypeCheck(thumbstickReleaseMessage);

                // Store previous state
                this.previousThumbsticks[(int)thumbstickReleaseMessage.PlayerIndex, (int)thumbstickReleaseMessage.StickType] =
                    this.thumbsticks[(int)thumbstickReleaseMessage.PlayerIndex, (int)thumbstickReleaseMessage.StickType];

                ReleaseThumbstick(thumbstickReleaseMessage.Data);
                break;

            case MessageType.Trigger:
                MsgGamePadTrigger triggerMessage = message as MsgGamePadTrigger;
                message.TypeCheck(triggerMessage);

                // Store previous state
                this.previousTriggers[(int)triggerMessage.PlayerIndex, (int)triggerMessage.GamePadInputSide] =
                    this.triggers[(int)triggerMessage.PlayerIndex, (int)triggerMessage.GamePadInputSide];

                this.triggers[(int)triggerMessage.PlayerIndex, (int)triggerMessage.GamePadInputSide] =
                    triggerMessage.TriggerValue;
                break;

            case MessageType.TriggerRelease:
                MsgGamePadTriggerReleased triggerReleaseMessage = message as MsgGamePadTriggerReleased;
                message.TypeCheck(triggerReleaseMessage);

                // Store previous state
                previousTriggers[(int)triggerReleaseMessage.PlayerIndex, (int)triggerReleaseMessage.GamePadInputSide] =
                    triggers[(int)triggerReleaseMessage.PlayerIndex, (int)triggerReleaseMessage.GamePadInputSide];

                ReleaseTrigger(triggerReleaseMessage.Data);
                break;

            case MessageType.ButtonDown:
                MsgGamePadButtonPressed buttonDownMessage = message as MsgGamePadButtonPressed;
                message.TypeCheck(buttonDownMessage);

                Press(buttonDownMessage.Button, buttonDownMessage.PlayerIndex);
                break;

            case MessageType.ButtonUp:
                MsgGamePadButtonReleased buttonUpMessage = message as MsgGamePadButtonReleased;
                message.TypeCheck(buttonUpMessage);

                Release(buttonUpMessage.Button, buttonUpMessage.PlayerIndex);
                break;

            case MessageType.ButtonHeld:
                MsgGamePadButtonHeld buttonHeldMessage = message as MsgGamePadButtonHeld;
                message.TypeCheck(buttonHeldMessage);

                SetHeld(buttonHeldMessage.Button, buttonHeldMessage.PlayerIndex, true);
                break;
            }
        }