public void Remove(ManagedGameComponent component) { Components.Remove(component); _ComponentsToUpdate.Remove(component); component.ComponentManager = null; }
/// <summary> /// The constructor is private: loading screens should /// be activated via the static Load method instead. /// </summary> private Loader(ManagedGameComponent screenManager, ManagedGameComponent loadingScreen, ManagedGameComponent[] screensToLoad) { this._LoadingScreen = loadingScreen; this._ScreensToLoad = screensToLoad; TransitionOnTime = TimeSpan.FromSeconds(0.5); }
/// <summary> /// Activates the loading screen. /// </summary> public static void Load(ManagedGameComponent componentManager, ManagedGameComponent loadingScreen, params ManagedGameComponent[] screensToLoad) { // Tell all the current screens to transition off. foreach (ManagedGameComponent screen in componentManager.Components) screen.ExitScreen(); // Create and activate the loading screen. Loader _Loader = new Loader(componentManager,loadingScreen,screensToLoad); componentManager.Add(_Loader); }
public void Add(ManagedGameComponent component) { if (component.ComponentManager == null) { component.ComponentManager = this; component.IsExiting = false; Components.Add(component); } else { //exception here? //throw new Exception("Component is already being managed by another component"); } }
/// <summary> /// Allows the screen to run logic, such as updating the transition position. /// Unlike HandleInput, this method is called regardless of whether the screen /// is active, hidden, or in the middle of a transition. /// </summary> /// public override void Update(GameTime gameTime) { // Read the keyboard and gamepad. //input.Update(); // Make a copy of the master screen list, to avoid confusion if // the process of updating one screen adds or removes others. _ComponentsToUpdate.Clear(); foreach (ManagedGameComponent screen in Components) { _ComponentsToUpdate.Add(screen); } bool otherScreenHasFocus = !Game.IsActive; bool coveredByOtherScreen = false; // Loop as long as there are screens waiting to be updated. while (_ComponentsToUpdate.Count > 0) { // Pop the topmost screen off the waiting list. ManagedGameComponent screen = _ComponentsToUpdate[_ComponentsToUpdate.Count - 1]; _ComponentsToUpdate.RemoveAt(_ComponentsToUpdate.Count - 1); // Update the screen. screen.Update(gameTime); screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (screen.ScreenState == ScreenState.TransitionOn || screen.ScreenState == ScreenState.Active) { // If this is the first active screen we came across, // give it a chance to handle input. if (!otherScreenHasFocus) { //screen.HandleInput(input); otherScreenHasFocus = true; } // If this is an active non-popup, inform any subsequent // screens that they are covered by it. if (!screen.IsPopup) { coveredByOtherScreen = true; } } } }
/// <summary> /// Activates the loading screen. /// </summary> public static void Load(ManagedGameComponent componentManager, ManagedGameComponent loadingScreen, params ManagedGameComponent[] screensToLoad) { // Tell all the current screens to transition off. foreach (ManagedGameComponent screen in componentManager.Components) { screen.ExitScreen(); } // Create and activate the loading screen. Loader _Loader = new Loader(componentManager, loadingScreen, screensToLoad); componentManager.Add(_Loader); }