Пример #1
0
        /// <summary>
        /// Changes to a new Screen.
        /// </summary>
        /// <param name="screen">The new Screen.</param>
        public virtual bool Push(Screen screen)
        {
            if (ChildScreen != null)
            {
                throw new InvalidOperationException("Can not push more than one child screen.");
            }

            screen.ParentScreen = this;
            childModeContainer.Add(screen);

            if (screen.hasExited)
            {
                screen.Expire();
                return(false);
            }

            startSuspend(screen);

            screen.OnEntering(this);

            ModePushed?.Invoke(screen);

            Content.Expire();

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Changes to a new Screen.
        /// This will trigger an async load if the screen is not already loaded, during which the current screen will no longer be current (or accept user input).
        /// </summary>
        /// <param name="screen">The new Screen.</param>
        public virtual void Push(Screen screen)
        {
            if (hasExited)
            {
                throw new TargetAlreadyExitedException();
            }

            if (!IsCurrentScreen)
            {
                throw new ScreenNotCurrentException(nameof(Push));
            }

            if (ChildScreen != null)
            {
                throw new ScreenHasChildException(nameof(Push), "Exit the existing child screen first.");
            }

            if (screen.hasExited)
            {
                throw new ScreenAlreadyExitedException();
            }

            if (screen.hasEntered)
            {
                throw new ScreenAlreadyEnteredException();
            }

            screen.ParentScreen = this;
            startSuspend(screen);
            ModePushed?.Invoke(screen);

            void finishLoad()
            {
                if (hasExited || screen.hasExited)
                {
                    return;
                }

                childModeContainer.Add(screen);

                screen.enter(this);

                Content.Expire();
            }

            if (screen.LoadState >= LoadState.Ready)
            {
                finishLoad();
            }
            else
            {
                LoadComponentAsync(screen, _ => finishLoad());
            }
        }
Пример #3
0
        /// <summary>
        /// Changes to a new GameMode.
        /// </summary>
        /// <param name="mode">The new GameMode.</param>
        public void Push(GameMode mode)
        {
            Debug.Assert(ChildGameMode == null);

            startSuspend(mode);

            AddTopLevel(mode);
            mode.OnEntering(this);

            ModePushed?.Invoke(mode);

            Content.Expire();
        }
Пример #4
0
        /// <summary>
        /// Changes to a new Screen.
        /// </summary>
        /// <param name="screen">The new Screen.</param>
        public virtual bool Push(Screen screen)
        {
            Debug.Assert(ChildScreen == null);

            screen.ParentScreen = this;
            childModeContainer.Add(screen);

            if (screen.hasExited)
            {
                screen.Expire();
                return(false);
            }

            startSuspend(screen);

            screen.OnEntering(this);

            ModePushed?.Invoke(screen);

            Content.Expire();

            return(true);
        }
Пример #5
0
        /// <summary>
        /// Changes to a new GameMode.
        /// </summary>
        /// <param name="mode">The new GameMode.</param>
        public virtual bool Push(GameMode mode)
        {
            Debug.Assert(ChildGameMode == null);

            mode.ParentGameMode = this;
            childModeContainer.Add(mode);

            if (mode.hasExited)
            {
                mode.Expire();
                return(false);
            }

            startSuspend(mode);

            mode.OnEntering(this);

            ModePushed?.Invoke(mode);

            Content.Expire();

            return(true);
        }
Пример #6
0
        /// <summary>
        /// Changes to a new Screen.
        /// This will trigger an async load if the screen is not already loaded, during which the current screen will no longer be current (or accept user input).
        /// </summary>
        /// <param name="screen">The new Screen.</param>
        public virtual void Push(Screen screen)
        {
            if (hasExited)
            {
                throw new InvalidOperationException("Cannot push to an already exited screen.");
            }

            if (!IsCurrentScreen)
            {
                throw new InvalidOperationException("Cannot push a child screen to a non-current screen.");
            }

            if (ChildScreen != null)
            {
                throw new InvalidOperationException("Can not push more than one child screen.");
            }

            if (screen.hasExited)
            {
                throw new InvalidOperationException("Cannot push an already exited screen.");
            }

            if (screen.hasEntered)
            {
                throw new InvalidOperationException("Cannot push an already entered screen.");
            }

            screen.ParentScreen = this;
            startSuspend(screen);
            ModePushed?.Invoke(screen);

            void finishLoad()
            {
                if (hasExited)
                {
                    return;
                }

                childModeContainer.Add(screen);

                if (screen.hasExited)
                {
                    screen.Expire();
                    startResume(screen);
                    return;
                }

                screen.enter(this);

                Content.Expire();
            }

            if (screen.LoadState >= LoadState.Ready)
            {
                finishLoad();
            }
            else
            {
                LoadComponentAsync(screen, _ => finishLoad());
            }
        }