InputCallbackSystem - add an ActiveChanged event handler, the event fires anytime the collection goes from 0 to greater than 0, or greater than 0 to 0

This commit is contained in:
adelikat 2014-12-04 00:56:04 +00:00
parent a07263c04e
commit ccb8cce788
1 changed files with 41 additions and 0 deletions

View File

@ -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<Action> 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();
}
}
}
}
}