#region CPL License /* Nuclex Framework Copyright (C) 2002-2010 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using SynapseGaming.LightingSystem.Core; using SynapseGaming.LightingSystem.Rendering; using Ninject; namespace Nuclex.Ninject.Sunburn { /// /// Displays the Sunburn splash screen and sends out a notification when /// the splash screen has finished /// /// /// When the splash screen has finished displaying, this component drops all /// of its references and turns into a service that does nothing more than /// return the value of a boolean. /// public class SplashScreenComponent : DrawableGameComponent, ISplashScreenService { /// Triggered once when the splash screen has been displayed public event EventHandler DisplayComplete; /// Initializes a new splash screen display component /// Game the splash screen will be displayed in /// Access hub for all of Sunburn's managers /// Kernel that is managing the game public SplashScreenComponent(Game game, SceneInterface sceneInterface, IKernel kernel) : base(game) { this.sceneInterface = sceneInterface; this.kernel = kernel; } /// Whether the splash screen has finished displaying itself public bool IsDisplayComplete { get { return this.displayComplete; } } /// Called when the GameComponent needs to be updated /// Time elapsed since the last call to Update public override void Update(GameTime gameTime) { if (!this.displayComplete) { this.sceneInterface.Update(gameTime); this.sunburnSplashScreen.Update(gameTime); } } /// Called when the DrawableGameComponent needs to be drawn /// Time passed since the last call to Draw public override void Draw(GameTime gameTime) { if (!this.displayComplete) { this.sunburnSplashScreen.Draw(gameTime); if (SplashScreenGameComponent.DisplayComplete) { OnDisplayComplete(); } } } /// Called when the splash screen has finished displaying protected virtual void OnDisplayComplete() { this.displayComplete = true; disposeSunburnSplashScreen(); if (DisplayComplete != null) { DisplayComplete(this, EventArgs.Empty); // Eliminate all subscribers. This allows subscribers that are kept alive // solely by the event subscription to be garbage collected. DisplayComplete = null; } } /// Immediately releases all resources owned by the instance /// /// Whether dispsoe has been called explicitly and it is safe to access other /// objects referenced by this instance /// protected override void Dispose(bool calledExplicitly) { disposeSunburnSplashScreen(); } /// Called when graphics resources need to be loaded protected override void LoadContent() { if (this.sunburnSplashScreen == null) { // The SplashScreenGameComponent accesses the LightingSystemManager through // an internal static property (so the LightingSystemManager is sort of an // explicitly instantiated singleton). Because there's no dependency visible // to Ninject, we have to make sure the LightingSystemManager is created first. this.kernel.Get(); // Set up a new Sunburn splash screen and add it to the game's component // collection so it will be drawn. this.sunburnSplashScreen = new SplashScreenGameComponent( Game, this.kernel.Get() ); Game.Components.Add(this.sunburnSplashScreen); } } /// Disposes the sunburn splash screen game component if it exists private void disposeSunburnSplashScreen() { Game.Components.Remove(this.sunburnSplashScreen); if (this.sunburnSplashScreen != null) { this.sunburnSplashScreen.Dispose(); this.sunburnSplashScreen = null; } this.kernel = null; this.sceneInterface = null; } /// Whether Sunburn has finished displaying the splash screen private bool displayComplete; /// The splash screen game component from sunburn private SplashScreenGameComponent sunburnSplashScreen; /// The kernel private IKernel kernel; /// Access hub for all of Sunburn's managers private SceneInterface sceneInterface; } } // namespace Nuclex.Ninject.Sunburn