diff --git a/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs b/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs index c45cc73673..5ffaad8823 100644 --- a/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs @@ -16,43 +16,45 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render { [Desc("Display the time remaining until the super weapon attached to the actor is ready.")] - class SupportPowerChargeBarInfo : ITraitInfo + class SupportPowerChargeBarInfo : ConditionalTraitInfo { [Desc("Defines to which players the bar is to be shown.")] public readonly Stance DisplayStances = Stance.Ally; public readonly Color Color = Color.Magenta; - public object Create(ActorInitializer init) { return new SupportPowerChargeBar(init.Self, this); } + public override object Create(ActorInitializer init) { return new SupportPowerChargeBar(init.Self, this); } } - class SupportPowerChargeBar : ISelectionBar, INotifyOwnerChanged + class SupportPowerChargeBar : ConditionalTrait, ISelectionBar, INotifyOwnerChanged { readonly Actor self; - readonly SupportPowerChargeBarInfo info; SupportPowerManager spm; public SupportPowerChargeBar(Actor self, SupportPowerChargeBarInfo info) + : base(info) { this.self = self; - this.info = info; spm = self.Owner.PlayerActor.Trait(); } float ISelectionBar.GetValue() { + if (IsTraitDisabled) + return 0; + var power = spm.GetPowersForActor(self).FirstOrDefault(sp => !sp.Disabled); if (power == null) return 0; var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer; - if (viewer != null && !info.DisplayStances.HasStance(self.Owner.Stances[viewer])) + if (viewer != null && !Info.DisplayStances.HasStance(self.Owner.Stances[viewer])) return 0; return 1 - (float)power.RemainingTime / power.TotalTime; } - Color ISelectionBar.GetColor() { return info.Color; } + Color ISelectionBar.GetColor() { return Info.Color; } bool ISelectionBar.DisplayWhenEmpty { get { return false; } } void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs index b8f261db08..b648b6a769 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs @@ -124,7 +124,8 @@ namespace OpenRA.Mods.Common.Traits return NoInstances; return a.TraitsImplementing() - .Select(t => Powers[MakeKey(t)]); + .Select(t => Powers[MakeKey(t)]) + .Where(p => p.Instances.Any(i => !i.IsTraitDisabled && i.Self == a)); } public void PrerequisitesAvailable(string key)