Extract ProductionPalette background drawing into logic code.

This commit is contained in:
Paul Chote
2014-07-12 21:37:06 +12:00
parent 54b5da3460
commit 2de9d3780b
4 changed files with 72 additions and 19 deletions

View File

@@ -55,6 +55,34 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var typesContainer = Ui.Root.Get(tabs.TypesContainer);
foreach (var i in typesContainer.Children)
SetupProductionGroupButton(i as ProductionTypeButtonWidget);
var background = Ui.Root.GetOrNull(tabs.BackgroundContainer);
if (background != null)
{
var palette = tabs.Parent.Get<ProductionPaletteWidget>(tabs.PaletteWidget);
var icontemplate = background.Get("ICON_TEMPLATE");
Action<int, int> updateBackground = (oldCount, newCount) =>
{
background.RemoveChildren();
for (var i = 0; i < newCount; i++)
{
var x = i % palette.Columns;
var y = i / palette.Columns;
var bg = icontemplate.Clone();
bg.Bounds.X = palette.IconSize.X * x;
bg.Bounds.Y = palette.IconSize.Y * y;
background.AddChild(bg);
}
};
palette.OnIconCountChanged += updateBackground;
// Set the initial palette state
updateBackground(0, 0);
}
}
void UnregisterEvents()