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);
|
var typesContainer = Ui.Root.Get(tabs.TypesContainer);
|
||||||
foreach (var i in typesContainer.Children)
|
foreach (var i in typesContainer.Children)
|
||||||
SetupProductionGroupButton(i as ProductionTypeButtonWidget);
|
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()
|
void UnregisterEvents()
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
public readonly ReadyTextStyleOptions ReadyTextStyle = ReadyTextStyleOptions.Blinking;
|
public readonly ReadyTextStyleOptions ReadyTextStyle = ReadyTextStyleOptions.Blinking;
|
||||||
public readonly Color ReadyTextAltColor = Color.Red;
|
public readonly Color ReadyTextAltColor = Color.Red;
|
||||||
public readonly int Columns = 3;
|
public readonly int Columns = 3;
|
||||||
|
public readonly int2 IconSize = new int2(64, 48);
|
||||||
|
|
||||||
public readonly string TabClick = null;
|
public readonly string TabClick = null;
|
||||||
public readonly string DisabledTabClick = null;
|
public readonly string DisabledTabClick = null;
|
||||||
public readonly string TooltipContainer;
|
public readonly string TooltipContainer;
|
||||||
@@ -45,6 +47,9 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
[Translate] public readonly string ReadyText = "";
|
[Translate] public readonly string ReadyText = "";
|
||||||
[Translate] public readonly string HoldText = "";
|
[Translate] public readonly string HoldText = "";
|
||||||
|
|
||||||
|
public int IconCount { get; private set; }
|
||||||
|
public event Action<int, int> OnIconCountChanged = (a, b) => {};
|
||||||
|
|
||||||
public string TooltipActor { get; private set; }
|
public string TooltipActor { get; private set; }
|
||||||
public readonly World World;
|
public readonly World World;
|
||||||
readonly OrderManager orderManager;
|
readonly OrderManager orderManager;
|
||||||
@@ -176,18 +181,30 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
{
|
{
|
||||||
icons = new Dictionary<Rectangle, ProductionIcon>();
|
icons = new Dictionary<Rectangle, ProductionIcon>();
|
||||||
if (CurrentQueue == null)
|
if (CurrentQueue == null)
|
||||||
|
{
|
||||||
|
if (IconCount != 0)
|
||||||
|
{
|
||||||
|
OnIconCountChanged(IconCount, 0);
|
||||||
|
IconCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var allBuildables = CurrentQueue.AllItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);
|
var allBuildables = CurrentQueue.AllItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);
|
||||||
var i = 0;
|
|
||||||
|
var oldIconCount = IconCount;
|
||||||
|
IconCount = 0;
|
||||||
|
|
||||||
var rb = RenderBounds;
|
var rb = RenderBounds;
|
||||||
foreach (var item in allBuildables)
|
foreach (var item in allBuildables)
|
||||||
{
|
{
|
||||||
var x = i % Columns;
|
var x = IconCount % Columns;
|
||||||
var y = i / Columns;
|
var y = IconCount / Columns;
|
||||||
var rect = new Rectangle(rb.X + x * 64 + 1, rb.Y + y * 48 + 1, 64, 48);
|
var rect = new Rectangle(rb.X + x * IconSize.X + 1, rb.Y + y * IconSize.Y + 1, IconSize.X, IconSize.Y);
|
||||||
var icon = new Animation(World, RenderSimple.GetImage(item));
|
var icon = new Animation(World, RenderSimple.GetImage(item));
|
||||||
icon.Play(item.Traits.Get<TooltipInfo>().Icon);
|
icon.Play(item.Traits.Get<TooltipInfo>().Icon);
|
||||||
|
|
||||||
var pi = new ProductionIcon()
|
var pi = new ProductionIcon()
|
||||||
{
|
{
|
||||||
Name = item.Name,
|
Name = item.Name,
|
||||||
@@ -195,17 +212,20 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
Pos = new float2(rect.Location),
|
Pos = new float2(rect.Location),
|
||||||
Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
|
Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
|
||||||
};
|
};
|
||||||
|
|
||||||
icons.Add(rect, pi);
|
icons.Add(rect, pi);
|
||||||
i++;
|
IconCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
eventBounds = icons.Any() ? icons.Keys.Aggregate(Rectangle.Union) : Rectangle.Empty;
|
eventBounds = icons.Any() ? icons.Keys.Aggregate(Rectangle.Union) : Rectangle.Empty;
|
||||||
|
|
||||||
|
if (oldIconCount != IconCount)
|
||||||
|
OnIconCountChanged(oldIconCount, IconCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
var iconSize = new float2(64, 48);
|
var iconOffset = 0.5f * IconSize.ToFloat2();
|
||||||
var iconOffset = 0.5f * iconSize;
|
|
||||||
|
|
||||||
overlayFont = Game.Renderer.Fonts["TinyBold"];
|
overlayFont = Game.Renderer.Fonts["TinyBold"];
|
||||||
timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
|
timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
|
||||||
@@ -218,10 +238,6 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
|
|
||||||
var buildableItems = CurrentQueue.BuildableItems();
|
var buildableItems = CurrentQueue.BuildableItems();
|
||||||
|
|
||||||
// Background
|
|
||||||
foreach (var rect in icons.Keys)
|
|
||||||
WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1, 1, 1, 1));
|
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
foreach (var icon in icons.Values)
|
foreach (var icon in icons.Values)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
|
|
||||||
public readonly string PaletteWidget = null;
|
public readonly string PaletteWidget = null;
|
||||||
public readonly string TypesContainer = null;
|
public readonly string TypesContainer = null;
|
||||||
|
public readonly string BackgroundContainer = null;
|
||||||
|
|
||||||
public readonly int TabWidth = 30;
|
public readonly int TabWidth = 30;
|
||||||
public readonly int ArrowWidth = 20;
|
public readonly int ArrowWidth = 20;
|
||||||
|
|||||||
@@ -369,21 +369,29 @@ Container@PLAYER_WIDGETS:
|
|||||||
X: 7
|
X: 7
|
||||||
Y: 7
|
Y: 7
|
||||||
ImageCollection: production-icons
|
ImageCollection: production-icons
|
||||||
ProductionTabs@PRODUCTION_TABS:
|
Container@PRODUCTION_BACKGROUND:
|
||||||
Logic: ProductionTabsLogic
|
|
||||||
PaletteWidget: PRODUCTION_PALETTE
|
|
||||||
TypesContainer: PRODUCTION_TYPES
|
|
||||||
X: WINDOW_RIGHT - 204
|
X: WINDOW_RIGHT - 204
|
||||||
Y: 268
|
Y: 287
|
||||||
Width: 194
|
Children:
|
||||||
Height: 20
|
Background@ICON_TEMPLATE:
|
||||||
|
Width: 66
|
||||||
|
Height: 50
|
||||||
|
Background: panel-black
|
||||||
ProductionPalette@PRODUCTION_PALETTE:
|
ProductionPalette@PRODUCTION_PALETTE:
|
||||||
X: WINDOW_RIGHT - 204
|
X: WINDOW_RIGHT - 204
|
||||||
Y: 287
|
Y: 287
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ReadyText: Ready
|
ReadyText: Ready
|
||||||
HoldText: On Hold
|
HoldText: On Hold
|
||||||
|
ProductionTabs@PRODUCTION_TABS:
|
||||||
|
Logic: ProductionTabsLogic
|
||||||
|
PaletteWidget: PRODUCTION_PALETTE
|
||||||
|
TypesContainer: PRODUCTION_TYPES
|
||||||
|
BackgroundContainer: PRODUCTION_BACKGROUND
|
||||||
|
X: WINDOW_RIGHT - 204
|
||||||
|
Y: 268
|
||||||
|
Width: 194
|
||||||
|
Height: 20
|
||||||
Background@FMVPLAYER:
|
Background@FMVPLAYER:
|
||||||
Width: WINDOW_RIGHT
|
Width: WINDOW_RIGHT
|
||||||
Height: WINDOW_BOTTOM
|
Height: WINDOW_BOTTOM
|
||||||
|
|||||||
Reference in New Issue
Block a user