2014-12-04 00:43:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-12-04 00:56:04 +00:00
|
|
|
|
using System.Linq;
|
2014-12-04 00:43:12 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Emulation.Common
|
|
|
|
|
{
|
2016-12-14 15:11:07 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is a generic implementation of IInputCallbackSystem that can be used
|
|
|
|
|
/// by any core
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <seealso cref="IInputCallbackSystem" />
|
2014-12-04 00:43:12 +00:00
|
|
|
|
public class InputCallbackSystem : List<Action>, IInputCallbackSystem
|
|
|
|
|
{
|
|
|
|
|
public void Call()
|
|
|
|
|
{
|
|
|
|
|
foreach (var action in this)
|
|
|
|
|
{
|
|
|
|
|
action();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 13:24:21 +00:00
|
|
|
|
// TODO: these just happen to be all the add/remove methods the client uses, to be thorough the others should be overriden as well
|
2014-12-04 00:43:12 +00:00
|
|
|
|
public void RemoveAll(IEnumerable<Action> actions)
|
|
|
|
|
{
|
2014-12-04 00:56:04 +00:00
|
|
|
|
var hadAny = this.Any();
|
|
|
|
|
|
2014-12-04 00:43:12 +00:00
|
|
|
|
foreach (var action in actions)
|
|
|
|
|
{
|
2016-02-29 00:03:01 +00:00
|
|
|
|
Remove(action);
|
2014-12-04 00:43:12 +00:00
|
|
|
|
}
|
2014-12-04 00:56:04 +00:00
|
|
|
|
|
|
|
|
|
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();
|
2014-12-04 22:31:42 +00:00
|
|
|
|
var result = base.Remove(item);
|
2014-12-04 00:56:04 +00:00
|
|
|
|
var hasAny = this.Any();
|
|
|
|
|
|
|
|
|
|
Changes(hadAny, hasAny);
|
2014-12-04 22:31:42 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2014-12-04 00:56:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public delegate void ActiveChangedEventHandler();
|
|
|
|
|
public event ActiveChangedEventHandler ActiveChanged;
|
|
|
|
|
|
|
|
|
|
private void Changes(bool hadAny, bool hasAny)
|
|
|
|
|
{
|
|
|
|
|
if ((hadAny && !hasAny) || (!hadAny && hasAny))
|
|
|
|
|
{
|
2017-04-15 20:37:30 +00:00
|
|
|
|
ActiveChanged?.Invoke();
|
2014-12-04 00:56:04 +00:00
|
|
|
|
}
|
2014-12-04 00:43:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|