diff --git a/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs b/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs index ffcc55d8a9..7cdbd04a32 100644 --- a/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs @@ -28,20 +28,38 @@ namespace OpenRA.Mods.Common.Widgets Widget tooltip; int nextToken = 1; int currentToken; + string id; + WidgetArgs widgetArgs; public TooltipContainerWidget() { graphicSettings = Game.Settings.Graphics; - IsVisible = () => Game.RunTime > Viewport.LastMoveRunTime + TooltipDelayMilliseconds; + IsVisible = () => + { + // PERF: Only load widget once visible. + var visible = Game.RunTime > Viewport.LastMoveRunTime + TooltipDelayMilliseconds; + if (visible) + LoadWidget(); + + return visible; + }; + } + + void LoadWidget() + { + if (id == null || tooltip != null) + return; + + tooltip = Ui.LoadWidget(id, this, new WidgetArgs(widgetArgs) { { "tooltipContainer", this } }); } public int SetTooltip(string id, WidgetArgs args) { RemoveTooltip(); currentToken = nextToken++; - - tooltip = Ui.LoadWidget(id, this, new WidgetArgs(args) { { "tooltipContainer", this } }); - + tooltip = null; + this.id = id; + widgetArgs = args; return currentToken; } @@ -50,6 +68,10 @@ namespace OpenRA.Mods.Common.Widgets if (currentToken != token) return; + tooltip = null; + id = null; + widgetArgs = null; + RemoveChildren(); BeforeRender = Nothing; } @@ -59,7 +81,10 @@ namespace OpenRA.Mods.Common.Widgets RemoveTooltip(currentToken); } - public override void Draw() { BeforeRender(); } + public override void Draw() + { + BeforeRender(); + } public override bool EventBoundsContains(int2 location) { return false; }