/// <summary>
 /// Responds to user input, accepting or cancelling the message box.
 /// </summary>
 public override void HandleInput(InputHelper input, GameTime gameTime)
 {
     if (input.IsMenuSelect() || input.IsMenuCancel() || input.IsNewKeyPress(Keys.F1) || input.IsNewButtonPress(Buttons.Start))
     {
         ExitScreen();
     }
 }
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            if (input.IsNewButtonPress(Buttons.A) || input.IsNewMouseButtonPress(MouseButtons.RightButton) || input.IsNewKeyPress(Keys.Space))
                _walker.Reverse();

            base.HandleInput(input, gameTime);
        }
Exemple #3
0
 public override void HandleInput(InputHelper input, GameTime gameTime)
 {
     if (input.IsMenuSelect() || input.IsMenuCancel())
     {
         _duration = TimeSpan.Zero;
     }
 }
 /// <summary>
 /// Responds to user input, accepting or cancelling the message box.
 /// </summary>
 public override void HandleInput(InputHelper input, GameTime gameTime)
 {
     if (input.IsMenuSelect() || input.IsMenuCancel() ||
         input.IsNewMouseButtonPress(MouseButtons.LeftButton))
     {
         ExitScreen();
     }
 }
Exemple #5
0
 public override void HandleInput(InputHelper input, GameTime gameTime)
 {
     if (input.KeyboardState.GetPressedKeys().Length > 0 ||
         input.GamePadState.IsButtonDown(Buttons.A | Buttons.Start | Buttons.Back) ||
         input.MouseState.LeftButton == ButtonState.Pressed)
     {
         _duration = TimeSpan.Zero;
     }
 }
        protected override void Initialize()
        {
            _input = new InputHelper();
#if WINDOWS
            _counter = new FrameRateCounter();
            _showFPS = false;
#endif
            _isExiting = false;

            base.Initialize();
        }
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            // Control debug view
            if (input.IsNewButtonPress(Buttons.Start))
            {
                EnableOrDisableFlag(DebugViewFlags.Shape);
                EnableOrDisableFlag(DebugViewFlags.DebugPanel);
                EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
                EnableOrDisableFlag(DebugViewFlags.Joint);
                EnableOrDisableFlag(DebugViewFlags.ContactPoints);
                EnableOrDisableFlag(DebugViewFlags.ContactNormals);
                EnableOrDisableFlag(DebugViewFlags.Controllers);
            }

            if (input.IsNewKeyPress(Keys.F1))
                EnableOrDisableFlag(DebugViewFlags.Shape);
            if (input.IsNewKeyPress(Keys.F2))
            {
                EnableOrDisableFlag(DebugViewFlags.DebugPanel);
                EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
            }
            if (input.IsNewKeyPress(Keys.F3))
                EnableOrDisableFlag(DebugViewFlags.Joint);
            if (input.IsNewKeyPress(Keys.F4))
            {
                EnableOrDisableFlag(DebugViewFlags.ContactPoints);
                EnableOrDisableFlag(DebugViewFlags.ContactNormals);
            }
            if (input.IsNewKeyPress(Keys.F5))
                EnableOrDisableFlag(DebugViewFlags.PolygonPoints);
            if (input.IsNewKeyPress(Keys.F6))
                EnableOrDisableFlag(DebugViewFlags.Controllers);
            if (input.IsNewKeyPress(Keys.F7))
                EnableOrDisableFlag(DebugViewFlags.CenterOfMass);
            if (input.IsNewKeyPress(Keys.F8))
                EnableOrDisableFlag(DebugViewFlags.AABB);

            if (input.IsNewButtonPress(Buttons.Back) || input.IsNewKeyPress(Keys.Escape))
                ExitScreen();

            if (HasCursor)
                HandleCursor(input);

            if (_userAgent != null)
                HandleUserAgent(input);

            if (EnableCameraControl)
                HandleCamera(input, gameTime);

            base.HandleInput(input, gameTime);
        }
        /// <summary>
        /// Constructs a new screen manager component.
        /// </summary>
        public ScreenManager(Game game)
            : base(game)
        {
            // we must set EnabledGestures before we can query for them, but
            // we don't assume the game wants to read them.
            TouchPanel.EnabledGestures = GestureType.None;
            Content = game.Content;
            Content.RootDirectory = "Content";
            _input = new InputHelper(this);

            _screens = new List<GameScreen>();
            _screensToUpdate = new List<GameScreen>();
            _transitions = new List<RenderTarget2D>();
        }
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            if (input.IsNewMouseButtonPress(MouseButtons.RightButton) ||
                input.IsNewButtonPress(Buttons.B))
            {
                Vector2 cursorPos = Camera.ConvertScreenToWorld(input.Cursor);

                Vector2 min = cursorPos - new Vector2(10, 10);
                Vector2 max = cursorPos + new Vector2(10, 10);

                AABB aabb = new AABB(ref min, ref max);

                World.QueryAABB(fixture =>
                                {
                                    Vector2 fv = fixture.Body.Position - cursorPos;
                                    fv.Normalize();
                                    fv *= 80;
                                    fixture.Body.ApplyLinearImpulse(ref fv);
                                    return true;
                                }, ref aabb);
            }

            base.HandleInput(input, gameTime);
        }
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            if (input.GamePadState.ThumbSticks.Left.X > 0.5f || input.KeyboardState.IsKeyDown(Keys.D))
                _acceleration = Math.Min(_acceleration + (float)(2.0 * gameTime.ElapsedGameTime.TotalSeconds), 1f);
            else if (input.GamePadState.ThumbSticks.Left.X < -0.5f || input.KeyboardState.IsKeyDown(Keys.A))
                _acceleration = Math.Max(_acceleration - (float)(2.0 * gameTime.ElapsedGameTime.TotalSeconds), -1f);
            else if (input.IsNewButtonPress(Buttons.A) || input.IsNewKeyRelease(Keys.S))
                _acceleration = 0f;
            else
                _acceleration -= Math.Sign(_acceleration) * (float)(2.0 * gameTime.ElapsedGameTime.TotalSeconds);

            base.HandleInput(input, gameTime);
        }
