#region CPL License /* Nuclex Framework Copyright (C) 2002-2011 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 Microsoft.Xna.Framework; using StateEventHandler = System.EventHandler; namespace Nuclex.Game.States { /// Base class for updateable game states public abstract class GameState : IGameState, IUpdateable { /// Never called because the Enabled property cannot change event StateEventHandler IUpdateable.EnabledChanged { add { } remove { } } /// Never called because the UpdateOrder property cannot change event StateEventHandler IUpdateable.UpdateOrderChanged { add { } remove { } } /// Initializes a new game state /// Called when the game state is being paused public void Pause() { if (!this.paused) { OnPause(); this.paused = true; } } /// Called when the game state is being resumed from pause mode public void Resume() { if (this.paused) { OnResume(); this.paused = false; } } /// Called when the component needs to update its state. /// Provides a snapshot of the Game's timing values public abstract void Update(GameTime gameTime); /// Called when the game state has been entered protected virtual void OnEntered() { } /// Called when the game state is being left again protected virtual void OnLeaving() { } /// Called when the game state should enter pause mode protected virtual void OnPause() { } /// Called when the game state should resume from pause mode protected virtual void OnResume() { } /// Whether the game state is currently paused protected bool Paused { get { return this.paused; } } /// Called when the game state has been entered void IGameState.Enter() { OnEntered(); } /// Called when the game state is being left again void IGameState.Leave() { OnLeaving(); } /// /// Always true to indicate the game state is enabled and should be updated /// bool IUpdateable.Enabled { get { return true; } } /// /// Always 0 because game states have no ordering relative to each other /// int IUpdateable.UpdateOrder { get { return 0; } } /// Used to avoid pausing the game state multiple times private bool paused; } } // namespace Nuclex.Game.States