Make SupportPowerChargeBar conditional

This commit is contained in:
Mustafa Alperen Seki
2018-01-14 13:17:33 +03:00
committed by abcdefg30
parent ce63dd33db
commit 99eedfd0e7
2 changed files with 11 additions and 8 deletions

View File

@@ -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<SupportPowerChargeBarInfo>, 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<SupportPowerManager>();
}
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)