Extract ProductionPalette background drawing into logic code.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user