Fix production tooltip padding.

This commit is contained in:
Paul Chote
2018-12-05 21:54:14 +00:00
committed by reaperrr
parent 3e7caa2faa
commit 13f5ef50b9
4 changed files with 44 additions and 15 deletions

View File

@@ -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;

View File

@@ -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:

View File

@@ -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:

View File

@@ -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: