Example #1
0
        public IGameScreen Switch(IGameScreen screen, GameScreenModality modality)
        {
            int screenCount = this.gameScreens.Count;

            if (screenCount == 0)
            {
                Push(screen, modality);
                return null;
            }

            int lastScreenIndex = screenCount - 1;
            KeyValuePair<IGameScreen, GameScreenModality> old = this.gameScreens[lastScreenIndex];
            IGameScreen previousScreen = old.Key;

            // Notify the previous screen that it's being left and kill it if desired
            previousScreen.Leave();
            DisposeIfSupportedAndDesired(previousScreen);

            // If the switched-to screen is exclusive, we need to clear the update
            // and draw lists. If not, depending on whether the previous screen was
            // a popup screen, we might have to
            if (old.Value == GameScreenModality.Popup)
            {
                RemoveFromUpdateableAndDrawableList(previousScreen);
            }
            else
            {
                this.updateableScreens.Clear();
                this.drawableScreens.Clear();
            }

            // Now swap out the screen and put it in the update and draw lists. If we're
            // switching from an exclusive to a pop-up screen, the draw and update lists need
            // to be rebuilt.
            var newScreen = new KeyValuePair<IGameScreen, GameScreenModality>(screen, modality);
            this.gameScreens[lastScreenIndex] = newScreen;
            if (old.Value == GameScreenModality.Exclusive && modality == GameScreenModality.Popup)
            {
                RebuildUpdateableAndDrawableListRecursively(lastScreenIndex);
            }
            else
            {
                AppendToUpdateableAndDrawableList(screen);
            }

            // Let the screen know that it has been entered
            screen.Enter();

            return previousScreen;
        }
Example #2
0
        public void Push(IGameScreen screen, GameScreenModality modality)
        {
            Pause();

            // If this game screen is modal, take all game screens that came before it
            // from the draw and update lists
            if (modality == GameScreenModality.Exclusive)
            {
                this.drawableScreens.Clear();
                this.updateableScreens.Clear();
            }

            // Add the new screen to the update and draw lists if it implements
            // the required interfaces
            this.gameScreens.Add(new KeyValuePair<IGameScreen, GameScreenModality>(screen, modality));
            AppendToUpdateableAndDrawableList(screen);

            // Screen is set, now try to enter it
            #if DEBUG
            screen.Enter();
            #else
            try
            {
                screen.Enter();
            }
            catch (Exception)
            {
                Pop();
                throw;
            }
            #endif
        }