From 13f5ef50b93f920230ff56e8ea1b3d7ad3402e4c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 5 Dec 2018 21:54:14 +0000 Subject: [PATCH] Fix production tooltip padding. --- .../Logic/Ingame/ProductionTooltipLogic.cs | 30 +++++++++++++++---- mods/cnc/chrome/tooltips.yaml | 9 ++++-- mods/common/chrome/tooltips.yaml | 11 ++++--- mods/d2k/chrome/tooltips.yaml | 9 ++++-- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs index 75e061bf0b..39df0e61d9 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs @@ -50,6 +50,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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 = () => { @@ -88,8 +90,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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) @@ -116,6 +130,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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); @@ -124,9 +140,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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; diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index 3cd8a9985f..ea8b451824 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -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: @@ -123,6 +124,7 @@ Background@PRODUCTION_TOOLTIP: X: 3 Y: 24 Width: 16 + Height: 16 ImageCollection: sidebar-bits ImageName: production-tooltip-time Label@TIME: @@ -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: diff --git a/mods/common/chrome/tooltips.yaml b/mods/common/chrome/tooltips.yaml index aeff05d379..0fae9cd17e 100644 --- a/mods/common/chrome/tooltips.yaml +++ b/mods/common/chrome/tooltips.yaml @@ -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: @@ -268,6 +269,7 @@ Background@PRODUCTION_TOOLTIP: X: 3 Y: 26 Width: 16 + Height: 16 ImageCollection: sidebar-bits ImageName: production-tooltip-time Label@TIME: @@ -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: diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml index 91ec038be5..00c544aedc 100644 --- a/mods/d2k/chrome/tooltips.yaml +++ b/mods/d2k/chrome/tooltips.yaml @@ -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: @@ -271,6 +272,7 @@ Background@PRODUCTION_TOOLTIP: X: 3 Y: 26 Width: 16 + Height: 16 ImageCollection: sidebar-bits ImageName: production-tooltip-time Label@TIME: @@ -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: