Example #1
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);
            }
        }
Example #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)
                {
                    //////////////////////////////////
                    //Navigate back to our old screen
                    //////////////////////////////////
                    if (_menuEntries[_selectedEntry].IsNoAction())
                    {
                        this.ExitScreen();
                    }
                    //////////////////////////////////
                    //Resume the game ie Pause Menu
                    //////////////////////////////////
                    if (_menuEntries[_selectedEntry].IsResumeGame())
                    {
                        //////////////////
                        //Resume the music
                        //////////////////
                        MusicHelper.ResumeSong();
                        this.ExitScreen();
                    }
                    //////////////////////////////////
                    //Restart Game
                    //////////////////////////////////
                    if (_menuEntries[_selectedEntry].IsRestart())
                    {
                        GameScreen[]      scrs = ScreenManager.GetScreens();
                        PhysicsGameScreen game = scrs[scrs.Length - 2] as PhysicsGameScreen;
                        game.Reset();
                        this.ExitScreen();
                    }

                    //////////////////////////////////
                    //Go to Next Level
                    //////////////////////////////////
                    if (_menuEntries[_selectedEntry].IsNextLevel())
                    {
                        GameScreen[]      scrs = ScreenManager.GetScreens();
                        PhysicsGameScreen game = scrs[scrs.Length - 2] as PhysicsGameScreen;
                        game.NextLevel();
                        this.ExitScreen();
                    }
                    //////////////////////////////////
                    //Navigate back to Main Menu
                    //////////////////////////////////
                    else if (_menuEntries[_selectedEntry].IsMainMenu())
                    {
                        GameScreen[] scrs = ScreenManager.GetScreens();
                        for (int i = scrs.Length - 1; i > 4; i--)
                        {
                            scrs[i].ExitScreen();
                        }
                    }
                }
                //////////////////////////////
                //Play Default Music and game
                //////////////////////////////
                else if (_menuEntries[_selectedEntry].Screen != null &&
                         _menuEntries[_selectedEntry].IsDefaultMusic())
                {
                    PhysicsGameScreen screen = _menuEntries[_selectedEntry].Screen as PhysicsGameScreen;
                    //////////////////////////////////////
                    //Check whether it is game or Freeplay
                    //////////////////////////////////////
                    if (_menuType == MenuType.FreePlayLevel)
                    {
                        //////////////////////////
                        //Force the FreePLay Level
                        //Index plus on becuase
                        //there is no option for
                        //tutorial
                        //////////////////////////
                        screen.GoToLevel(_selectedEntry + 1, 0);
                    }
                    else
                    {
                        screen.GoToLevel(_selectedEntry, 1);
                    }

                    MusicHelper.SetMusicType(MusicType.Default);
                    ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);
                }
                //////////////////////////////
                //Play Custom Music and game
                //////////////////////////////
                else if (_menuEntries[_selectedEntry].Screen != null &&
                         _menuEntries[_selectedEntry].IsCustomMusic())
                {
                    //MusicHelper.LoadSongFromLibrary();
                    ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);
                }
                ///////////////////////////////////////
                //Leave the playing Music and play game
                ///////////////////////////////////////
                else if (_menuEntries[_selectedEntry].Screen != null &&
                         _menuEntries[_selectedEntry].IsBackgroundMuiscMuisc())
                {
                    PhysicsGameScreen mscreen = _menuEntries[_selectedEntry].Screen as PhysicsGameScreen;
                    mscreen.GoToLevel(_selectedEntry, 1);
                    MusicHelper.SetMusicType(MusicType.Background);
                    ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);
                }
                ////////////////////////
                //MainMenu GameMode Game
                ////////////////////////
                else if (_menuEntries[_selectedEntry].Screen != null &&
                         _menuEntries[_selectedEntry].IsGameModeGame())
                {
                    ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);
                }
                ////////////////////////////
                //MainMenu GameMode FreePlay
                ////////////////////////////
                else if (_menuEntries[_selectedEntry].Screen != null &&
                         _menuEntries[_selectedEntry].IsGameModeFreePlay())
                {
                    ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);
                }
                //////////////////////////////
                //Normal Add Screen
                //////////////////////////////
                else if (_menuEntries[_selectedEntry].Screen != null)
                {
                    ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);
                }
                ///////////////////////
                //Use for tutorial
                ///////////////////////
                if (_menuEntries[_selectedEntry].Screen is IDemoScreen)
                {
                    ScreenManager.AddScreen(
                        new MessageBoxScreen((_menuEntries[_selectedEntry].Screen as IDemoScreen).GetDetails()));
                }
            }
            else if (input.IsMenuCancel())
            {
                //////////////////////////
                //Main Menu
                //////////////////////////
                if (_menuType == MenuType.MainMenu)
                {
                    ScreenManager.Game.Exit();
                }
                else if (_menuType != MenuType.MainMenu)
                {
                    if (_menuType == MenuType.Pause)
                    {
                        MusicHelper.ResumeSong();
                    }
                    this.ExitScreen();
                }
            }

            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);
            }
        }