Пример #1
0
 /// <summary>
 /// Constructs a new menu entry with the specified text.
 /// </summary>
 public MenuButton(Texture2D sprite, bool flip, Vector2 position, GameScreen screen)
 {
     _screen = screen;
     _scale = 1f;
     _sprite = sprite;
     _baseOrigin = new Vector2(_sprite.Width / 2f, _sprite.Height / 2f);
     _hover = false;
     _flip = flip;
     Position = position;
 }
Пример #2
0
 /// <summary>
 /// Constructs a new menu entry with the specified text.
 /// </summary>
 /// 
 public MenuEntry(GameScreen menu, string text, EntryType type, GameScreen screen, Texture2D texture)
 {
     _text = text;
     _screen = screen;
     _type = type;
     _menu = menu;
     #if NETFX_CORE
     BaseScale = 1f;
     #else
     BaseScale = 1f;
     #endif
     _scale = 1f;
     //_width = 100;
     //_height = 40;
     _alpha = 1.0f;
     _menuItemBackground = texture;
 }
Пример #3
0
 public MenuEntry(GameScreen menu, string text, EntryType type, GameScreen screen, Texture2D texture, GameScreen phyisicsscreen)
     : this(menu, text, type, screen, texture)
 {
     _phyisicsGameScreen = phyisicsscreen;
 }
Пример #4
0
        public void AddLevelMenuItem(string name, EntryType type, GameScreen screen, GameScreen physicsscreen)
        {
            MenuEntry entry = new MenuEntry(this, name, type, screen, _menuItemBackground, physicsscreen);

            _menuEntries.Add(entry);
        }
Пример #5
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();
                        GameScreen   game = scrs[scrs.Length - 2] as GameScreen;
                        //game.Reset();
                        this.ExitScreen();
                    }

                    //////////////////////////////////
                    //Go to Next Level
                    //////////////////////////////////
                    if (_menuEntries[_selectedEntry].IsNextLevel())
                    {
                        GameScreen[] scrs = ScreenManager.GetScreens();
                        GameScreen   game = scrs[scrs.Length - 2] as GameScreen;
                        //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())
                {
                    GameScreen screen = _menuEntries[_selectedEntry].Screen as GameScreen;
                    //////////////////////////////////////
                    //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())
                {
                    GameScreen mscreen = _menuEntries[_selectedEntry].Screen as GameScreen;
                    //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);
            }
        }
Пример #6
0
        /// <summary>
        /// Removes a screen from the screen manager. You should normally
        /// use GameScreen.ExitScreen instead of calling this directly, so
        /// the screen can gradually transition off rather than just being
        /// instantly removed.
        /// </summary>
        public void RemoveScreen(GameScreen screen)
        {
            // If we have a graphics device, tell the screen to unload content.
            if (_isInitialized)
            {
                screen.UnloadContent();
            }

            _screens.Remove(screen);
            _screensToUpdate.Remove(screen);

            // if there is a screen still in the manager, update TouchPanel
            // to respond to gestures that screen is interested in.
            if (_screens.Count > 0)
            {
                TouchPanel.EnabledGestures = _screens[_screens.Count - 1].EnabledGestures;
            }
        }
Пример #7
0
        /// <summary>
        /// Adds a new screen to the screen manager.
        /// </summary>
        public void AddScreen(GameScreen screen)
        {
            screen.ScreenManager = this;
            screen.IsExiting = false;

            // If we have a graphics device, tell the screen to load content.
            if (_isInitialized)
            {
                screen.LoadContent();
            }

            _screens.Add(screen);

            // update the TouchPanel to respond to gestures this screen is interested in
            TouchPanel.EnabledGestures = screen.EnabledGestures;
        }
Пример #8
0
 public ControlClient(Game game,  GameScreen gamescreen)
     : base(game)
 {
     gameScreen = gamescreen;
 }
Пример #9
0
 public void AddMenuItem(string name, EntryType type, GameScreen screen)
 {
     MenuEntry entry = new MenuEntry(this, name, type, screen, _menuItemBackground);
     _menuEntries.Add(entry);
 }