Exemple #11
0
 /// <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(InputHelper input, GameTime gameTime)
 {
 }
Exemple #12
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            // Mouse on a menu item
            _hoverEntry = GetMenuEntryAt(input.Cursor);

            // Accept or cancel the menu?
            if (input.IsMenuSelect())
            {
                if (GetPreviewCollision(input.Cursor))
                {
                    if (_menuEntries[_selectedEntry].Screen != null)
                    {
                        Framework.AddScreen(_menuEntries[_selectedEntry].Screen);
                        Framework.AddScreen(new DescriptionBoxScreen((_menuEntries[_selectedEntry].Screen as PhysicsDemoScreen).GetDetails()));
                        ContentWrapper.PlaySoundEffect("Click");
                    }
                }
                if (_hoverEntry != -1)
                {
                    if (_selectedEntry == _hoverEntry)
                    {
                        if (_menuEntries[_selectedEntry].Screen != null)
                        {
                            Framework.AddScreen(_menuEntries[_selectedEntry].Screen);
                            Framework.AddScreen(new DescriptionBoxScreen((_menuEntries[_selectedEntry].Screen as PhysicsDemoScreen).GetDetails()));
                            ContentWrapper.PlaySoundEffect("Click");
                        }
                    }
                    else
                    {
                        _selectedEntry = _hoverEntry;
                    }
                }
            }

            if (GetSliderCollision(input.Cursor))
            {
                _scrollHover = true;
                if (input.IsMenuHold())
                {
                    _scrollLock = true;
                }
            }
            else
            {
                _scrollHover = false;
            }

            if (input.IsMenuRelease())
            {
                _scrollLock = false;
            }

            if (_scrollLock)
            {
                _menuOffset = (int)Math.Round((MathHelper.Clamp(input.Cursor.Y, _menuStart, _menuStart + _menuSpacing * (NumEntries - 1)) - _menuStart) / _scrollSpacing);
                UpdateMenuPositions();
            }

            if (input.IsScreenExit())
            {
                Framework.ExitGame();
            }

            if (input.IsMenuDown())
            {
                _menuOffset++;
                UpdateMenuPositions();
            }

            if (input.IsMenuUp())
            {
                _menuOffset--;
                UpdateMenuPositions();
            }
        }
        private void HandleCursor(InputHelper input)
        {
            Vector2 position = Camera.ConvertScreenToWorld(input.Cursor);

            if ((input.IsNewButtonPress(Buttons.A) ||
                 input.IsNewMouseButtonPress(MouseButtons.LeftButton)) &&
                _fixedMouseJoint == null)
            {
                Fixture savedFixture = World.TestPoint(position);
                if (savedFixture != null)
                {
                    Body body = savedFixture.Body;
                    _fixedMouseJoint = new FixedMouseJoint(body, position);
                    _fixedMouseJoint.MaxForce = 1000.0f * body.Mass;
                    World.AddJoint(_fixedMouseJoint);
                    body.Awake = true;
                }
            }

            if ((input.IsNewButtonRelease(Buttons.A) ||
                 input.IsNewMouseButtonRelease(MouseButtons.LeftButton)) &&
                _fixedMouseJoint != null)
            {
                World.RemoveJoint(_fixedMouseJoint);
                _fixedMouseJoint = null;
            }

            if (_fixedMouseJoint != null)
            {
                _fixedMouseJoint.WorldAnchorB = position;
            }
        }
        private void HandleUserAgent(InputHelper input)
        {
            Vector2 force = _agentForce * new Vector2(input.GamePadState.ThumbSticks.Right.X,
                                                      -input.GamePadState.ThumbSticks.Right.Y);
            float torque = _agentTorque * (input.GamePadState.Triggers.Right - input.GamePadState.Triggers.Left);

            _userAgent.ApplyForce(force);
            _userAgent.ApplyTorque(torque);

            float forceAmount = _agentForce * 0.6f;

            force = Vector2.Zero;
            torque = 0;

            if (input.KeyboardState.IsKeyDown(Keys.A))
            {
                force += new Vector2(-forceAmount, 0);
            }
            if (input.KeyboardState.IsKeyDown(Keys.S))
            {
                force += new Vector2(0, forceAmount);
            }
            if (input.KeyboardState.IsKeyDown(Keys.D))
            {
                force += new Vector2(forceAmount, 0);
            }
            if (input.KeyboardState.IsKeyDown(Keys.W))
            {
                force += new Vector2(0, -forceAmount);
            }
            if (input.KeyboardState.IsKeyDown(Keys.Q))
            {
                torque -= _agentTorque;
            }
            if (input.KeyboardState.IsKeyDown(Keys.E))
            {
                torque += _agentTorque;
            }

            _userAgent.ApplyForce(force);
            _userAgent.ApplyTorque(torque);
        }
