/// <summary> /// Draws game states /// </summary> public void Draw() { // No screen to draw if (Screens.Count == 0) { return; } Stack <GameScreenBase> screensToUpdate = new Stack <GameScreenBase>(); foreach (GameScreenBase scr in Screens) { screensToUpdate.Push(scr); } GameScreenBase screen = screensToUpdate.Pop(); screen.Draw(); return; /* * foreach (GameScreen screen in Screens) * { * if (screen.State == ScreenState.Hidden) * continue; * * screen.Draw(); * } */ }
/// <summary> /// Removes the a screen /// </summary> /// <param name="screen">Screen to remove</param> public void RemoveScreen(GameScreenBase screen) { if (screen == null) { return; } screen.OnLeave(); screen.UnloadContent(); Screens.Remove(screen); if (Screens.Count > 0) { Screens[Screens.Count - 1].OnEnter(); } }
/// <summary> /// Update game states /// </summary> /// <param name="time">Elapsed game time</param> public void Update_OLD(GameTime time) { // Make a copy of the master screen list, to avoid confusion if // the process of updating one screen adds or removes others. List <GameScreenBase> screensToUpdate = new List <GameScreenBase>(); foreach (GameScreenBase screen in Screens) { screensToUpdate.Add(screen); } bool hasFocus = true; bool isCovered = false; // Update each screens while (screensToUpdate.Count > 0) { // Pop the topmost screen off the waiting list. GameScreenBase screen = screensToUpdate[screensToUpdate.Count - 1]; screensToUpdate.RemoveAt(screensToUpdate.Count - 1); // Update screen logic screen.Update(time, hasFocus, isCovered); if (screen.ScreenState == ScreenState.Entering || screen.ScreenState == ScreenState.Active) { // If this is the first active screen we came across, // give it a chance to handle input. if (hasFocus) { screen.HandleInput(); hasFocus = false; } // If this is an active non-popup, inform any subsequent // screens that they are covered by it. if (!screen.IsPopupScreen) { isCovered = true; } } } }
/// <summary> /// Pushes a GameScreen over the current game state /// </summary> /// <param name="screen">Screen handle</param> public void AddScreen(GameScreenBase screen) { if (screen == null) { return; } if (Screens.Count > 0) { GameScreenBase current = Screens[Screens.Count - 1]; current.OnLeave(); } Screens.Add(screen); screen.ScreenManager = this; screen.IsExiting = false; screen.LoadContent(); screen.OnEnter(); }
/// <summary> /// Update game states /// </summary> /// <param name="time">Elapsed game time</param> public void Update(GameTime time) { // No screen to update if (Screens.Count == 0) { return; } // Make a copy of the master screen list, to avoid confusion if // the process of updating one screen adds or removes others. Stack <GameScreenBase> screensToUpdate = new Stack <GameScreenBase>(); foreach (GameScreenBase scr in Screens) { screensToUpdate.Push(scr); } GameScreenBase screen = screensToUpdate.Pop(); screen.Update(time, true, false); }