From e8084daad7a6cd30d90f40691239747e85f6bd6a Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sun, 1 May 2016 13:56:40 +0200 Subject: [PATCH] Cache the SupportPowerManager in SupportPowerChargeBar --- .../Traits/Render/SupportPowerChargeBar.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs b/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs index e01c215e77..8297b1ff68 100644 --- a/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs @@ -26,22 +26,22 @@ namespace OpenRA.Mods.Common.Traits.Render public object Create(ActorInitializer init) { return new SupportPowerChargeBar(init.Self, this); } } - class SupportPowerChargeBar : ISelectionBar + class SupportPowerChargeBar : ISelectionBar, INotifyOwnerChanged { readonly Actor self; readonly SupportPowerChargeBarInfo info; + SupportPowerManager spm; public SupportPowerChargeBar(Actor self, SupportPowerChargeBarInfo info) { this.self = self; this.info = info; + spm = self.Owner.PlayerActor.Trait(); } float ISelectionBar.GetValue() { - var spm = self.Owner.PlayerActor.Trait(); var power = spm.GetPowersForActor(self).FirstOrDefault(sp => !sp.Disabled); - if (power == null) return 0; @@ -53,5 +53,10 @@ namespace OpenRA.Mods.Common.Traits.Render } Color ISelectionBar.GetColor() { return info.Color; } + + void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) + { + spm = newOwner.PlayerActor.Trait(); + } } }