Exemple #15
0
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            if (input.VirtualState.ThumbSticks.Left.X > 0.5f)
                _acceleration = Math.Min(_acceleration + (float)(2.0 * gameTime.ElapsedGameTime.TotalSeconds), 1f);
            else if (input.VirtualState.ThumbSticks.Left.X < -0.5f)
                _acceleration = Math.Max(_acceleration - (float)(2.0 * gameTime.ElapsedGameTime.TotalSeconds), -1f);
            else if (input.VirtualState.Buttons.A == ButtonState.Pressed)
                _acceleration = 0f;
            else
                _acceleration -= Math.Sign(_acceleration) * (float)(2.0 * gameTime.ElapsedGameTime.TotalSeconds);

            base.HandleInput(input, gameTime);
        }
        private void HandleCamera(InputHelper input, GameTime gameTime)
        {
            Vector2 camMove = Vector2.Zero;

            if (input.KeyboardState.IsKeyDown(Keys.Up))
            {
                camMove.Y -= 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.KeyboardState.IsKeyDown(Keys.Down))
            {
                camMove.Y += 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.KeyboardState.IsKeyDown(Keys.Left))
            {
                camMove.X -= 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.KeyboardState.IsKeyDown(Keys.Right))
            {
                camMove.X += 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.KeyboardState.IsKeyDown(Keys.PageUp))
            {
                Camera.Zoom += 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;
            }
            if (input.KeyboardState.IsKeyDown(Keys.PageDown))
            {
                Camera.Zoom -= 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;
            }
            if (camMove != Vector2.Zero)
            {
                Camera.MoveCamera(camMove);
            }
            if (input.IsNewKeyPress(Keys.Home))
            {
                Camera.ResetCamera();
            }
        }
