Skip to content

Commit

Permalink
Updated production spec widget to handle overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
teinarss committed Oct 20, 2019
1 parent 5e3d163 commit cd85a95
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs
Expand Up @@ -47,6 +47,7 @@ public class ObserverProductionIconsWidget : Widget

float2 iconSize;
int lastIconIdx;
public int MinWidth = 240;

[ObjectCreator.UseCtor]
public ObserverProductionIconsWidget(World world, WorldRenderer worldRenderer)
Expand Down Expand Up @@ -82,6 +83,8 @@ protected ObserverProductionIconsWidget(ObserverProductionIconsWidget other)
TooltipIcon = other.TooltipIcon;
GetTooltipIcon = () => TooltipIcon;

MinWidth = other.MinWidth;

TooltipTemplate = other.TooltipTemplate;
TooltipContainer = other.TooltipContainer;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -172,6 +175,20 @@ public override void Draw()

queueCol++;
}

var parentWidth = Bounds.X + Bounds.Width;
Parent.Bounds.Width = parentWidth;

var gradient = Parent.Get<GradientColorBlockWidget>("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)
Expand Down

0 comments on commit cd85a95

Please sign in to comment.