Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
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)
                    {
                        var demoScreen = _menuEntries[_selectedEntry].Screen as IDemoScreen;
                        ScreenManager.AddScreen(new MessageBoxScreen(demoScreen.GetTitle(), demoScreen.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.WheelDelta != 0)
            {
                _menuOffset = MathHelper.Clamp(_menuOffset - 32f * (input.WheelDelta / 120f), 0f, _maxOffset);
                _scrollLock = false;
            }


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

            if (_scrollLock)
            {
                _scrollSlider.Hover = true;
                _menuOffset         = Math.Max(Math.Min(((input.Cursor.Y - _menuBorderTop) / (_menuBorderBottom - _menuBorderTop)) * _maxOffset, _maxOffset), 0f);
            }
        }
Ejemplo n.º 3
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)
 {
 }
Ejemplo n.º 4
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();
            }
        }