Exemple #17
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            // Mouse on a menu item
            _hoverEntry = GetMenuEntryAt(input.Cursor);

            // Accept or cancel the menu? 
            if (input.IsMenuSelect())
            {
                if (GetPreviewCollision(input.Cursor))
                {
                    if (_menuEntries[_selectedEntry].Screen != null)
                    {
                        Framework.AddScreen(_menuEntries[_selectedEntry].Screen);
                        Framework.AddScreen(new DescriptionBoxScreen((_menuEntries[_selectedEntry].Screen as PhysicsDemoScreen).GetDetails()));
                        ContentWrapper.PlaySoundEffect("Click");
                    }
                }
                if (_hoverEntry != -1)
                {
                    if (_selectedEntry == _hoverEntry)
                    {
                        if (_menuEntries[_selectedEntry].Screen != null)
                        {
                            Framework.AddScreen(_menuEntries[_selectedEntry].Screen);
                            Framework.AddScreen(new DescriptionBoxScreen((_menuEntries[_selectedEntry].Screen as PhysicsDemoScreen).GetDetails()));
                            ContentWrapper.PlaySoundEffect("Click");
                        }
                    }
                    else
                    {
                        _selectedEntry = _hoverEntry;
                    }
                }
            }

            if (GetSliderCollision(input.Cursor))
            {
                _scrollHover = true;
                if (input.IsMenuHold())
                {
                    _scrollLock = true;
                }
            }
            else
            {
                _scrollHover = false;
            }

            if (input.IsMenuRelease())
            {
                _scrollLock = false;
            }

            if (_scrollLock)
            {
                _menuOffset = (int)Math.Round((MathHelper.Clamp(input.Cursor.Y, _menuStart, _menuStart + _menuSpacing * (NumEntries - 1)) - _menuStart) / _scrollSpacing);
                UpdateMenuPositions();
            }

            if (input.IsScreenExit())
            {
                Framework.ExitGame();
            }

            if (input.IsMenuDown())
            {
                _menuOffset++;
                UpdateMenuPositions();
            }

            if (input.IsMenuUp())
            {
                _menuOffset--;
                UpdateMenuPositions();
            }
        }
