Add upgrade support to WithMuzzleFlash.

This commit is contained in:
Paul Chote
2015-03-29 18:44:27 +01:00
parent ee12257d24
commit 42f3fa7439

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Renders the MuzzleSequence from the Armament trait.")] [Desc("Renders the MuzzleSequence from the Armament trait.")]
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo> class WithMuzzleFlashInfo : UpgradableTraitInfo, ITraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo>
{ {
[Desc("Ignore the weapon position, and always draw relative to the center of the actor")] [Desc("Ignore the weapon position, and always draw relative to the center of the actor")]
public readonly bool IgnoreOffset = false; public readonly bool IgnoreOffset = false;
@@ -25,13 +25,14 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.Self, this); } public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.Self, this); }
} }
class WithMuzzleFlash : INotifyAttack, IRender, ITick class WithMuzzleFlash : UpgradableTrait<WithMuzzleFlashInfo>, INotifyAttack, IRender, ITick
{ {
Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>(); Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>();
Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>(); Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();
Func<int> getFacing; Func<int> getFacing;
public WithMuzzleFlash(Actor self, WithMuzzleFlashInfo info) public WithMuzzleFlash(Actor self, WithMuzzleFlashInfo info)
: base(info)
{ {
var render = self.Trait<RenderSprites>(); var render = self.Trait<RenderSprites>();
var facing = self.TraitOrDefault<IFacing>(); var facing = self.TraitOrDefault<IFacing>();
@@ -64,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
anims.Add(barrel, anims.Add(barrel,
new AnimationWithOffset(muzzleFlash, new AnimationWithOffset(muzzleFlash,
() => info.IgnoreOffset ? WVec.Zero : armClosure.MuzzleOffset(self, barrel), () => info.IgnoreOffset ? WVec.Zero : armClosure.MuzzleOffset(self, barrel),
() => !visible[barrel], () => IsTraitDisabled || !visible[barrel],
() => false, () => false,
p => WithTurret.ZOffsetFromCenter(self, p, 2))); p => WithTurret.ZOffsetFromCenter(self, p, 2)));
} }