/// <summary> /// Responds to user input, accepting or cancelling the message box. /// </summary> public override void HandleInput(InputHelper 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 (input.IsMenuSelect(ControllingPlayer, out playerIndex)) { // Raise the accepted event, then exit the message box. if (Accepted != null) Accepted(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { // Raise the cancelled event, then exit the message box. if (Cancelled != null) Cancelled(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputHelper input) { // Move to the previous menu entry? if (input.IsMenuUp(ControllingPlayer)) { _selectedEntry--; if (_selectedEntry < 0) _selectedEntry = _menuEntries.Count - 1; } // Move to the next menu entry? if (input.IsMenuDown(ControllingPlayer)) { _selectedEntry++; if (_selectedEntry >= _menuEntries.Count) _selectedEntry = 0; } #if !XBOX // Mouse or touch on a menu item if (input.CurrentMouseState.X != input.LastMouseState.X || input.CurrentMouseState.Y != input.LastMouseState.Y) { int hoverIndex = GetMenuEntryAt(ref input.CurrentMouseState); if (hoverIndex > -1) { _selectedEntry = hoverIndex; } } if (input.CurrentMouseState.LeftButton == ButtonState.Released && input.LastMouseState.LeftButton == ButtonState.Pressed) { int index = GetMenuEntryAt(ref input.LastMouseState); if (index > -1) { _selectedEntry = index; OnSelectEntry(_selectedEntry, input.DefaultPlayerIndex); } } #endif // Accept or cancel the menu? 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; if (input.IsMenuSelect(ControllingPlayer, out playerIndex)) { OnSelectEntry(_selectedEntry, playerIndex); } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } }