Add support for button tooltip descriptions.
This commit is contained in:
@@ -54,6 +54,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
[Translate] public string TooltipText;
|
||||
public Func<string> GetTooltipText;
|
||||
[Translate] public string TooltipDesc;
|
||||
public Func<string> GetTooltipDesc;
|
||||
|
||||
// Equivalent to OnMouseUp, but without an input arg
|
||||
public Action OnClick = () => { };
|
||||
@@ -77,6 +79,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
IsDisabled = () => Disabled;
|
||||
IsHighlighted = () => Highlighted;
|
||||
GetTooltipText = () => TooltipText;
|
||||
GetTooltipDesc = () => TooltipDesc;
|
||||
tooltipContainer = Exts.Lazy(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
@@ -115,6 +118,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
TooltipTemplate = other.TooltipTemplate;
|
||||
TooltipText = other.TooltipText;
|
||||
GetTooltipText = other.GetTooltipText;
|
||||
TooltipDesc = other.TooltipDesc;
|
||||
GetTooltipDesc = other.GetTooltipDesc;
|
||||
TooltipContainer = other.TooltipContainer;
|
||||
tooltipContainer = Exts.Lazy(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
@@ -195,7 +200,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||
new WidgetArgs { { "button", this }, { "getText", GetTooltipText } });
|
||||
new WidgetArgs { { "button", this }, { "getText", GetTooltipText }, { "getDesc", GetTooltipDesc } });
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -38,6 +39,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
widget.Bounds.Width = hotkey.Bounds.X + label.Bounds.X + font.Measure(hotkeyLabel).X;
|
||||
}
|
||||
|
||||
var desc = button.GetTooltipDesc();
|
||||
if (!string.IsNullOrEmpty(desc))
|
||||
{
|
||||
var descTemplate = widget.Get<LabelWidget>("DESC");
|
||||
widget.RemoveChild(descTemplate);
|
||||
|
||||
var descFont = Game.Renderer.Fonts[descTemplate.Font];
|
||||
var descWidth = 0;
|
||||
var descOffset = descTemplate.Bounds.Y;
|
||||
foreach (var line in desc.Split(new[] { "\\n" }, StringSplitOptions.None))
|
||||
{
|
||||
descWidth = Math.Max(descWidth, descFont.Measure(line).X);
|
||||
var lineLabel = (LabelWidget)descTemplate.Clone();
|
||||
lineLabel.GetText = () => line;
|
||||
lineLabel.Bounds.Y = descOffset;
|
||||
widget.AddChild(lineLabel);
|
||||
descOffset += descTemplate.Bounds.Height;
|
||||
}
|
||||
|
||||
widget.Bounds.Width = Math.Max(widget.Bounds.Width, descTemplate.Bounds.X * 2 + descWidth);
|
||||
widget.Bounds.Height += descOffset - descTemplate.Bounds.Y + descTemplate.Bounds.X;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user