public override void HandleInput(InputState input) { string text = input.GetTextSinceUpdate(ControllingPlayer); text = text.Replace("\n", ""); PlayerIndex outs; if(text.Length > 0) { int index = text.IndexOf('\b'); text = text.Replace("\b", ""); int displacement = (cursorPosition > 0 && index != -1 ? -1 : 0); Content = Content.Substring(0, cursorPosition + displacement) + text + Content.Substring(cursorPosition); cursorPosition += text.Length + displacement; } else if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Left, null, out outs)) cursorPosition--; else if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Right, null, out outs)) cursorPosition++; else base.HandleInput(input); cursorPosition = (int)MathHelper.Clamp(cursorPosition, 0, Content.Length); }
public override void HandleInput(InputState input) { if (mReadingInput) { string text = input.GetTextSinceUpdate(ControllingPlayer); if (text.Length == 0) return; if (text[text.Length - 1] == '\n') { text = text.Remove(text.Length - 1); mReadingInput = false; } if (text.Length > 0 && text[0] == '\b') { if (mProfiles[mSelectedButton].Name.Length > 0) mProfiles[mSelectedButton].Name = mProfiles[mSelectedButton].Name.Remove(mProfiles[mSelectedButton].Name.Length - 1) + text.Substring(1); else mProfiles[mSelectedButton].Name = text.Substring(1); } else mProfiles[mSelectedButton].Name += text; Buttons[mSelectedButton].Text = mProfiles[mSelectedButton].Name; CreateDimensions(); if (!mReadingInput) { if (mProfiles[mSelectedButton].Name.Length < 1) mProfiles[mSelectedButton].Name = " "; ProfileSelectedButton(Buttons[mSelectedButton], null); if (ProfileSaved != null) ProfileSaved(this, new PlayerIndexEventArgs(ControllingPlayer.HasValue ? ControllingPlayer.Value : PlayerIndex.One)); mProfiles[mSelectedButton].Register(); ExitScreen(); } } else { base.HandleInput(input); PlayerIndex pl; if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Delete, ControllingPlayer, out pl)) { MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen("Are you sure you want to delete Profile:\n " + mProfiles[mSelectedButton].Name); confirmExitMessageBox.Buttons[0].Pressed += ConfirmExitMessageBoxAccepted; ScreenManager.AddScreen(confirmExitMessageBox, pl); } } }
public override void HandleInput(InputState input) { Keybinding tmpKey = input.GetNewestKeybindingPressed(this.ControllingPlayer); if (tmpKey != null && mNewKey == null) { Content = "Key [" + tmpKey.ToString() + "] Pressed"; mNewKey = tmpKey; this.mSelectedButton = 0; Buttons[0].State = UIState.Selected; Buttons[1].State = UIState.Active; } else base.HandleInput(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(InputState input) { if (input == null) throw new ArgumentNullException("input"); mInputState = 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]; if (input.IsPausingGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(mLevel), ControllingPlayer); } }
private void UpdateProjectile(GameTime theGameTime, InputState inputState, Level level) { if (mOrbs[0].Visible) { mOrbs[0].Update(theGameTime); mOrbs[0].CheckCollisions(level); } else if (inputState.IsFiringPortal1(null) && level.Portals.CanClose()) { ShootProjectile(0, inputState.CurrentMouseState, level); mOrbs[0].CheckCollisions(level); level.Portals.Close(0); } if (mOrbs[1].Visible) { mOrbs[1].Update(theGameTime); mOrbs[1].CheckCollisions(level); } else if (inputState.IsFiringPortal2(null) && level.Portals.CanClose()) { ShootProjectile(1, inputState.CurrentMouseState, level); mOrbs[1].CheckCollisions(level); level.Portals.Close(1); } }
private bool UpdateJump(InputState inputState) { if ((mCurrentState == State.Ground || mCurrentState == State.Platform || mCurrentState == State.Portal) && Velocity.Y == 0) { if (inputState.IsJumping(null)) { mCurrentState = State.Air; Velocity.Y = -DEFAULT_SPEED; return true; } } return false; }
private void UpdateMovement(InputState inputState) { if (mCurrentState == State.Ground || mCurrentState == State.Platform || mCurrentState == State.Portal) { if (Math.Abs(Velocity.X) <= STATIC_ACCEL_GND) { Acceleration.X = 0; Velocity.X = 0; } else Acceleration.X = mCurrentFriction * (-Math.Sign(Velocity.X)); if (inputState.IsMovingBackwards(null)) { Velocity.X = DEFAULT_SPEED * MOVE_LEFT * (mIsDucking ? .5f : 1); } else if (inputState.IsMovingForward(null)) { Velocity.X = DEFAULT_SPEED * MOVE_RIGHT * (mIsDucking ? .5f : 1); } } else if(mCurrentState == State.Air || mCurrentState == State.GravityPortal) { if (Math.Abs(Velocity.X) <= STATIC_ACCEL_AIR) { Acceleration.X = 0; Velocity.X = 0; } else { Acceleration.X = DYNAMIC_ACCEL_AIR * (Math.Abs(Velocity.X) <= STATIC_ACCEL_AIR ? 0 : 1) * (-Math.Sign(Velocity.X)); } if (inputState.IsMovingBackwards(null)) { //Acceleration.X += DYNAMIC_ACCEL_AIR * MOVE_LEFT / 4; Velocity.X = Math.Min(Velocity.X, DEFAULT_SPEED / 2f * MOVE_LEFT * (mIsDucking ? .5f : 1)); } else if (inputState.IsMovingForward(null)) { //Acceleration.X += DYNAMIC_ACCEL_AIR * MOVE_RIGHT / 4; Velocity.X = Math.Max(Velocity.X, DEFAULT_SPEED / 2f * MOVE_RIGHT * (mIsDucking ? .5f : 1)); } //if (mIsDucking) // Acceleration.X *= .75f; //} } }
public void Update(GameTime theGameTime, Level level, InputState inputState) { Acceleration = Vector2.Zero; var curstate = mCurrentState; CheckCollisions(level, inputState.IsInteracting(null)); if (curstate == State.Air && (mCurrentState == State.Ground || mCurrentState == State.Platform)) level.PlaySoundEffect(mLandingEffect); UpdateMovement(inputState); if (UpdateJump(inputState)) level.PlaySoundEffect(mJumpEffect); UpdateDuck(inputState); Acceleration.Y = (mCurrentState == State.Air || mCurrentState == State.GravityPortal || mCurrentState == State.Portal ? 1 : 0) * level.Gravity * Level.METERS_TO_UNITS; if (Angle != 0) { if(Angle > 0) Angle = (float)Math.Max(0, Angle - Math.PI * theGameTime.ElapsedGameTime.TotalSeconds / 2); else Angle = (float)Math.Min(0, Angle + Math.PI * theGameTime.ElapsedGameTime.TotalSeconds / 2); } base.Update(theGameTime); mFlip = mGunhand.Update(inputState.CurrentMouseState, mIsDucking, this, level.Position); UpdateProjectile(theGameTime, inputState, level); }
private void UpdateDuck(InputState inputState) { if (inputState.IsDucking(null) || mForcedDucking) { Duck(); } else { StopDucking(); } }
public void Update(GameTime theGameTime, InputState inputState) { if (MediaPlayer.State == MediaState.Stopped) MediaPlayer.Play(mBackgroundMusic); KeyboardState aCurrentKeyboardState = Keyboard.GetState(); MouseState aCurrentMouseState = Mouse.GetState(); LevelStatistics.TimeElapsed += theGameTime.ElapsedGameTime.TotalSeconds; Portals.ClearSprites(); foreach (Obstacle spr in Obstacles) spr.Update(theGameTime); Player.Update(theGameTime, this, inputState); foreach (Actor spr in Actors) { spr.Update(theGameTime, this); } mTextEffects = mTextEffects.Where(x => !x.Done).ToList(); foreach (TextEffect effect in mTextEffects) { effect.Update(theGameTime); } Portals.Update(theGameTime); Position = mCenterVector - Player.Position; Position = new Vector2(MathHelper.Clamp(Position.X, mDimensions.X - Size.Width, 0), MathHelper.Clamp(Position.Y, mDimensions.Y - Size.Height, 0)); mBackground.Position = Position; if(Player.IsGrounded()) while (Checkpoints[mCheckpointIndex].InBounds(Player.Position)) { if (++mCheckpointIndex >= Checkpoints.Count) { GameOver(); } else { mTextEffects.Add(new CheckpointNotification(Player.Position+Position)); PlaySoundEffect(mCheckpointSound); } } }
public override bool HandleMouseInput(InputState input) { for(int i = 0; i < mElements.Length; i++) if (mElements[i].HandleMouseInput(input)) { mSelected = i; State = State; return true; } return base.HandleMouseInput(input); }
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; }
/// <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(InputState input) { }
//UNDER CONSTRUCTION private void UpdateMovement(InputState inputState) { bool invert = Math.Abs(Angle) > MathHelper.PiOver2; //Movement while on the ground is UNDER CONSTRUCTION (values are hardcoded) if (mCurrentState == State.Ground || mCurrentState == State.Platform || mCurrentState == State.Portal) { if (Math.Abs(Velocity.X) <= STATIC_ACCEL_GND) { Acceleration.X = 0; Velocity.X = 0; } else Acceleration.X = mCurrentFriction * (-Math.Sign(Velocity.X)); if ((inputState.IsMovingBackwards(null) && !invert) || (inputState.IsMovingForward(null) && invert)) { Velocity.X = DEFAULT_SPEED * MOVE_LEFT * (mIsDucking ? .5f : 1); if (mIsDucking) { } else { animator.PlayAnimation(runAnimation); } } else if ((inputState.IsMovingBackwards(null) && invert) || (inputState.IsMovingForward(null) && !invert)) { Velocity.X = DEFAULT_SPEED * MOVE_RIGHT * (mIsDucking ? .5f : 1); if (mIsDucking) { } else { animator.PlayAnimation(runAnimation); } } else { animator.PlayAnimation(idleAnimation); } } //Movement while in the AIR is UNDER CONSTRUCTION (values are hardcoded) else if (mCurrentState == State.Air || mCurrentState == State.GravityPortal) { if (Math.Abs(Velocity.X) <= STATIC_ACCEL_AIR) { Acceleration.X = 0; Velocity.X = 0; } else { Acceleration.X = DYNAMIC_ACCEL_AIR * (Math.Abs(Velocity.X) <= STATIC_ACCEL_AIR ? 0 : 1) * (-Math.Sign(Velocity.X)); } if ((inputState.IsMovingBackwards(null) && !invert) || (inputState.IsMovingForward(null) && invert)) { //Acceleration.X += DYNAMIC_ACCEL_AIR * MOVE_LEFT / 4; //Velocity.X = Math.Min(Velocity.X, DEFAULT_SPEED / 2f * MOVE_LEFT * (mIsDucking ? .5f : 1)); if (Velocity.X >= -DEFAULT_SPEED) { if (Velocity.X > 0) { Velocity.X -= 50; } else { Velocity.X -= 25; } } animator.PlayAnimation(jumpAnimation); } else if ((inputState.IsMovingBackwards(null) && invert) || (inputState.IsMovingForward(null) && !invert)) { //Acceleration.X += DYNAMIC_ACCEL_AIR * MOVE_RIGHT / 4; //Velocity.X = Math.Max(Velocity.X, DEFAULT_SPEED / 2f * MOVE_RIGHT * (mIsDucking ? .5f : 1)); if (Velocity.X <= DEFAULT_SPEED) { if (Velocity.X < 0) { Velocity.X += 50; } else { Velocity.X += 25; } } animator.PlayAnimation(jumpAnimation); } //if (mIsDucking) // Acceleration.X *= .75f; //} } }
//UNDER CONSTRUCTION private bool UpdateJump(InputState inputState, GameTime theGameTime) { //start jump if ((mCurrentState == State.Ground || mCurrentState == State.Platform) && Velocity.Y == 0) { if (inputState.IsNewJump(null)) { mCurrentState = State.Air; Velocity.Y = -DEFAULT_JUMP; stillJumping = true; jumpTimer = TimeSpan.Zero; animator.PlayAnimation(jumpAnimation); return true; } } //walljumping if (mCurrentState == State.Air) { if (wallJumpRight) //walljump from left wall to right direction is available to player { if (inputState.IsNewJump(null)) { Velocity.X = DEFAULT_SPEED * MOVE_RIGHT * 2f; //Velocity.Y = -DEFAULT_JUMP / 2; Velocity.Y = -DEFAULT_JUMP; stillJumping = true; stillWallJumpingRight = true; jumpTimer = TimeSpan.Zero; wallJumpTimer = TimeSpan.Zero; animator.ResetAnimation(); return true; } } else if (wallJumpLeft) //walljump from right wall to left direction is available to player { if (inputState.IsNewJump(null)) { Velocity.X = DEFAULT_SPEED * MOVE_LEFT * 2f; //Velocity.Y = -DEFAULT_JUMP / 2; Velocity.Y = -DEFAULT_JUMP; stillJumping = true; stillWallJumpingLeft = true; jumpTimer = TimeSpan.Zero; wallJumpTimer = TimeSpan.Zero; animator.ResetAnimation(); return true; } } if (stillWallJumpingRight) { wallJumpTimer += theGameTime.ElapsedGameTime; if (wallJumpTimer < TimeSpan.FromMilliseconds(JUMP_HEIGHT_MAX / 2)) { Velocity.X = DEFAULT_SPEED * MOVE_RIGHT * 2f; //Velocity.Y = -DEFAULT_JUMP/2; Velocity.Y = -DEFAULT_JUMP; } else { stillWallJumpingRight = false; stillJumping = false; } } else if (stillWallJumpingLeft) { wallJumpTimer += theGameTime.ElapsedGameTime; if (wallJumpTimer < TimeSpan.FromMilliseconds(JUMP_HEIGHT_MAX / 2)) { Velocity.X = DEFAULT_SPEED * MOVE_LEFT * 2f; //Velocity.Y = -DEFAULT_JUMP/2; Velocity.Y = -DEFAULT_JUMP; } else { stillWallJumpingLeft = false; stillJumping = false; } } } else { stillWallJumpingRight = false; stillWallJumpingLeft = false; stillJumping = false; } //variable height jump if (stillJumping && !stillWallJumpingRight && !stillWallJumpingLeft) { if (inputState.IsJumping(null)) { mCurrentState = State.Air; //Velocity.Y = -DEFAULT_JUMP; Velocity.Y = -DEFAULT_JUMP; jumpTimer += theGameTime.ElapsedGameTime; if (jumpTimer > TimeSpan.FromMilliseconds(JUMP_HEIGHT_MAX)) { stillJumping = false; jumpTimer = TimeSpan.Zero; } } else //player let go of jump key early for a shorter jump { stillJumping = false; } } wallJumpLeft = false; wallJumpRight = false; return false; }
/// <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) { for(int i = 0; i < buttons.Length; i++) if (buttons[i].HandleMouseInput(input)) { selected = i; State = State; return true; } return base.HandleMouseInput(input); }
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, 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) { 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); }
public void Update(GameTime theGameTime, ScreenManager manager, InputState inputState) { if (MediaPlayer.State == MediaState.Stopped && mCanPlayerMusic) try { MediaPlayer.Play(mBackgroundMusic); } catch { mCanPlayerMusic = false; } KeyboardState aCurrentKeyboardState = Keyboard.GetState(); MouseState aCurrentMouseState = Mouse.GetState(); LevelStatistics.TimeElapsed += theGameTime.ElapsedGameTime.TotalSeconds; Portals.ClearSprites(); Player.Update(theGameTime, this, inputState); foreach (Obstacle spr in Obstacles) spr.Update(theGameTime); foreach (Actor spr in Actors) { spr.Update(theGameTime, this); } mTextEffects = mTextEffects.Where(x => !x.Done).ToList(); foreach (TextEffect effect in mTextEffects) { effect.Update(theGameTime); } Portals.Update(theGameTime); if(Player.IsGrounded()) while (Checkpoints[mCheckpointIndex].InBounds(Player.Position)) { if (++mCheckpointIndex >= Checkpoints.Count) { GameOver(); } else { mTextEffects.Add(new CheckpointNotification(Player.Position+Position)); if (Checkpoints[mCheckpointIndex - 1].NarrationText != null && Checkpoints[mCheckpointIndex - 1].NarrationText.Length > 0) mTextEffects.Add(new NarrationEffect(Checkpoints[mCheckpointIndex - 1].NarrationText, manager)); PlaySoundEffect(mCheckpointSound); } } }
/// <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--; } // Move to the next menu entry? if (input.IsMenuDown(ControllingPlayer)) { selectedEntry++; } selectedEntry = (int)MathHelper.Clamp(selectedEntry, 0, MenuEntries.Count - 1); if (!menuEntries[selectedEntry].HandleMouseInput(input)) for (int i = 0; i < menuEntries.Count; i++) { if(menuEntries[i].HandleMouseInput(input)) { selectedEntry = i; break; } } if(selectedEntry != before) { menuEntries[before].State = UIState.Active; menuEntries[selectedEntry].State = UIState.Selected; AudioSettings settings = (ScreenManager.Game as HalfCakedGame).CurrentProfile.Audio; if(EntryFocusChanged != null) 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)) { OnSelectEntry(selectedEntry, playerIndex, 0); } else if (menuEntries[selectedEntry].ChangesValue && input.IsNextButton(ControllingPlayer)) { OnSelectEntry(selectedEntry, playerIndex, 1); } else if (menuEntries[selectedEntry].ChangesValue && (input.IsPreviousButton(ControllingPlayer))) { OnSelectEntry(selectedEntry, playerIndex, -1); } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } }
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; }