예제 #1
0
        public static void NavigateBack()
        {
            if (!PlatformServices.BackStackEnabled)
            {
                return;
            }

            StackItem?stackResult = null;

            // screens are added when moving to a new screen, while states are added as you move
            if (mBackStack.Current.HasValue && !string.IsNullOrEmpty(mBackStack.Current.Value.Screen))
            {
                stackResult = mBackStack.Current.Value;
                mBackStack.Back();
            }
            else
            {
                stackResult = mBackStack.Back();
            }

            if (!stackResult.HasValue)
            {
                // if we've gone to the beginning of the back stack, we should exit the game
                FlatRedBallServices.Game.Exit();
                return;
            }

            StackItem stackItem = stackResult.Value;

            if (!string.IsNullOrEmpty(stackItem.Screen))
            {
                mCurrentScreen.NextScreen         = stackItem.Screen;
                mCurrentScreen.IsActivityFinished = true;
                mCurrentScreen.IsMovingBack       = true;
            }
            else if (stackItem.State > -1)
            {
                // states are set as they are moved to, so if this is the last state, we should exit
                if (mBackStack.Count == 0)
                {
                    FlatRedBallServices.Game.Exit();
                    return;
                }

                mCurrentScreen.MoveToState(stackItem.State);
            }
        }