diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs index fe1773ba8f..0b64876631 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs @@ -8,6 +8,8 @@ */ #endregion +using System; +using OpenRA.Mods.RA; using OpenRA.Support; using OpenRA.Widgets; @@ -17,10 +19,38 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { [ObjectCreator.UseCtor] public SupportPowerTooltipLogic([ObjectCreator.Param] Widget widget, + [ObjectCreator.Param] TooltipContainerWidget tooltipContainer, [ObjectCreator.Param] SupportPowersWidget palette) { widget.IsVisible = () => palette.TooltipPower != null; - widget.GetWidget("NAME").GetText = () => palette.TooltipPower; + var nameLabel = widget.GetWidget("NAME"); + var timeLabel = widget.GetWidget("TIME"); + var nameFont = Game.Renderer.Fonts[nameLabel.Font]; + var timeFont = Game.Renderer.Fonts[timeLabel.Font]; + var name = ""; + var time = ""; + + SupportPowerManager.SupportPowerInstance lastPower = null; + tooltipContainer.BeforeRender = () => + { + var sp = palette.TooltipPower; + if (sp == null) + return; + + time = "{0} / {1}".F(WidgetUtils.FormatTime(sp.RemainingTime), + WidgetUtils.FormatTime(sp.Info.ChargeTime*25)); + + if (sp == lastPower) + return; + + name = sp.Info.Description; + widget.Bounds.Width = 2*nameLabel.Bounds.X + + Math.Max(nameFont.Measure(name).X, timeFont.Measure(time).X); + lastPower = sp; + }; + + nameLabel.GetText = () => name; + timeLabel.GetText = () => time; } } } diff --git a/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs b/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs index 7525a83dc0..bf06d12110 100755 --- a/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.Widgets public readonly string TooltipContainer; public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP"; - public string TooltipPower { get; private set; } + public SupportPowerManager.SupportPowerInstance TooltipPower { get; private set; } Lazy tooltipContainer; Rectangle eventBounds; @@ -136,8 +136,9 @@ namespace OpenRA.Mods.Cnc.Widgets { if (mi.Event == MouseInputEvent.Move) { - TooltipPower = Icons.Where(i => i.Key.Contains(mi.Location)) + var power = Icons.Where(i => i.Key.Contains(mi.Location)) .Select(i => i.Value).FirstOrDefault(); + TooltipPower = (power != null) ? spm.Powers[power] : null; return false; } diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index 6bdd32bd20..ee6b09fb42 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -69,11 +69,16 @@ Background@SUPPORT_POWER_TOOLTIP: Logic:SupportPowerTooltipLogic Background:panel-black Width:200 - Height:25 + Height:45 Children: Label@NAME: Id:NAME X:5 - Width:PARENT_RIGHT-10 + Height:23 + Font:Bold + Label@TIME: + Id:TIME + X:5 + Y:19 Height:23 Font:Bold \ No newline at end of file