/// <summary> /// Activates the loading screen. /// </summary> public static void Load(ScreenManager screenManager, bool loadingIsSlow, params GameScreen[] screensToLoad) { // 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(screenManager, loadingIsSlow, screensToLoad); screenManager.AddScreen(loadingScreen); }
/// <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) { SpriteBatch spriteBatch = ScreenManager.SpriteBatch; SpriteFont font = ScreenManager.Font; string message = Resources.Loading; // Center the text in the viewport. Viewport viewport = ScreenManager.GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 textSize = font.MeasureString(message); Vector2 textPosition = (viewportSize - textSize) / 2; Color color = new Color(255, 255, 255, TransitionAlpha); // Animate the number of dots after our "Loading..." message. loadAnimationTimer += gameTime.ElapsedGameTime; int dotCount = (int)(loadAnimationTimer.TotalSeconds * 5) % 10; message += new string('.', dotCount); // Draw the text. spriteBatch.Begin(); spriteBatch.DrawString(font, message, textPosition, color); spriteBatch.End(); } }
/// <summary> /// Activates the loading screen. /// </summary> public static void Load(ScreenManager screenManager, bool loadingIsSlow, params GameScreen[] screensToLoad) { // 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(screenManager, loadingIsSlow, screensToLoad); screenManager.AddScreen(loadingScreen); }
void LeaveSessionFromGame(AudioManager audioManager)//Audio audioHelper) { // Remove the NetworkSessionComponent. Game.Components.Remove(this); // Remove the NetworkSession service. Game.Services.RemoveService(typeof(NetworkSession)); // Dispose the NetworkSession. networkSession.Dispose(); networkSession = null; // If we have a sessionEndMessage string explaining why the session has // ended (maybe this was a network disconnect, or perhaps the host kicked // us out?) create a message box to display this reason to the user. MessageBoxScreen messageBox; if (!string.IsNullOrEmpty(sessionEndMessage)) { messageBox = new MessageBoxScreen(sessionEndMessage, false); } else { messageBox = null; } // At this point we normally want to return the user all the way to the // main menu screen. But what if they just joined a session? In that case // they went through this flow of screens: // // - MainMenuScreen // - CreateOrFindSessionsScreen // - JoinSessionScreen (if joining, skipped if creating a new session) // - LobbyScreeen // // If we have these previous screens on the history stack, and the user // backs out of the LobbyScreen, the right thing is just to pop off the // LobbyScreen and JoinSessionScreen, returning them to the // CreateOrFindSessionsScreen (we cannot just back up to the // JoinSessionScreen, because it contains search results that will no // longer be valid). But if the user is in gameplay, or has been in // gameplay and then returned to the lobby, the screen stack will have // been emptied. // // To do the right thing in both cases, we scan through the screen history // stack looking for a CreateOrFindSessionScreen. If we find one, we pop // any subsequent screens so as to return back to it, while if we don't // find it, we just reset everything and go back to the main menu. GameScreen[] screens = screenManager.GetScreens(); // Look for the CreateOrFindSessionsScreen. for (int i = 0; i < screens.Length; i++) { if (screens[i] is CreateOrFindSessionScreen) { // If we found one, pop everything since then to return back to it. for (int j = i + 1; j < screens.Length; j++) { screens[j].ExitScreen(); } // Display the why-did-the-session-end message box. if (messageBox != null) { screenManager.AddScreen(messageBox); } return; } } // If we didn't find a CreateOrFindSessionsScreen, reset everything and // go back to the main menu. The why-did-the-session-end message box // will be displayed after the loading screen has completed. LoadingScreen.Load(screenManager, false, new BackgroundScreen(NetworkSessionComponent.Level.shipMap), new MainMenuScreen(), messageBox); }