using Chernobyl.Collections.Generic.Event; using Chernobyl.DesignPatterns.Extension; using Chernobyl.Game; namespace Chernobyl.Interface.Game.StateMachine { /// /// An that, when attached to an /// , displays itself when that enters /// into its paused state. /// public class PauseScreen : StateScreen { /// /// Initializes a new instance of the class. /// /// The root /// instance that gives and takes services. /// The instance whose pause state is to be /// rendered to the screen. public PauseScreen(IEventCollection services, IGame extended) : base(services) { _services = services; Extended = extended; } /// /// Attaches this extension to the passed in object so that is can be /// extended. /// /// The object to extend. protected override void AttachTo(IGame extended) { extended.OfType(service => PausedEnableable = service); } /// /// Removes this extension from an object so that it is no longer extended. /// /// The object to remove the extension from. protected override void DetachFrom(IGame extended) { PausedEnableable = null; } /// /// The instance retrieved from the extended /// instance that indicates whether the /// is paused or not. /// IEnableable PausedEnableable { get { return _pausedEnableable; } set { IEnableable previousValue = _pausedEnableable; _pausedEnableable = value; if (previousValue != null) { previousValue.Enabled.Entered -= OnOffDrawable.Enable; previousValue.Enabled.Left -= OnOffDrawable.Disable; } if (_pausedEnableable != null) { _pausedEnableable.Enabled.Entered += OnOffDrawable.Enable; _pausedEnableable.Enabled.Left += OnOffDrawable.Disable; } } } /// /// The root instance that gives and /// takes services. /// IEventCollection _services; /// /// The backing field to . /// IEnableable _pausedEnableable; } }