Added BuildableItemsChanged event to tech tree.

This lets the Sidebar only repopulate its item list when the items that can be built changes.
This commit is contained in:
Matthew Bowra-Dean
2009-10-07 03:37:35 +13:00
parent 803b18d9b5
commit aa3801eace
3 changed files with 14 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ namespace OpenRa.Game
public Sidebar( Race race, Renderer renderer, Game game ) public Sidebar( Race race, Renderer renderer, Game game )
{ {
this.techTree = game.LocalPlayer.TechTree; this.techTree = game.LocalPlayer.TechTree;
this.techTree.BuildableItemsChanged += (sender, e) => { PopulateItemList(); };
this.game = game; this.game = game;
region = GRegion.Create(game.viewport, DockStyle.Right, 128, Paint, MouseHandler); region = GRegion.Create(game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
game.viewport.AddRegion( region ); game.viewport.AddRegion( region );
@@ -98,7 +99,7 @@ namespace OpenRa.Game
void Paint() void Paint()
{ {
PopulateItemList(); // todo: do this less often, just when things actually change! // PopulateItemList(); // todo: do this less often, just when things actually change!
foreach (SidebarItem i in items) foreach (SidebarItem i in items)
i.Paint(spriteRenderer, region.Location); i.Paint(spriteRenderer, region.Location);

View File

@@ -9,6 +9,8 @@ namespace OpenRa.Game
public readonly float2 location; public readonly float2 location;
readonly Sprite sprite; readonly Sprite sprite;
public bool isBuilding = false;
public SidebarItem(Sprite s, Item item, int y) public SidebarItem(Sprite s, Item item, int y)
{ {
this.techTreeItem = item; this.techTreeItem = item;

View File

@@ -93,8 +93,16 @@ namespace OpenRa.TechTree
void CheckAll() void CheckAll()
{ {
bool changed = false;
foreach (Item unit in objects.Values) foreach (Item unit in objects.Values)
{
bool old = unit.CanBuild;
unit.CheckPrerequisites(built, currentRace); unit.CheckPrerequisites(built, currentRace);
if (old != unit.CanBuild)
changed = true;
}
if (changed) BuildableItemsChanged(this, EventArgs.Empty);
} }
public IEnumerable<Item> BuildableItems public IEnumerable<Item> BuildableItems
@@ -106,5 +114,7 @@ namespace OpenRa.TechTree
yield return b; yield return b;
} }
} }
public event EventHandler BuildableItemsChanged = (sender, e) => { };
} }
} }