Kill RenderUnitRotor in favour of RenderUnit + WithRotor.
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class RenderUnitRotorInfo : RenderUnitInfo
|
||||
{
|
||||
public readonly int[] PrimaryOffset = { 0, 0 };
|
||||
public readonly int[] SecondaryOffset = null;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new RenderUnitRotor(init.self); }
|
||||
}
|
||||
|
||||
class RenderUnitRotor : RenderUnit
|
||||
{
|
||||
public Animation rotorAnim, secondRotorAnim;
|
||||
|
||||
public RenderUnitRotor( Actor self )
|
||||
: base(self)
|
||||
{
|
||||
var facing = self.Trait<IFacing>();
|
||||
var info = self.Info.Traits.Get<RenderUnitRotorInfo>();
|
||||
|
||||
rotorAnim = new Animation(GetImage(self));
|
||||
rotorAnim.PlayRepeating("rotor");
|
||||
anims.Add("rotor_1", new AnimationWithOffset(
|
||||
rotorAnim,
|
||||
() => Combat.GetTurretPosition( self, facing, new Turret(info.PrimaryOffset)),
|
||||
null ) { ZOffset = 1 } );
|
||||
|
||||
if (info.SecondaryOffset == null) return;
|
||||
|
||||
secondRotorAnim = new Animation(GetImage(self));
|
||||
secondRotorAnim.PlayRepeating("rotor2");
|
||||
anims.Add("rotor_2", new AnimationWithOffset(
|
||||
secondRotorAnim,
|
||||
() => Combat.GetTurretPosition(self, facing, new Turret(info.SecondaryOffset)),
|
||||
null) { ZOffset = 1 });
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
|
||||
var isFlying = self.Trait<IMove>().Altitude > 0 && !self.IsDead();
|
||||
if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor"))
|
||||
return;
|
||||
|
||||
rotorAnim.ReplaceAnim(isFlying ? "rotor" : "slow-rotor");
|
||||
if (secondRotorAnim != null)
|
||||
secondRotorAnim.ReplaceAnim(isFlying ? "rotor2" : "slow-rotor2");
|
||||
}
|
||||
}
|
||||
}
|
||||
55
OpenRA.Mods.RA/Render/WithMuzzleFlash.cs
Normal file
55
OpenRA.Mods.RA/Render/WithMuzzleFlash.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class WithMuzzleFlashInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo>
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); }
|
||||
}
|
||||
|
||||
class WithMuzzleFlash : INotifyAttack
|
||||
{
|
||||
List<Animation> muzzleFlashes = new List<Animation>();
|
||||
bool isShowing;
|
||||
|
||||
public WithMuzzleFlash(Actor self)
|
||||
{
|
||||
var attack = self.Trait<AttackBase>();
|
||||
var render = self.Trait<RenderSimple>();
|
||||
var facing = self.Trait<IFacing>();
|
||||
|
||||
foreach (var t in attack.Turrets)
|
||||
{
|
||||
var turret = t;
|
||||
var muzzleFlash = new Animation(render.GetImage(self), () => self.Trait<IFacing>().Facing);
|
||||
muzzleFlash.Play("muzzle");
|
||||
|
||||
render.anims.Add("muzzle{0}".F(muzzleFlashes.Count), new RenderSimple.AnimationWithOffset(
|
||||
muzzleFlash,
|
||||
() => Combat.GetTurretPosition(self, facing, turret),
|
||||
() => !isShowing));
|
||||
|
||||
muzzleFlashes.Add(muzzleFlash);
|
||||
}
|
||||
}
|
||||
|
||||
public void Attacking(Actor self, Target target)
|
||||
{
|
||||
isShowing = true;
|
||||
foreach( var mf in muzzleFlashes )
|
||||
mf.PlayThen("muzzle", () => isShowing = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
48
OpenRA.Mods.RA/Render/WithRotor.cs
Executable file
48
OpenRA.Mods.RA/Render/WithRotor.cs
Executable file
@@ -0,0 +1,48 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class WithRotorInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Id = "rotor";
|
||||
public readonly int[] Offset = { 0, 0 };
|
||||
public object Create(ActorInitializer init) { return new WithRotor(init.self, this); }
|
||||
}
|
||||
|
||||
public class WithRotor : ITick
|
||||
{
|
||||
public Animation rotorAnim;
|
||||
public WithRotor(Actor self, WithRotorInfo info)
|
||||
{
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var facing = self.Trait<IFacing>();
|
||||
|
||||
rotorAnim = new Animation(rs.GetImage(self));
|
||||
rotorAnim.PlayRepeating("rotor");
|
||||
rs.anims.Add(info.Id, new RenderSimple.AnimationWithOffset(
|
||||
rotorAnim,
|
||||
() => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)),
|
||||
null ) { ZOffset = 1 } );
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
var isFlying = self.Trait<IMove>().Altitude > 0 && !self.IsDead();
|
||||
if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor"))
|
||||
return;
|
||||
|
||||
rotorAnim.ReplaceAnim(isFlying ? "rotor" : "slow-rotor");
|
||||
}
|
||||
}
|
||||
}
|
||||
32
OpenRA.Mods.RA/Render/WithShadow.cs
Normal file
32
OpenRA.Mods.RA/Render/WithShadow.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class WithShadowInfo : TraitInfo<WithShadow> {}
|
||||
|
||||
class WithShadow : IRenderModifier
|
||||
{
|
||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||
{
|
||||
var move = self.Trait<IMove>();
|
||||
|
||||
var shadowSprites = r.Select(a => a.WithPalette("shadow"));
|
||||
var flyingSprites = (move.Altitude <= 0) ? r
|
||||
: r.Select(a => a.WithPos(a.Pos - new float2(0, move.Altitude)).WithZOffset(move.Altitude));
|
||||
|
||||
return shadowSprites.Concat(flyingSprites);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user