Add tooltip support to ImageWidget.
This commit is contained in:
@@ -17,16 +17,27 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
public class ImageWidget : Widget
|
public class ImageWidget : Widget
|
||||||
{
|
{
|
||||||
|
public readonly string TooltipTemplate;
|
||||||
|
public readonly string TooltipContainer;
|
||||||
|
|
||||||
public string ImageCollection = "";
|
public string ImageCollection = "";
|
||||||
public string ImageName = "";
|
public string ImageName = "";
|
||||||
public bool ClickThrough = true;
|
public bool ClickThrough = true;
|
||||||
public Func<string> GetImageName;
|
public Func<string> GetImageName;
|
||||||
public Func<string> GetImageCollection;
|
public Func<string> GetImageCollection;
|
||||||
|
|
||||||
|
[Translate] public string TooltipText;
|
||||||
|
|
||||||
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
|
public Func<string> GetTooltipText;
|
||||||
|
|
||||||
public ImageWidget()
|
public ImageWidget()
|
||||||
{
|
{
|
||||||
GetImageName = () => ImageName;
|
GetImageName = () => ImageName;
|
||||||
GetImageCollection = () => ImageCollection;
|
GetImageCollection = () => ImageCollection;
|
||||||
|
GetTooltipText = () => TooltipText;
|
||||||
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ImageWidget(ImageWidget other)
|
protected ImageWidget(ImageWidget other)
|
||||||
@@ -37,6 +48,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
GetImageName = other.GetImageName;
|
GetImageName = other.GetImageName;
|
||||||
ImageCollection = other.ImageCollection;
|
ImageCollection = other.ImageCollection;
|
||||||
GetImageCollection = other.GetImageCollection;
|
GetImageCollection = other.GetImageCollection;
|
||||||
|
|
||||||
|
TooltipTemplate = other.TooltipTemplate;
|
||||||
|
TooltipContainer = other.TooltipContainer;
|
||||||
|
GetTooltipText = other.GetTooltipText;
|
||||||
|
tooltipContainer = Exts.Lazy(() =>
|
||||||
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone() { return new ImageWidget(this); }
|
public override Widget Clone() { return new ImageWidget(this); }
|
||||||
@@ -57,5 +74,21 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
return !ClickThrough && RenderBounds.Contains(mi.Location);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user