From 1fa90c04743755a1046c2046747ab258f0ef0c45 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 9 Oct 2018 19:28:02 +0100 Subject: [PATCH] Allow support powers to override the icon overlay/tooltip labels. --- .../Traits/SupportPowers/SupportPowerManager.cs | 17 ++++++++++------- .../Logic/Ingame/SupportPowerTooltipLogic.cs | 14 ++++++++++---- .../Widgets/SupportPowersWidget.cs | 10 +++++++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs index 22c129f842..19a7b7dc8e 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs @@ -105,13 +105,6 @@ namespace OpenRA.Mods.Common.Traits Powers[order.OrderString].Activate(order); } - // Deprecated. Remove after SupportPowerBinWidget is removed. - public void Target(string key) - { - if (Powers.ContainsKey(key)) - Powers[key].Target(); - } - static readonly SupportPowerInstance[] NoInstances = { }; public IEnumerable GetPowersForActor(Actor a) @@ -260,6 +253,16 @@ namespace OpenRA.Mods.Common.Traits oneShotFired = true; } } + + public virtual string IconOverlayTextOverride() + { + return null; + } + + public virtual string TooltipTimeTextOverride() + { + return null; + } } public class SelectGenericPowerTarget : OrderGenerator diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs index 73155902e5..698c4cd295 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs @@ -59,11 +59,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic descLabel.Text = sp.Info.LongDesc.Replace("\\n", "\n"); var descSize = descFont.Measure(descLabel.Text); - var remaining = WidgetUtils.FormatTime(sp.RemainingTicks, world.Timestep); - var total = WidgetUtils.FormatTime(sp.Info.ChargeInterval, world.Timestep); - timeLabel.Text = "{0} / {1}".F(remaining, total); - var timeSize = timeFont.Measure(timeLabel.Text); + var customLabel = sp.TooltipTimeTextOverride(); + if (customLabel == null) + { + var remaining = WidgetUtils.FormatTime(sp.RemainingTicks, world.Timestep); + var total = WidgetUtils.FormatTime(sp.Info.ChargeInterval, world.Timestep); + timeLabel.Text = "{0} / {1}".F(remaining, total); + } + else + timeLabel.Text = customLabel; + var timeSize = timeFont.Measure(timeLabel.Text); var hotkeyWidth = 0; hotkeyLabel.Visible = hotkey.IsValid(); if (hotkeyLabel.Visible) diff --git a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs index 3c32031da4..dc080fd7f4 100644 --- a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs +++ b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs @@ -215,7 +215,15 @@ namespace OpenRA.Mods.Common.Widgets // Overlay foreach (var p in icons.Values) { - if (p.Power.Ready) + var customText = p.Power.IconOverlayTextOverride(); + if (customText != null) + { + var customOffset = iconOffset - overlayFont.Measure(customText) / 2; + overlayFont.DrawTextWithContrast(customText, + p.Pos + customOffset, + Color.White, Color.Black, 1); + } + else if (p.Power.Ready) overlayFont.DrawTextWithContrast(ReadyText, p.Pos + readyOffset, Color.White, Color.Black, 1);