From 90468974ce611e2ee973cdecf7a573bc930dc905 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 29 May 2016 00:36:14 +0100 Subject: [PATCH] Add tooltip support to ImageWidget. --- OpenRA.Mods.Common/Widgets/ImageWidget.cs | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/OpenRA.Mods.Common/Widgets/ImageWidget.cs b/OpenRA.Mods.Common/Widgets/ImageWidget.cs index ace095e384..2838ee6055 100644 --- a/OpenRA.Mods.Common/Widgets/ImageWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ImageWidget.cs @@ -17,16 +17,27 @@ namespace OpenRA.Mods.Common.Widgets { public class ImageWidget : Widget { + public readonly string TooltipTemplate; + public readonly string TooltipContainer; + public string ImageCollection = ""; public string ImageName = ""; public bool ClickThrough = true; public Func GetImageName; public Func GetImageCollection; + [Translate] public string TooltipText; + + Lazy tooltipContainer; + public Func GetTooltipText; + public ImageWidget() { GetImageName = () => ImageName; GetImageCollection = () => ImageCollection; + GetTooltipText = () => TooltipText; + tooltipContainer = Exts.Lazy(() => + Ui.Root.Get(TooltipContainer)); } protected ImageWidget(ImageWidget other) @@ -37,6 +48,12 @@ namespace OpenRA.Mods.Common.Widgets GetImageName = other.GetImageName; ImageCollection = other.ImageCollection; GetImageCollection = other.GetImageCollection; + + TooltipTemplate = other.TooltipTemplate; + TooltipContainer = other.TooltipContainer; + GetTooltipText = other.GetTooltipText; + tooltipContainer = Exts.Lazy(() => + Ui.Root.Get(TooltipContainer)); } public override Widget Clone() { return new ImageWidget(this); } @@ -57,5 +74,21 @@ namespace OpenRA.Mods.Common.Widgets { return !ClickThrough && RenderBounds.Contains(mi.Location); } + + public override void MouseEntered() + { + if (TooltipContainer == null || GetTooltipText == null) + return; + + tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() { { "getText", GetTooltipText } }); + } + + public override void MouseExited() + { + if (TooltipContainer == null) + return; + + tooltipContainer.Value.RemoveTooltip(); + } } }