Add support for button tooltip descriptions.
This commit is contained in:
@@ -54,6 +54,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
[Translate] public string TooltipText;
|
[Translate] public string TooltipText;
|
||||||
public Func<string> GetTooltipText;
|
public Func<string> GetTooltipText;
|
||||||
|
[Translate] public string TooltipDesc;
|
||||||
|
public Func<string> GetTooltipDesc;
|
||||||
|
|
||||||
// Equivalent to OnMouseUp, but without an input arg
|
// Equivalent to OnMouseUp, but without an input arg
|
||||||
public Action OnClick = () => { };
|
public Action OnClick = () => { };
|
||||||
@@ -77,6 +79,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
IsDisabled = () => Disabled;
|
IsDisabled = () => Disabled;
|
||||||
IsHighlighted = () => Highlighted;
|
IsHighlighted = () => Highlighted;
|
||||||
GetTooltipText = () => TooltipText;
|
GetTooltipText = () => TooltipText;
|
||||||
|
GetTooltipDesc = () => TooltipDesc;
|
||||||
tooltipContainer = Exts.Lazy(() =>
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
}
|
}
|
||||||
@@ -115,6 +118,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
TooltipTemplate = other.TooltipTemplate;
|
TooltipTemplate = other.TooltipTemplate;
|
||||||
TooltipText = other.TooltipText;
|
TooltipText = other.TooltipText;
|
||||||
GetTooltipText = other.GetTooltipText;
|
GetTooltipText = other.GetTooltipText;
|
||||||
|
TooltipDesc = other.TooltipDesc;
|
||||||
|
GetTooltipDesc = other.GetTooltipDesc;
|
||||||
TooltipContainer = other.TooltipContainer;
|
TooltipContainer = other.TooltipContainer;
|
||||||
tooltipContainer = Exts.Lazy(() =>
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
@@ -195,7 +200,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||||
new WidgetArgs { { "button", this }, { "getText", GetTooltipText } });
|
new WidgetArgs { { "button", this }, { "getText", GetTooltipText }, { "getDesc", GetTooltipDesc } });
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
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;
|
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