Add a CellEntryChanged event to CellLayer.

This commit is contained in:
Paul Chote
2014-12-02 18:14:52 +13:00
parent ab4a8be66e
commit e064593961

View File

@@ -20,6 +20,8 @@ namespace OpenRA
{ {
public readonly Size Size; public readonly Size Size;
public readonly TileShape Shape; public readonly TileShape Shape;
public event Action<CPos> CellEntryChanged = null;
readonly T[] entries; readonly T[] entries;
public CellLayer(Map map) public CellLayer(Map map)
@@ -48,15 +50,35 @@ namespace OpenRA
/// <summary>Gets or sets the <see cref="OpenRA.CellLayer"/> using cell coordinates</summary> /// <summary>Gets or sets the <see cref="OpenRA.CellLayer"/> using cell coordinates</summary>
public T this[CPos cell] public T this[CPos cell]
{ {
get { return entries[Index(cell)]; } get
set { entries[Index(cell)] = value; } {
return entries[Index(cell)];
}
set
{
entries[Index(cell)] = value;
if (CellEntryChanged != null)
CellEntryChanged(cell);
}
} }
/// <summary>Gets or sets the layer contents using raw map coordinates (not CPos!)</summary> /// <summary>Gets or sets the layer contents using raw map coordinates (not CPos!)</summary>
public T this[int u, int v] public T this[int u, int v]
{ {
get { return entries[Index(u, v)]; } get
set { entries[Index(u, v)] = value; } {
return entries[Index(u, v)];
}
set
{
entries[Index(u, v)] = value;
if (CellEntryChanged != null)
CellEntryChanged(Map.MapToCell(Shape, new CPos(u, v)));
}
} }
/// <summary>Clears the layer contents with a known value</summary> /// <summary>Clears the layer contents with a known value</summary>