Exemple #18
0
 /// <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(InputHelper input, GameTime gameTime)
 {
 }
        private void HandleCamera(InputHelper input, GameTime gameTime)
        {
            Vector2 camMove = Vector2.Zero;
            if (input.GamePadState.IsButtonDown(Buttons.RightShoulder))
            {
                camMove = input.GamePadState.ThumbSticks.Right * new Vector2(10f, -10f) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (input.GamePadState.IsButtonDown(Buttons.RightTrigger))
                    Camera.Zoom += 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;

                if (input.GamePadState.IsButtonDown(Buttons.LeftTrigger))
                    Camera.Zoom -= 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;

                if (input.IsNewButtonPress(Buttons.X))
                    Camera.ResetCamera();
            }
            else
            {
                if (input.KeyboardState.IsKeyDown(Keys.Up))
                    camMove.Y -= 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (input.KeyboardState.IsKeyDown(Keys.Down))
                    camMove.Y += 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (input.KeyboardState.IsKeyDown(Keys.Left))
                    camMove.X -= 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (input.KeyboardState.IsKeyDown(Keys.Right))
                    camMove.X += 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (input.KeyboardState.IsKeyDown(Keys.PageUp))
                    Camera.Zoom += 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;
                if (input.KeyboardState.IsKeyDown(Keys.PageDown))
                    Camera.Zoom -= 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;
                if (input.IsNewKeyPress(Keys.Home))
                    Camera.ResetCamera();
            }

            if (camMove != Vector2.Zero)
                Camera.MoveCamera(camMove);
        }
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            // Mouse on a menu item
            _hoverEntry = GetOptionEntryAt(input.Cursor);

            // Accept or cancel the menu?
            if (input.IsMenuSelect())
            {
                if (_hoverEntry != -1)
                {
                    _optionEntries[_hoverEntry].Switch();

                    switch (_hoverEntry)
                    {
                        case 0:
                            PhysicsDemoScreen.RenderDebug = _optionEntries[_hoverEntry].IsChecked;
                            break;
                        case 1:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.DebugPanel : PhysicsDemoScreen.Flags & ~DebugViewFlags.DebugPanel;
                            break;
                        case 2:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.PerformanceGraph : PhysicsDemoScreen.Flags & ~DebugViewFlags.PerformanceGraph;
                            break;
                        case 3:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.Shape : PhysicsDemoScreen.Flags & ~DebugViewFlags.Shape;
                            break;
                        case 4:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.PolygonPoints : PhysicsDemoScreen.Flags & ~DebugViewFlags.PolygonPoints;
                            break;
                        case 5:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.Joint : PhysicsDemoScreen.Flags & ~DebugViewFlags.Joint;
                            break;
                        case 6:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.AABB : PhysicsDemoScreen.Flags & ~DebugViewFlags.AABB;
                            break;
                        case 7:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.CenterOfMass : PhysicsDemoScreen.Flags & ~DebugViewFlags.CenterOfMass;
                            break;
                        case 8:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.ContactPoints : PhysicsDemoScreen.Flags & ~DebugViewFlags.ContactPoints;
                            break;
                        case 9:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.ContactNormals : PhysicsDemoScreen.Flags & ~DebugViewFlags.ContactNormals;
                            break;
                        case 10:
                            PhysicsDemoScreen.Flags = _optionEntries[_hoverEntry].IsChecked ? PhysicsDemoScreen.Flags | DebugViewFlags.Controllers : PhysicsDemoScreen.Flags & ~DebugViewFlags.Controllers;
                            break;
                        case 11:
                            ContentWrapper.SoundVolume = _optionEntries[_hoverEntry].IsChecked ? 100 : 0;
                            break;
                    }
                    ContentWrapper.PlaySoundEffect("Click");
                }
            }

            if (input.IsScreenExit())
                ExitScreen();
        }
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            if (input.IsNewButtonPress(Buttons.Start) || input.IsNewKeyPress(Keys.F1))
                Framework.AddScreen(new DescriptionBoxScreen(GetDetails()));

            if (input.IsScreenExit())
                ExitScreen();

            if (HasCursor)
                HandleCursor(input);

            if (_userAgent != null)
                HandleUserAgent(input);

            if (EnableCameraControl)
                HandleCamera(input, gameTime);

            base.HandleInput(input, gameTime);
        }
