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:
@@ -32,6 +32,7 @@ namespace OpenRa.Game
|
||||
public Sidebar( Race race, Renderer renderer, Game game )
|
||||
{
|
||||
this.techTree = game.LocalPlayer.TechTree;
|
||||
this.techTree.BuildableItemsChanged += (sender, e) => { PopulateItemList(); };
|
||||
this.game = game;
|
||||
region = GRegion.Create(game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
|
||||
game.viewport.AddRegion( region );
|
||||
@@ -98,7 +99,7 @@ namespace OpenRa.Game
|
||||
|
||||
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)
|
||||
i.Paint(spriteRenderer, region.Location);
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace OpenRa.Game
|
||||
public readonly float2 location;
|
||||
readonly Sprite sprite;
|
||||
|
||||
public bool isBuilding = false;
|
||||
|
||||
public SidebarItem(Sprite s, Item item, int y)
|
||||
{
|
||||
this.techTreeItem = item;
|
||||
|
||||
@@ -93,8 +93,16 @@ namespace OpenRa.TechTree
|
||||
|
||||
void CheckAll()
|
||||
{
|
||||
bool changed = false;
|
||||
foreach (Item unit in objects.Values)
|
||||
{
|
||||
bool old = unit.CanBuild;
|
||||
unit.CheckPrerequisites(built, currentRace);
|
||||
if (old != unit.CanBuild)
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) BuildableItemsChanged(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public IEnumerable<Item> BuildableItems
|
||||
@@ -106,5 +114,7 @@ namespace OpenRa.TechTree
|
||||
yield return b;
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler BuildableItemsChanged = (sender, e) => { };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user