Cache SupportPowersWidget offsets at initialization

As well as overlay font.
This commit is contained in:
reaperrr
2020-08-15 21:12:18 +02:00
committed by abcdefg30
parent db9744ea7f
commit 36d5ae5421

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Widgets
Rectangle eventBounds;
public override Rectangle EventBounds { get { return eventBounds; } }
SpriteFont overlayFont;
float2 holdOffset, readyOffset, timeOffset;
float2 iconOffset, holdOffset, readyOffset, timeOffset;
[CustomLintableHotkeyNames]
public static IEnumerable<string> LinterHotkeyNames(MiniYamlNode widgetNode, Action<string> emitError, Action<string> emitWarning)
@@ -111,6 +111,10 @@ namespace OpenRA.Mods.Common.Widgets
i => modData.Hotkeys[HotkeyPrefix + (i + 1).ToString("D2")]);
overlayFont = Game.Renderer.Fonts[OverlayFont];
iconOffset = 0.5f * IconSize.ToFloat2() + IconSpriteOffset;
holdOffset = iconOffset - overlayFont.Measure(HoldText) / 2;
readyOffset = iconOffset - overlayFont.Measure(ReadyText) / 2;
}
public class SupportPowerIcon
@@ -194,10 +198,6 @@ namespace OpenRA.Mods.Common.Widgets
public override void Draw()
{
var iconOffset = 0.5f * IconSize.ToFloat2() + IconSpriteOffset;
holdOffset = iconOffset - overlayFont.Measure(HoldText) / 2;
readyOffset = iconOffset - overlayFont.Measure(ReadyText) / 2;
timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0, worldRenderer.World.Timestep)) / 2;
// Icons