コード例 #1
0
ファイル: InputAction.cs プロジェクト: Raynd/XNA_RPG
        /// <summary>
        /// Evaluates the action against a given InputState.
        /// </summary>
        /// <param name="state">The InputState to test for the action.</param>
        /// <param name="controllingPlayer">The player to test, or null to allow any player.</param>
        /// <param name="player">If controllingPlayer is null, this is the player that performed the action.</param>
        /// <returns>True if the action occurred, false otherwise.</returns>
        public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
        {
            // Figure out which delegate methods to map from the state which takes care of our "newPressOnly" logic
            ButtonPress buttonTest;
            KeyPress keyTest;
            if (newPressOnly)
            {
                buttonTest = state.IsNewButtonPress;
                keyTest = state.IsNewKeyPress;
            }
            else
            {
                buttonTest = state.IsButtonPressed;
                keyTest = state.IsKeyPressed;
            }

            // Now we simply need to invoke the appropriate methods for each button and key in our collections
            foreach (Buttons button in buttons)
            {
                if (buttonTest(button, controllingPlayer, out player))
                    return true;
            }
            foreach (Keys key in keys)
            {
                if (keyTest(key, controllingPlayer, out player))
                    return true;
            }

            // If we got here, the action is not matched
            player = PlayerIndex.One;
            return false;
        }
コード例 #2
0
ファイル: RankingScreen.cs プロジェクト: rroveri/triolozzi
        /// <summary>
        /// Responds to user input when cancelling the ranking screen.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex;

            if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));
            }
        }
コード例 #3
0
ファイル: LoadingScreen.cs プロジェクト: rroveri/triolozzi
 public override void HandleInput(GameTime gameTime, InputState input)
 {
     PlayerIndex playerIndex;
     base.HandleInput(gameTime, input);
     if (_isReady && StartAction.Evaluate(input, null, out playerIndex))
     {
         GameServices.GetService<SoundManager>().StopSong();
         ScreenManager.ShowScreen<GameScreen>();
     }
     if (switchTutorialAction.Evaluate(input, null, out playerIndex))
     {
         currentTutorial++;
         if (currentTutorial >= _tutorials.Length) currentTutorial = 0;
     }
 }
コード例 #4
0
ファイル: InputAction.cs プロジェクト: rroveri/triolozzi
        /// <summary>
        /// Evaluates the action against a given InputState.
        /// </summary>
        /// <param name="state">The InputState to test for the action.</param>
        /// <param name="controllingPlayer">The player to test, or null to allow any player.</param>
        /// <param name="player">If controllingPlayer is null, this is the player that performed the action.</param>
        /// <returns>True if the action occurred, false otherwise.</returns>
        public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
        {
            // Figure out which delegate methods to map from the state which takes care of our "newPressOnly" logic
            if (newPressOnly)
            {
                buttonTest = state.IsNewButtonPress;
                keyTest = state.IsNewKeyPress;
            }
            else
            {
                buttonTest = state.IsButtonPressed;
                keyTest = state.IsKeyPressed;
            }

            // Now we simply need to invoke the appropriate methods for each button and key in our collections
            for (int i = 0; i < buttons.Length; i++)
            {
                if (buttonTest(buttons[i], controllingPlayer, out player))
                {
                    playMenuSound();
                    return true;
                }
            }
            for (int i = 0; i < keys.Length; i++)
            {
                if (keyTest(keys[i], controllingPlayer, out player))
                {
                    playMenuSound();
                    return true;
                }
            }

            // If we got here, the action is not matched
            player = PlayerIndex.One;
            return false;
        }
コード例 #5
0
ファイル: MenuScreen.cs プロジェクト: Raynd/XNA_RPG
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            // For input tests we pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            // Move to the previous menu entry?
            if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
コード例 #6
0
ファイル: MessageBoxScreen.cs プロジェクト: Raynd/XNA_RPG
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
コード例 #7
0
ファイル: AbstractScreen.cs プロジェクト: rroveri/triolozzi
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(GameTime gameTime, InputState input)
 {
 }
コード例 #8
0
ファイル: OptionsScreen.cs プロジェクト: Raynd/XNA_RPG
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex;

            if (menuAccept.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                aiFlag = 1;
                game.SetAiFlag(aiFlag);

                OpponentAI ai = new OpponentAI(game);
                game.Components.Add(ai);
                ai.LoadCursor(game);

                game.Services.AddService(typeof(OpponentAI), ai);
                PlayerManager tempRef = (PlayerManager)game.Services.GetService(typeof(PlayerManager));
                tempRef.LoadAI(game);

                ExitScreen();
            }
            if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                aiFlag = 0;
                game.SetAiFlag(aiFlag);
                ExitScreen();
            }
        }
コード例 #9
0
ファイル: PopupScreen.cs プロジェクト: Raynd/XNA_RPG
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (menuMove.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                if (selectedChar == null || selectedChar.HasMoved == true)
                {
                    selectScreen.ExitScreen();
                    screenManager.RemoveScreen(selectScreen);
                }
                else
                {
                    cursor.MoveHelper(selectedChar);
                    selectedChar.HasMoved = true;
                    ExitScreen();
                    selectScreen.ExitScreen();
                    screenManager.RemoveScreen(selectScreen);
                }
            }
            else if (menuAttack.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                if (selectedChar == null || selectedChar.HasAttacked == true)
                {
                    selectScreen.ExitScreen();
                    screenManager.RemoveScreen(selectScreen);
                }
                else
                {
                    cursor.AttackHelper(selectedChar);
                    selectedChar.HasAttacked = true;
                    ExitScreen();
                    selectScreen.ExitScreen();
                    screenManager.RemoveScreen(selectScreen);
                }
            }

            else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                ExitScreen();
                selectScreen.ExitScreen();
                screenManager.RemoveScreen(selectScreen);
            }

            else if (menuEndTurn.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                playerManager.EndTurn();
                ExitScreen();
                selectScreen.ExitScreen();
                screenManager.RemoveScreen(selectScreen);
            }
            else if (menuBuy.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                if (selectedChar == null || selectedChar.CharType != "champion")
                {
                    gameStateManager.State = GameState.playing;
                    ExitScreen();
                    selectScreen.ExitScreen();
                    screenManager.RemoveScreen(selectScreen);
                }
                else
                {
                    selectedChar.BuyMercenary();
                    ExitScreen();
                    selectScreen.ExitScreen();
                    screenManager.RemoveScreen(selectScreen);
                }
            }
        }
コード例 #10
0
ファイル: SelectScreen.cs プロジェクト: Raynd/XNA_RPG
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
        }
コード例 #11
0
ファイル: GameplayScreen.cs プロジェクト: Raynd/XNA_RPG
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            PlayerIndex player;
            if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
        }