diff --git a/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs b/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs index d4bb90aa28..674660f633 100644 --- a/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace BizHawk.Emulation.Common { @@ -15,10 +16,50 @@ namespace BizHawk.Emulation.Common public void RemoveAll(IEnumerable actions) { + var hadAny = this.Any(); + foreach (var action in actions) { this.Remove(action); } + + var hasAny = this.Any(); + + Changes(hadAny, hasAny); + } + + public new void Add(Action item) + { + var hadAny = this.Any(); + base.Add(item); + var hasAny = this.Any(); + + Changes(hadAny, hasAny); + } + + public new bool Remove(Action item) + { + var hadAny = this.Any(); + return base.Remove(item); + var hasAny = this.Any(); + + Changes(hadAny, hasAny); + } + + // TODO: these just happen to be all the add/remove methods the client uses, to be thorough the others should be overriden as well + + public delegate void ActiveChangedEventHandler(); + public event ActiveChangedEventHandler ActiveChanged; + + private void Changes(bool hadAny, bool hasAny) + { + if ((hadAny && !hasAny) || (!hadAny && hasAny)) + { + if (ActiveChanged != null) + { + ActiveChanged(); + } + } } } }