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; }
public override bool HandleMouseInput(InputState input) { int direction = 0; if(input.IsNewLeftMouseClick() || input.IsNewRightMouseClick()) { var rect1 = new Rectangle((int)leftArrowPosition.X, (int)leftArrowPosition.Y - 10, 20, 20); var rect2 = new Rectangle((int)rightArrowPosition.X, (int)rightArrowPosition.Y - 10, 20, 20); var rect3 = new Rectangle(rect1.Right, rect1.Top, (int)(maxChoiceSize.X + choiceLabel.Padding.X * 2), mRectangle.Height); if (rect1.Contains(input.CurrentMouseState.X, input.CurrentMouseState.Y)) direction = -1; else if (rect2.Contains(input.CurrentMouseState.X, input.CurrentMouseState.Y)) direction = 1; else if (rect3.Contains(input.CurrentMouseState.X, input.CurrentMouseState.Y)) direction = input.IsNewRightMouseClick() ? -1 : 1; if (direction != 0) { OnPressedElement(PlayerIndex.One, direction); return true; } } return base.HandleMouseInput(input); }
/// <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; } }
/// <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 = -1; var prevButton = mSelectedButton; Vector2 mousePos = new Vector2(-1, -1); if(Buttons.Any(x => x.State != UIState.Inactive)) if (input.IsNextButton(ControllingPlayer)) { do mSelectedButton = (mSelectedButton + 1) % Buttons.Count; while (Buttons[mSelectedButton].State == UIState.Inactive); } else if (input.IsPreviousButton(ControllingPlayer)) { do mSelectedButton = (mSelectedButton - 1 + Buttons.Count) % Buttons.Count; while (Buttons[mSelectedButton].State == UIState.Inactive); } for(int i = 0; i < Buttons.Count; i++) if (Buttons[i].HandleMouseInput(input)) { mSelectedButton = i; if (input.IsNewLeftMouseClick()) { state = i; return; } break; } if (prevButton != mSelectedButton) { if(prevButton >= 0) Buttons[prevButton].State = UIState.Active; Buttons[mSelectedButton].State = UIState.Selected; } if (input.IsMenuSelect(ControllingPlayer, out playerIndex) && !input.IsNewLeftMouseClick()) { state = mSelectedButton; } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { state = -2; } switch (state) { case -1: break; case -2: if (Cancelled != null) Cancelled(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); break; default: Buttons[state].OnPressedElement(playerIndex, 0); break; } }
/// <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); } }
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; }
public override bool HandleMouseInput(InputState input) { if (State == UIState.Inactive) return false; int before = value; isDragging &= input.CurrentMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed || input.CurrentMouseState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed; var rect1 = new Rectangle((int)leftArrowPosition.X, (int)leftArrowPosition.Y - 10, 20, 20); var rect2 = new Rectangle((int)rightArrowPosition.X, (int)rightArrowPosition.Y - 10, 20, 20); bool click_in_slider = rect1.Right + 5 < input.CurrentMouseState.X && rect2.Left - 5 > input.CurrentMouseState.X && rect1.Top < input.CurrentMouseState.Y && rect1.Bottom > input.CurrentMouseState.Y; if (input.IsNewLeftMouseClick() || input.IsNewRightMouseClick()) { if (rect1.Contains(input.CurrentMouseState.X, input.CurrentMouseState.Y)) value -= 5; else if (rect2.Contains(input.CurrentMouseState.X, input.CurrentMouseState.Y)) value += 5; else if (click_in_slider ) value = (int)(input.CurrentMouseState.X - (rect1.Right + 5)) / 2; } else if (isDragging) value = (int)(input.CurrentMouseState.X - (rect1.Right + 5)) / 2; else if ((input.IsNewLeftMousePress() || input.IsNewRightMousePress()) && click_in_slider) { value = (int)(input.CurrentMouseState.X - (rect1.Right + 5)) / 2; isDragging = true; } else return base.HandleMouseInput(input); OnPressedElement(PlayerIndex.One, 0); return true; }