using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Xna.Framework;
// ************************************************************************* //
// Disable 'missing xml comment' warning for this file since it has been
// generated by .NET Reflector and I'm not going to comment this all
// just so I have to start from scratch again when XNA gets updated
#pragma warning disable 1591
// ************************************************************************* //
namespace Nuclex
{
/// A collection of game components.
public sealed class GameComponentCollection : Collection
{
/// Raised when a component is added to the GameComponentCollection.
public event EventHandler ComponentAdded;
///
/// Raised when a component is removed from the GameComponentCollection.
///
public event EventHandler ComponentRemoved;
// Methods
internal GameComponentCollection()
{
}
/// Removes all children from the collection.
protected override void ClearItems()
{
for (int i = 0; i < base.Count; i++)
{
this.OnComponentRemoved(new GameComponentCollectionEventArgs(base[i]));
}
base.ClearItems();
}
/// Inserts a child object into the collection at the specified location.
/// The position in the collection.
/// The child object being inserted.
protected override void InsertItem(int index, IGameComponent item)
{
if (base.IndexOf(item) != -1)
{
throw new ArgumentException("Resources.CannotAddSameComponentMultipleTimes");
}
base.InsertItem(index, item);
if (item != null)
{
this.OnComponentAdded(new GameComponentCollectionEventArgs(item));
}
}
private void OnComponentAdded(GameComponentCollectionEventArgs eventArgs)
{
if (this.ComponentAdded != null)
{
this.ComponentAdded(this, eventArgs);
}
}
private void OnComponentRemoved(GameComponentCollectionEventArgs eventArgs)
{
if (this.ComponentRemoved != null)
{
this.ComponentRemoved(this, eventArgs);
}
}
/// Removes a child object in the collection.
/// The index of the item being removed.
protected override void RemoveItem(int index)
{
IGameComponent gameComponent = base[index];
base.RemoveItem(index);
if (gameComponent != null)
{
this.OnComponentRemoved(new GameComponentCollectionEventArgs(gameComponent));
}
}
/// Modifies the specified child object in the collection.
/// The position in the collection.
/// The child object being modified.
protected override void SetItem(int index, IGameComponent item)
{
throw new NotSupportedException("Resources.CannotSetItemsIntoGameComponentCollection");
}
}
} // namespace Nuclex