Exemple #22
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            // Mouse or touch on a menu item
            int hoverIndex = GetMenuEntryAt(input.Cursor);
            if (hoverIndex > -1 && _menuEntries[hoverIndex].IsSelectable() && !_scrollLock)
            {
                _selectedEntry = hoverIndex;
            }
            else
            {
                _selectedEntry = -1;
            }

            _scrollSlider.Hover = false;
            if (input.IsCursorValid)
            {
                _scrollUp.Collide(input.Cursor);
                _scrollDown.Collide(input.Cursor);
                _scrollSlider.Collide(input.Cursor);
            }
            else
            {
                _scrollUp.Hover = false;
                _scrollDown.Hover = false;
                _scrollLock = false;
            }

            // Accept or cancel the menu?
            if (input.IsMenuSelect() && _selectedEntry != -1)
            {
                if (_menuEntries[_selectedEntry].IsExitItem())
                {
                    ScreenManager.Game.Exit();
                }
                else if (_menuEntries[_selectedEntry].Screen != null)
                {
                    ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);
                    if (_menuEntries[_selectedEntry].Screen is IDemoScreen)
                    {
                        ScreenManager.AddScreen(
                            new MessageBoxScreen((_menuEntries[_selectedEntry].Screen as IDemoScreen).GetDetails()));
                    }
                }
            }
            else if (input.IsMenuCancel())
            {
                ScreenManager.Game.Exit();
            }

            if (input.IsMenuPressed())
            {
                if (_scrollUp.Hover)
                {
                    _menuOffset = Math.Max(_menuOffset - 200f * (float)gameTime.ElapsedGameTime.TotalSeconds, 0f);
                    _scrollLock = false;
                }
                if (_scrollDown.Hover)
                {
                    _menuOffset = Math.Min(_menuOffset + 200f * (float)gameTime.ElapsedGameTime.TotalSeconds, _maxOffset);
                    _scrollLock = false;
                }
                if (_scrollSlider.Hover)
                {
                    _scrollLock = true;
                }
            }
            if (input.IsMenuReleased())
            {
                _scrollLock = false;
            }
            if (_scrollLock)
            {
                _scrollSlider.Hover = true;
                _menuOffset = Math.Max(Math.Min(((input.Cursor.Y - _menuBorderTop) / (_menuBorderBottom - _menuBorderTop)) * _maxOffset, _maxOffset), 0f);
            }
        }
Exemple #23
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputHelper input, GameTime gameTime)
        {
            // Mouse or touch on a menu item
            int hoverIndex = GetMenuEntryAt(input.Cursor);

            if (hoverIndex > -1 && _menuEntries[hoverIndex].IsSelectable() && !_scrollLock)
            {
                _selectedEntry = hoverIndex;
            }
            else
            {
                _selectedEntry = -1;
            }

            _scrollSlider.Hover = false;
            if (input.IsCursorValid)
            {
                _scrollUp.Collide(input.Cursor);
                _scrollDown.Collide(input.Cursor);
                _scrollSlider.Collide(input.Cursor);
            }
            else
            {
                _scrollUp.Hover   = false;
                _scrollDown.Hover = false;
                _scrollLock       = false;
            }

            // Accept or cancel the menu?
            if (input.IsMenuSelect() && _selectedEntry != -1)
            {
                if (_menuEntries[_selectedEntry].IsExitItem())
                {
                    ScreenManager.Game.Exit();
                }
                else if (_menuEntries[_selectedEntry].Screen != null)
                {
                    ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);

                    if (_menuEntries[_selectedEntry].Screen is IDemoScreen)
                    {
                        ScreenManager.AddScreen(new MessageBoxScreen((_menuEntries[_selectedEntry].Screen as IDemoScreen).GetDetails()));
                    }
                }
            }
            else if (input.IsMenuCancel())
            {
                ScreenManager.Game.Exit();
            }

            if (input.IsMenuPressed())
            {
                if (_scrollUp.Hover)
                {
                    _menuOffset = Math.Max(_menuOffset - 200f * (float)gameTime.ElapsedGameTime.TotalSeconds, 0f);
                    _scrollLock = false;
                }
                if (_scrollDown.Hover)
                {
                    _menuOffset = Math.Min(_menuOffset + 200f * (float)gameTime.ElapsedGameTime.TotalSeconds, _maxOffset);
                    _scrollLock = false;
                }
                if (_scrollSlider.Hover)
                {
                    _scrollLock = true;
                }
            }

            if (input.IsMenuReleased())
            {
                _scrollLock = false;
            }

            if (_scrollLock)
            {
                _scrollSlider.Hover = true;
                _menuOffset         = Math.Max(Math.Min(((input.Cursor.Y - _menuBorderTop) / (_menuBorderBottom - _menuBorderTop)) * _maxOffset, _maxOffset), 0f);
            }
        }