Ejemplo n.º 1
0
        /// <summary>
        /// Begins the asynchronous process of joining a game from an invitation.
        /// </summary>
        void NetworkSession_InviteAccepted(object sender, InviteAcceptedEventArgs e)
        {
            if (Guide.IsTrialMode)
            {
                screenManager.invited = e.Gamer;

                string           message    = "Need to unlock full version before you can accept this invite.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                screenManager.AddScreen(messageBox);

                System.Console.WriteLine("Cannot accept invite yet because we're in trial mode");

                return;
            }

            // We will join the game from a method in this screen.
            MainMenuScreen mainMenu = null;

            // Keep the background screen and main menu screen but remove all others
            // to prepare for joining the game we were invited to.
            foreach (GameScreen screen in screenManager.GetScreens())
            {
                if (screen is BackgroundScreen)
                {
                    continue;
                }
                else if (screen is MainMenuScreen)
                {
                    mainMenu = screen as MainMenuScreen;
                }
                else
                {
                    // If there's an active network session, we'll need to end it
                    // before attempting to join a new one.
                    MethodInfo method = screen.GetType().GetMethod("EndSession");
                    if (method != null)
                    {
                        method.Invoke(screen, null);
                    }

                    // Now exit and remove this screen.
                    screen.ExitScreen();
                    screenManager.RemoveScreen(screen);
                }
            }

            // Now attempt to join the game to which we were invited!
            if (mainMenu != null)
            {
                mainMenu.JoinInvitedGame();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Activates the loading screen.
        /// </summary>
        public static void Load(ScreenManager screenManager,
                                EventHandler<EventArgs> loadNextScreen,
                                bool loadingIsSlow)
        {
            // Tell all the current screens to transition off.
            foreach (GameScreen screen in screenManager.GetScreens())
                screen.ExitScreen();

            // Create and activate the loading screen.
            LoadingScreen loadingScreen = new LoadingScreen();

            loadingScreen.loadingIsSlow = loadingIsSlow;
            loadingScreen.loadNextScreen = loadNextScreen;

            screenManager.AddScreen(loadingScreen);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Activates the loading screen.
        /// </summary>
        public static void Load(ScreenManager screenManager,
                                EventHandler <EventArgs> loadNextScreen,
                                bool loadingIsSlow)
        {
            // Tell all the current screens to transition off.
            foreach (GameScreen screen in screenManager.GetScreens())
            {
                screen.ExitScreen();
            }

            // Create and activate the loading screen.
            LoadingScreen loadingScreen = new LoadingScreen();

            loadingScreen.loadingIsSlow  = loadingIsSlow;
            loadingScreen.loadNextScreen = loadNextScreen;

            screenManager.AddScreen(loadingScreen);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws the loading screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            // If we are the only active screen, that means all the previous screens
            // must have finished transitioning off. We check for this in the Draw
            // method, rather than in Update, because it isn't enough just for the
            // screens to be gone: in order for the transition to look good we must
            // have actually drawn a frame without them before we perform the load.
            if ((ScreenState == ScreenState.Active) &&
                (ScreenManager.GetScreens().Length == 1))
            {
                otherScreensAreGone = true;
            }

            // The gameplay screen takes a while to load, so we display a loading
            // message while that is going on, but the menus load very quickly, and
            // it would look silly if we flashed this up for just a fraction of a
            // second while returning from the game to the menus. This parameter
            // tells us how long the loading is going to take, so we know whether
            // to bother drawing the message.
            if (loadingIsSlow)
            {
                const string message = "Loading...";

                // Center the text in the viewport.
                Viewport viewport     = ScreenManager.GraphicsDevice.Viewport;
                Vector2  viewportSize = new Vector2(viewport.Width, viewport.Height);
                Vector2  textSize     = ScreenManager.Font.MeasureString(message);
                Vector2  textPosition = (viewportSize - textSize) / 2;

                Color color = new Color(255, 255, 255, TransitionAlpha);

                // Draw the text.
                ScreenManager.SpriteBatch.Begin();

                ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, message,
                                                     textPosition, color);

                ScreenManager.SpriteBatch.End();
            }
        }