public virtual bool HandleMouseInput(InputState input) { var paintedArea = mRectangle; paintedArea.Y -= (int)mOrigin.Y; paintedArea.X += (int)Padding.X; if (paintedArea.Contains(input.CurrentMouseState.X, input.CurrentMouseState.Y) && input.IsNewMouseState() && State != UIState.Inactive) { if (input.IsNewRightMouseClick() || input.IsNewLeftMouseClick()) OnPressedElement(PlayerIndex.One, 0); return true; } return false; }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState input) { var before = selectedEntry; // 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; } int yPosition = 150; bool pressed = false; for (int i = 0; i < menuEntries.Count; i++) { if (input.LastMouseState.Y > yPosition - menuEntries[i].GetHeight(this)/2 && input.IsNewMouseState() && input.LastMouseState.Y < yPosition + menuEntries[i].GetHeight(this)/2) { selectedEntry = i; pressed = input.IsNewLeftMouseClick(); break; } yPosition += menuEntries[i].GetHeight(this); } if(selectedEntry != before) { AudioSettings settings = (ScreenManager.Game as HalfCakedGame).CurrentProfile.Audio; EntryFocusChanged.Play(settings.SoundEffectsVolume / 500f, 0f, 0f); } // 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) || pressed) { OnSelectEntry(selectedEntry, playerIndex); } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } }
/// <summary> /// Responds to user input, accepting or cancelling the message box. /// </summary> public override void HandleInput(InputState input) { ScreenManager.Game.IsMouseVisible = true; PlayerIndex playerIndex; int state = -2; var prevButton = mSelectedButton; if (input.IsNextButton(ControllingPlayer)) { do mSelectedButton = (mSelectedButton + 1) % Buttons.Count; while(Buttons[mSelectedButton].State == Button.ButtonState.Inactive); } if (input.IsPreviousButton(ControllingPlayer)) { do mSelectedButton = (mSelectedButton - 1 + Buttons.Count) % Buttons.Count; while(Buttons[mSelectedButton].State == Button.ButtonState.Inactive); } for(int i = 0; i < Buttons.Count; i++) if (Buttons[i].Contains(input.CurrentMouseState.X, input.CurrentMouseState.Y) && input.IsNewMouseState() && Buttons[i].State != Button.ButtonState.Inactive) { mSelectedButton = i; if (input.IsNewLeftMouseClick()) { state = i; } } if (prevButton != mSelectedButton) { Buttons[prevButton].State = Button.ButtonState.Active; Buttons[mSelectedButton].State = Button.ButtonState.Selected; } if (input.IsMenuSelect(ControllingPlayer, out playerIndex) && !input.IsNewLeftMouseClick()) { state = mSelectedButton; } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { state = -1; } switch (state) { case -2: break; case -1: if (Cancelled != null) Cancelled(this, new PlayerIndexEventArgs(PlayerIndex.One)); ExitScreen(); break; default: ExitScreen(); Buttons[state].RaiseEvent(); break; } }
public override bool HandleMouseInput(InputState input) { var paintedArea = mRectangle; paintedArea.Y -= (int)Padding.Y; paintedArea.X -= (int)Padding.X; paintedArea.Height += 2*(int)Padding.Y; paintedArea.Width += 2 * (int)Padding.X; if (paintedArea.Contains(input.CurrentMouseState.X, input.CurrentMouseState.Y) && State != UIState.Inactive) { if (!input.IsNewMouseState()) return false; else if (input.IsNewLeftMouseClick() || input.IsNewRightMouseClick()) { OnPressedElement(PlayerIndex.One, 0); } return true; } return false; }