/// <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; }
/// <summary> /// Evaluates the action against a given InputState. /// </summary> /// <param name="inState">The InputState to test for the action.</param> /// <returns>True if the action occurred and false otherwise.</returns> public bool Evaluate( InputState inState ) { bool result = false; if ( isBtnAction ) { // The action corresponds to a mouse button press if ( newPressOnly ) { result = inState.IsNewMousePress( button ); } else { result = inState.IsMousePressed( button ); } } else { // The action corresponds to a mouse cursor action Point curCursor = inState.CurrentCursorPosition(); // Position of the cursor on current frame Point prevCursor = inState.LastCursorPosition(); // Position of the cursor on the last frame switch ( cursorAction ) { case MouseCursorAction.Enter: result = ( !hotZone.Contains( prevCursor ) && hotZone.Contains( curCursor ) ); break; case MouseCursorAction.Hover: result = hotZone.Contains( curCursor ); break; case MouseCursorAction.Leave: result = ( hotZone.Contains( prevCursor ) && !hotZone.Contains( curCursor ) ); break; } } return result; }
/// <summary> /// Responds to user input, accepting or cancelling the message box. /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { upg1.HandleInputs(gameTime, input); upg2.HandleInputs(gameTime, input); upg3.HandleInputs(gameTime, input); upg4.HandleInputs(gameTime, input); upg5.HandleInputs(gameTime, input); upg6.HandleInputs(gameTime, input); accept.HandleInputs(gameTime, input); //cancel.HandleInputs(gameTime, input); }
public override void HandleInput(GameTime gameTime, InputState input) { PlayerIndex playerIndex; // Any UI elements that use the InputState can be handled here if (escapePressed.Evaluate(input, null, out playerIndex)) { PopOutExit(); } if (uPressed.Evaluate(input, null, out playerIndex)) { DisplayUpgrades(); } if (cPress.Evaluate(input, null, out playerIndex)) { player.RoleID = ((player.RoleID + 1) % 4); } if (bPress.Evaluate(input, null, out playerIndex)) { drawBB = !drawBB; } }
/// <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) { }
public override void HandleInput( GameTime gameTime, InputState input ) { // Let the Controls handle their input backButton.HandleInputs( gameTime, input ); refreshButton.HandleInputs( gameTime, input ); joinButton.HandleInputs( gameTime, input ); lobbies.HandleInputs( gameTime, input ); newLobbyButton.HandleInputs( gameTime, input ); }
public override void HandleInput( GameTime gameTime, InputState input ) { // Let the Controls handle their input PlayerIndex playerIndex; if ( escapePressed.Evaluate( input, null, out playerIndex ) ) { ShowQuitDialog(); } if ( uPressed.Evaluate( input, null, out playerIndex ) ) { ScreenManager.AddScreen( new UpgradeMenu( GameManager.Instance ), null ); } }
/// <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) { #if WINDOWS_PHONE ScreenManager.AddScreen(new PhonePauseScreen(), ControllingPlayer); #else ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); #endif } else { // Otherwise move the player position. Vector2 movement = Vector2.Zero; if (keyboardState.IsKeyDown(Keys.Left)) movement.X--; if (keyboardState.IsKeyDown(Keys.Right)) movement.X++; if (keyboardState.IsKeyDown(Keys.Up)) movement.Y--; if (keyboardState.IsKeyDown(Keys.Down)) movement.Y++; Vector2 thumbstick = gamePadState.ThumbSticks.Left; movement.X += thumbstick.X; movement.Y -= thumbstick.Y; if (input.TouchState.Count > 0) { Vector2 touchPosition = input.TouchState[0].Position; Vector2 direction = touchPosition - playerPosition; direction.Normalize(); movement += direction; } if (movement.Length() > 1) movement.Normalize(); playerPosition += movement * 8f; } }
public override void HandleInput( GameTime gameTime, InputState input ) { // Let the Controls handle their input backButton.HandleInputs( gameTime, input ); priestButton.HandleInputs(gameTime, input); fireButton.HandleInputs(gameTime, input); bmButton.HandleInputs(gameTime, input); windButton.HandleInputs(gameTime, input); }
/// <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; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player)) { // Game Paused ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Tell the buttons to handle their inputs testBtn1.HandleInputs( gameTime, input ); testBtn2.HandleInputs( gameTime, input ); testlistView.HandleInputs(gameTime, input); testSelector.HandleInputs(gameTime, input); } }
public override void HandleInput( GameTime gameTime, InputState input ) { // Let the Controls handle their input spButton.HandleInputs( gameTime, input ); mpButton.HandleInputs( gameTime, input ); optionsButton.HandleInputs( gameTime, input ); achiButton.HandleInputs( gameTime, input ); exitButton.HandleInputs( gameTime, input ); }
/// <summary> /// Responds to user input, accepting or cancelling the message box. /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { if ( style == Style.YesNo ) { accept.HandleInputs(gameTime, input); cancel.HandleInputs(gameTime, input); } else if ( style == Style.OK ) { accept.HandleInputs( gameTime, input ); } }
/// <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); } }
public override void HandleInput( GameTime gameTime, InputState input ) { // Let the Controls handle their input backButton.HandleInputs( gameTime, input ); teamButton.HandleInputs( gameTime, input ); roleButton.HandleInputs( gameTime, input ); readyButton.HandleInputs( gameTime, input ); //redTeamList.HandleInputs( gameTime, input ); //blueTeamList.HandleInputs( gameTime, input ); }
public override void HandleInput( GameTime gameTime, InputState input ) { // Let the Controls handle their input backButton.HandleInputs( gameTime, input ); matchDurSel.HandleInputs( gameTime, input ); numPlayersSel.HandleInputs( gameTime, input ); createButton.HandleInputs( gameTime, input ); }
public override void HandleInput( GameTime gameTime, InputState input ) { // Let the Controls handle their input backButton.HandleInputs( gameTime, input ); musicSel.HandleInputs( gameTime, input ); }
/// <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(); } }