Exemple #1
0
 /// <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 #2
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;
     }
 }
        /// <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;
            _contentManager = game.Content;
            _contentManager.RootDirectory = "Content";
            #if WINDOWS
            TouchTarget touchTarget = new TouchTarget(game.Window.Handle, EventThreadChoice.OnBackgroundThread);
            touchTarget.EnableInput();
             _input = new InputHelper(touchTarget, this);
            #else
            _input = new InputHelper(this);
            #endif

            _screens = new List<GameScreen>();
            _screensToUpdate = new List<GameScreen>();
            _transitions = new List<RenderTarget2D>();
        }
Exemple #4
0
        private void HandleCamera(InputHelper input, GameTime gameTime)
        {
            Vector2 camMove = Vector2.Zero;
            float MoveSpeed = 100f;

            if (input.KeyboardState.IsKeyDown(Keys.Up))
            {
                camMove.Y -= MoveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.KeyboardState.IsKeyDown(Keys.Down))
            {
                camMove.Y += MoveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.KeyboardState.IsKeyDown(Keys.Left))
            {
                camMove.X -= MoveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.KeyboardState.IsKeyDown(Keys.Right))
            {
                camMove.X += MoveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (camMove != Vector2.Zero)
            {
                Camera.MoveCamera(camMove);
            }
            if (input.KeyboardState.IsKeyDown(Keys.OemPlus))
            {
                Camera.Zoom += 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;
            }
            if (input.KeyboardState.IsKeyDown(Keys.OemMinus))
            {
                Camera.Zoom -= 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;
            }
            if (input.IsNewKeyPress(Keys.Escape))
            {
                Camera.ResetCamera();
            }
        }
Exemple #5
0
 public override void HandleInput(InputHelper input, GameTime gameTime)
 {
     HandleCamera(input, gameTime);
 }
Exemple #6
0
        public override void HandleInput(InputHelper input, Microsoft.Xna.Framework.GameTime gameTime)
        {
            supers.Clear();
            #if WINDOWS
            var surfacetouches = input.SurfaceTouches;
            if (surfacetouches.Count > 0)
            {
                //Surface
                for (int i = 0; i < surfacetouches.Count; i++)
                {
                    Vector2 position = Camera.ConvertScreenToWorldAndDisplayUnits(new Vector2(surfacetouches[i].X, surfacetouches[i].Y));

                    supers[i] = new Individual(i,((double)position.X),
                         ((double)position.Y),
                         0.0, 0.0, new Parameters());
                }
            }
            else
            #endif
            if (input.Touches.Count > 0)
            {
                //Everthing else touch
                for (int i = 0; i < input.Touches.Count; i++)
                {
                    Vector2 position = Camera.ConvertScreenToWorldAndDisplayUnits(new Vector2(input.Touches[i].Position.X, input.Touches[i].Position.Y));

                    supers[i] = new Individual(i, ((double)position.X),
                                              ((double)position.Y),
                                              0.0, 0.0, new SuperParameters());
                }
            }
            else if (supers.Count <= 0 &&
                    (input.Cursor != Vector2.Zero) &&
                    input.MouseState.LeftButton == ButtonState.Pressed)
            {
                //Mouse
                supers.Add(0, new Individual());
                for (int i = 0; i < supers.Count; i++)
                {
                    Vector2 position = Camera.ConvertScreenToWorldAndDisplayUnits(input.Cursor);

                    supers[i] = new Individual(i, ((double)position.X),
                         ((double)position.Y),
                         0, 0, new SuperParameters());
                }
            }

            if (input.IsNewKeyPress(Keys.A))
            {
                controlClient.ToggleAnalyze();
            }

            if (input.IsNewKeyPress(Keys.C))
            {
                debugComponent.SetVisiblity();
            }

            ButtonSection.HandleInput(input, gameTime);
            base.HandleInput(input, gameTime);
        }
Exemple #7
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 #8
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);
            }
        }
Exemple #9
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);
            }
        }
Exemple #10
0
 public override void HandleInput(InputHelper input, GameTime gameTime)
 {
     
 }