diff --git a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs index 0002b84ede..44cdc31dd9 100644 --- a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs @@ -188,7 +188,7 @@ namespace OpenRA.Mods.Common.Widgets return; tooltipContainer.Value.SetTooltip(TooltipTemplate, - new WidgetArgs { { "button", this } }); + new WidgetArgs { { "button", this }, { "getText", GetTooltipText } }); } public override void MouseExited() diff --git a/OpenRA.Mods.Common/Widgets/Logic/SimpleTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SimpleTooltipLogic.cs index f2dfe416da..6cb8ab6213 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SimpleTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SimpleTooltipLogic.cs @@ -20,33 +20,42 @@ namespace OpenRA.Mods.Common.Widgets.Logic public SimpleTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, Func getText) { var label = widget.Get("LABEL"); + var spacing = widget.Get("LINE_HEIGHT"); + widget.RemoveChildren(); var font = Game.Renderer.Fonts[label.Font]; - var cachedWidth = 0; - var cachedHeight = 0; var horizontalPadding = label.Bounds.Width - widget.Bounds.Width; if (horizontalPadding <= 0) horizontalPadding = 2 * label.Bounds.X; - var vertcalPadding = widget.Bounds.Height - label.Bounds.Height; - if (vertcalPadding <= 0) - vertcalPadding = 2 * label.Bounds.Y; - var labelText = ""; + + var cachedText = ""; tooltipContainer.BeforeRender = () => { - labelText = getText(); - var textDim = font.Measure(labelText); - if (textDim.X != cachedWidth || textDim.Y != cachedHeight) - { - label.Bounds.Width = textDim.X; - widget.Bounds.Width = horizontalPadding + textDim.X; - label.Bounds.Height = textDim.Y; - widget.Bounds.Height = vertcalPadding + textDim.Y; - cachedWidth = textDim.X; - cachedHeight = textDim.Y; - } - }; + var text = getText(); + if (text == cachedText) + return; - label.GetText = () => labelText; + var lines = text.Split('\n'); + var textWidth = font.Measure(text).X; + + // Set up label widgets + widget.RemoveChildren(); + var bottom = 0; + for (var i = 0; i < lines.Length; i++) + { + var line = (LabelWidget)label.Clone(); + var lineText = lines[i]; + line.Bounds.Y += spacing.Bounds.Y + i * spacing.Bounds.Height; + line.Bounds.Width = textWidth; + line.GetText = () => lineText; + widget.AddChild(line); + bottom = line.Bounds.Y + line.Bounds.Height; + } + + widget.Bounds.Width = horizontalPadding + textWidth; + widget.Bounds.Height = bottom + spacing.Bounds.Y; + cachedText = text; + }; } } } \ No newline at end of file diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index 6da45a9ad9..4b4738fc74 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -315,7 +315,7 @@ Container@EDITOR_WORLD_ROOT: Visible: false Width: PARENT_RIGHT - 35 TooltipContainer: TOOLTIP_CONTAINER - TooltipTemplate: TWO_LINE_TOOLTIP + TooltipTemplate: SIMPLE_TOOLTIP IgnoreChildMouseOver: true Children: ActorPreview@ACTOR_PREVIEW: diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index 42552ab46d..4fabf0de10 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -3,23 +3,12 @@ Background@SIMPLE_TOOLTIP: Background: panel-black Height: 27 Children: + Container@LINE_HEIGHT: + Y: 2 + Height: 19 Label@LABEL: X: 5 - Height: 23 - Font: Bold - -Background@TWO_LINE_TOOLTIP: - Logic: ButtonTooltipLogic - Background: panel-black - Height: 48 - Children: - Label@LABEL: - X: 5 - Height: 46 - Font: Bold - Label@HOTKEY: - Visible: false - TextColor: FFFF00 + Y: 0-2 Height: 23 Font: Bold diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml index a010eb01b8..206c5685bd 100644 --- a/mods/d2k/chrome/tooltips.yaml +++ b/mods/d2k/chrome/tooltips.yaml @@ -3,29 +3,15 @@ Background@SIMPLE_TOOLTIP: Background: dialog3 Height: 34 Children: + Container@LINE_HEIGHT: + Y: 5 + Height: 19 Label@LABEL: X: 5 - Y: 3 + Y: 0-2 Height: 23 Font: Bold -Background@TWO_LINE_TOOLTIP: - Logic: ButtonTooltipLogic - Background: dialog3 - Height: 54 - Children: - Label@LABEL: - X: 5 - Y: 3 - Height: 46 - Font: Bold - Label@HOTKEY: - Visible: false - Y: 3 - Height: 23 - TextColor: FFFF00 - Font: Bold - Background@BUTTON_TOOLTIP: Logic: ButtonTooltipLogic Background: dialog3 diff --git a/mods/ra/chrome/editor.yaml b/mods/ra/chrome/editor.yaml index 9cb9d32a56..025f7a912e 100644 --- a/mods/ra/chrome/editor.yaml +++ b/mods/ra/chrome/editor.yaml @@ -294,7 +294,7 @@ Container@EDITOR_WORLD_ROOT: Visible: false Width: PARENT_RIGHT - 35 TooltipContainer: TOOLTIP_CONTAINER - TooltipTemplate: TWO_LINE_TOOLTIP + TooltipTemplate: SIMPLE_TOOLTIP IgnoreChildMouseOver: true Children: ActorPreview@ACTOR_PREVIEW: diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml index 74f528f7d7..005131f449 100644 --- a/mods/ra/chrome/tooltips.yaml +++ b/mods/ra/chrome/tooltips.yaml @@ -3,29 +3,15 @@ Background@SIMPLE_TOOLTIP: Background: dialog4 Height: 32 Children: + Container@LINE_HEIGHT: + Y: 3 + Height: 19 Label@LABEL: X: 7 - Y: 2 + Y: 0-1 Height: 23 Font: Bold -Background@TWO_LINE_TOOLTIP: - Logic: ButtonTooltipLogic - Background: dialog4 - Height: 52 - Children: - Label@LABEL: - X: 7 - Y: 2 - Height: 46 - Font: Bold - Label@HOTKEY: - Visible: false - Y: 2 - Height: 23 - TextColor: FFFF00 - Font: Bold - Background@BUTTON_TOOLTIP: Logic: ButtonTooltipLogic Background: dialog4