2012-08-09 09:45:04 +00:00
|
|
|
#region Using Statements
|
2011-10-31 05:36:24 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.ObjectModel;
|
2012-08-29 12:46:08 +00:00
|
|
|
using ANX.Framework.NonXNA.Development;
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
#endregion // Using Statements
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
namespace ANX.Framework
|
|
|
|
{
|
2012-08-29 12:46:08 +00:00
|
|
|
[PercentageComplete(100)]
|
2012-10-14 09:02:26 +00:00
|
|
|
[TestState(TestStateAttribute.TestState.Tested)]
|
|
|
|
[Developer("Glatzemann, AstrorEnales")]
|
2011-10-31 05:36:24 +00:00
|
|
|
public sealed class GameComponentCollection : Collection<IGameComponent>
|
|
|
|
{
|
2012-08-29 12:32:14 +00:00
|
|
|
#region Events
|
2011-10-31 05:36:24 +00:00
|
|
|
public event EventHandler<GameComponentCollectionEventArgs> ComponentAdded;
|
|
|
|
public event EventHandler<GameComponentCollectionEventArgs> ComponentRemoved;
|
2012-08-29 12:32:14 +00:00
|
|
|
#endregion
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
protected override void ClearItems()
|
|
|
|
{
|
2012-10-14 09:02:26 +00:00
|
|
|
for (int i = 0; i < Count; i++)
|
2012-08-29 12:32:14 +00:00
|
|
|
OnComponentRemoved(base[i]);
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
base.ClearItems();
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
protected override void InsertItem(int index, IGameComponent item)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2012-10-14 09:02:26 +00:00
|
|
|
if (IndexOf(item) != -1)
|
|
|
|
throw new ArgumentException(
|
|
|
|
"Cannot add the same game component to a game component collection multiple times.");
|
2012-08-29 12:32:14 +00:00
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
base.InsertItem(index, item);
|
|
|
|
if(item != null)
|
|
|
|
OnComponentAdded(item);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
protected override void RemoveItem(int index)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2012-08-29 12:32:14 +00:00
|
|
|
IGameComponent component = base[index];
|
2012-10-14 09:02:26 +00:00
|
|
|
base.RemoveItem(index);
|
|
|
|
if (component != null)
|
|
|
|
OnComponentRemoved(component);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 12:32:14 +00:00
|
|
|
protected override void SetItem(int index, IGameComponent item)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2012-10-14 09:02:26 +00:00
|
|
|
throw new NotSupportedException(
|
|
|
|
"Cannot set a value using operator[] on GameComponentCollection. Use Add/Remove instead.");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 12:32:14 +00:00
|
|
|
private void OnComponentAdded(IGameComponent component)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2012-08-29 12:32:14 +00:00
|
|
|
if (ComponentAdded != null)
|
|
|
|
ComponentAdded(this, new GameComponentCollectionEventArgs(component));
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-08-29 12:32:14 +00:00
|
|
|
private void OnComponentRemoved(IGameComponent component)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2012-08-29 12:32:14 +00:00
|
|
|
if (ComponentRemoved != null)
|
|
|
|
ComponentRemoved(this, new GameComponentCollectionEventArgs(component));
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|