Skip to content

Commit

Permalink
Fix production tooltip padding.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Dec 5, 2018
1 parent bdbc193 commit be1158e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
30 changes: 25 additions & 5 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs
Expand Up @@ -50,6 +50,8 @@ public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipConta
ActorInfo lastActor = null;
Hotkey lastHotkey = Hotkey.Invalid;
var lastPowerState = pm == null ? PowerState.Normal : pm.PowerState;
var descLabelY = descLabel.Bounds.Y;
var descLabelPadding = descLabel.Bounds.Height;

tooltipContainer.BeforeRender = () =>
{
Expand Down Expand Up @@ -88,8 +90,20 @@ public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipConta
var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a))
.Where(s => !s.StartsWith("~", StringComparison.Ordinal) && !s.StartsWith("!", StringComparison.Ordinal));
requiresLabel.Text = prereqs.Any() ? requiresFormat.F(prereqs.JoinWith(", ")) : "";
var requiresSize = requiresFont.Measure(requiresLabel.Text);
var requiresSize = int2.Zero;
if (prereqs.Any())
{
requiresLabel.Text = requiresFormat.F(prereqs.JoinWith(", "));
requiresSize = requiresFont.Measure(requiresLabel.Text);
requiresLabel.Visible = true;
descLabel.Bounds.Y = descLabelY + requiresLabel.Bounds.Height;
}
else
{
requiresLabel.Visible = false;
descLabel.Bounds.Y = descLabelY;
}
var powerSize = new int2(0, 0);
if (pm != null)
Expand All @@ -116,6 +130,8 @@ public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipConta
descLabel.Text = buildable.Description.Replace("\\n", "\n");
var descSize = descFont.Measure(descLabel.Text);
descLabel.Bounds.Width = descSize.X;
descLabel.Bounds.Height = descSize.Y + descLabelPadding;
var leftWidth = new[] { nameSize.X + hotkeyWidth, requiresSize.X, descSize.X }.Aggregate(Math.Max);
var rightWidth = new[] { powerSize.X, timeSize.X, costSize.X }.Aggregate(Math.Max);
Expand All @@ -124,9 +140,13 @@ public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipConta
timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = timeIcon.Bounds.Right + iconMargin;
widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X + timeIcon.Bounds.Width + iconMargin;
var leftHeight = nameSize.Y + requiresSize.Y + descSize.Y;
var rightHeight = powerSize.Y + timeSize.Y + costSize.Y;
widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;
// Set the bottom margin to match the left margin
var leftHeight = descLabel.Bounds.Bottom + descLabel.Bounds.X;
// Set the bottom margin to match the top margin
var rightHeight = (powerLabel.Visible ? powerIcon.Bounds.Bottom : timeIcon.Bounds.Bottom) + costIcon.Bounds.Top;
widget.Bounds.Height = Math.Max(leftHeight, rightHeight);
lastActor = actor;
lastHotkey = hotkey;
Expand Down
9 changes: 6 additions & 3 deletions mods/cnc/chrome/tooltips.yaml
Expand Up @@ -102,18 +102,19 @@ Background@PRODUCTION_TOOLTIP:
Label@REQUIRES:
X: 5
Y: 19
Height: 23
Height: 15
Font: TinyBold
Text: Requires {0}
Label@DESC:
X: 5
Y: 39
Height: 23
Y: 19
Height: 5
Font: TinyBold
VAlign: Top
Image@COST_ICON:
Y: 5
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-cost
Label@COST:
Expand All @@ -123,6 +124,7 @@ Background@PRODUCTION_TOOLTIP:
X: 3
Y: 24
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-time
Label@TIME:
Expand All @@ -132,6 +134,7 @@ Background@PRODUCTION_TOOLTIP:
Image@POWER_ICON:
Y: 44
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-power
Label@POWER:
Expand Down
11 changes: 7 additions & 4 deletions mods/common/chrome/tooltips.yaml
Expand Up @@ -246,19 +246,20 @@ Background@PRODUCTION_TOOLTIP:
Font: Bold
Label@REQUIRES:
X: 7
Y: 21
Height: 23
Y: 25
Height: 15
Font: TinyBold
Text: Requires {0}
Label@DESC:
X: 7
Y: 41
Height: 23
Y: 25
Height: 2
Font: TinyBold
VAlign: Top
Image@COST_ICON:
Y: 5
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-cost
Label@COST:
Expand All @@ -268,6 +269,7 @@ Background@PRODUCTION_TOOLTIP:
X: 3
Y: 26
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-time
Label@TIME:
Expand All @@ -277,6 +279,7 @@ Background@PRODUCTION_TOOLTIP:
Image@POWER_ICON:
Y: 46
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-power
Label@POWER:
Expand Down
9 changes: 6 additions & 3 deletions mods/d2k/chrome/tooltips.yaml
Expand Up @@ -250,18 +250,19 @@ Background@PRODUCTION_TOOLTIP:
Label@REQUIRES:
X: 7
Y: 21
Height: 23
Height: 15
Font: TinyBold
Text: Requires {0}
Label@DESC:
X: 7
Y: 41
Height: 23
Y: 21
Height: 5
Font: TinyBold
VAlign: Top
Image@COST_ICON:
Y: 5
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-cost
Label@COST:
Expand All @@ -271,6 +272,7 @@ Background@PRODUCTION_TOOLTIP:
X: 3
Y: 26
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-time
Label@TIME:
Expand All @@ -280,6 +282,7 @@ Background@PRODUCTION_TOOLTIP:
Image@POWER_ICON:
Y: 46
Width: 16
Height: 16
ImageCollection: sidebar-bits
ImageName: production-tooltip-power
Label@POWER:
Expand Down

0 comments on commit be1158e

Please sign in to comment.