From cd85a95aeeb903c1aa6f6752c1024f2fb72ca5f5 Mon Sep 17 00:00:00 2001 From: teinarss Date: Sat, 22 Jun 2019 11:57:18 +0200 Subject: [PATCH] Updated production spec widget to handle overflow --- .../Widgets/ObserverProductionIconsWidget.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs b/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs index cc7bbaf4640d..54e28a962f38 100644 --- a/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs @@ -47,6 +47,7 @@ public class ObserverProductionIconsWidget : Widget float2 iconSize; int lastIconIdx; + public int MinWidth = 240; [ObjectCreator.UseCtor] public ObserverProductionIconsWidget(World world, WorldRenderer worldRenderer) @@ -82,6 +83,8 @@ protected ObserverProductionIconsWidget(ObserverProductionIconsWidget other) TooltipIcon = other.TooltipIcon; GetTooltipIcon = () => TooltipIcon; + MinWidth = other.MinWidth; + TooltipTemplate = other.TooltipTemplate; TooltipContainer = other.TooltipContainer; @@ -114,7 +117,7 @@ public override void Draw() .ThenBy(g => g.First().BuildPaletteOrder) .ToList(); - Bounds.Width = currentItemsByItem.Count * (IconWidth + IconSpacing); + Bounds.Width = Math.Max(currentItemsByItem.Count * (IconWidth + IconSpacing), MinWidth); var queueCol = 0; foreach (var currentItems in currentItemsByItem) @@ -172,6 +175,20 @@ public override void Draw() queueCol++; } + + var parentWidth = Bounds.X + Bounds.Width; + Parent.Bounds.Width = parentWidth; + + var gradient = Parent.Get("PLAYER_GRADIENT"); + + var offset = gradient.Bounds.X - Bounds.X; + var gradientWidth = Math.Max(MinWidth - offset, currentItemsByItem.Count * (IconWidth + IconSpacing)); + + gradient.Bounds.Width = gradientWidth; + var widestChildWidth = Parent.Parent.Children.Max(x => x.Bounds.Width); + + // Add 25 pixels to account for the scrollbar on the left and 25 for gradiend fade-out after the icons. + Parent.Parent.Bounds.Width = Math.Max(25 + widestChildWidth, Bounds.Left + MinWidth); } static string GetOverlayForItem(ProductionItem item, int timestep)