Ejemplo n.º 1
0
        /// <summary>
        /// Allows each screen to run logic.
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            // Make a copy of the master screen list, to avoid confusion if
            // the process of updating one screen adds or removes others.
            _screensToUpdate.Clear();
            lock (_screens)
                for (Int32 i = 0; i < _screens.Count; i++)
                {
                    _screensToUpdate.Add(_screens[i]);
                }

            // Exit Game if there is nothing more to show or update
            if (_screensToUpdate.Count == 0)
            {
                if (NoMoreScreens != null)
                {
                    NoMoreScreens.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    Game.Exit();
                }
            }

            // Get Game State and Screen State
            Boolean i_otherScreenHasFocus  = !Game.IsActive;
            Boolean i_coveredByOtherScreen = false;

            // Loop as long as there are _screens waiting to be updated.
            while (_screensToUpdate.Count > 0)
            {
                // Pop the topmost screen off the waiting list.
                GameScreen i_screen = _screensToUpdate[_screensToUpdate.Count - 1];
                _screensToUpdate.RemoveAt(_screensToUpdate.Count - 1);

                // Update the screen.
                if (i_screen.IsEnabled)
                {
                    i_screen.Update(gameTime, i_otherScreenHasFocus, i_coveredByOtherScreen);

                    if (i_screen.ScreenState == ScreenState.TransitionOn ||
                        i_screen.ScreenState == ScreenState.Active)
                    {
                        // If this is the first active screen we came across,
                        // give it a chance to handle _input.
                        if (i_screen.IsCapturingInput)
                        {
                            i_screen.HandleInput(gameTime);
                            i_otherScreenHasFocus = true;
                        }
                        // If this is some active popup, handle _input
                        else if (i_screen.IsPopup)
                        {
                            i_screen.HandleInput(gameTime);
                        }

                        // If this is an active non-popup, inform any subsequent
                        // _screens that they are covered by it.
                        if (!i_screen.IsPopup)
                        {
                            i_coveredByOtherScreen = true;
                        }
                    }
                }
            }

            // Print debug trace?
            if (TraceEnabled)
            {
                TraceScreens();
            }
        }