factored out flying unit render into WithShadow:IRenderModifier

This commit is contained in:
Chris Forbes
2009-12-21 18:13:52 +13:00
parent 994266d95f
commit dbe962364b
7 changed files with 33 additions and 61 deletions

View File

@@ -42,16 +42,10 @@ namespace OpenRa.Game.Graphics
PlayThen( sequenceName, () => PlayRepeating( sequenceName ) ); PlayThen( sequenceName, () => PlayRepeating( sequenceName ) );
} }
public void PlayRepeatingPreservingPosition(string sequenceName)
{
var f = frame;
PlayThen(sequenceName, () => PlayRepeating(sequenceName));
frame = f % CurrentSequence.Length;
}
public void ReplaceAnim(string sequenceName) public void ReplaceAnim(string sequenceName)
{ {
CurrentSequence = SequenceProvider.GetSequence(name, sequenceName); CurrentSequence = SequenceProvider.GetSequence(name, sequenceName);
frame %= CurrentSequence.Length;
} }
public void PlayThen( string sequenceName, Action after ) public void PlayThen( string sequenceName, Action after )

View File

@@ -186,7 +186,6 @@
<Compile Include="Traits\Cloak.cs" /> <Compile Include="Traits\Cloak.cs" />
<Compile Include="Traits\RenderUnit.cs" /> <Compile Include="Traits\RenderUnit.cs" />
<Compile Include="Traits\RenderUnitMuzzleFlash.cs" /> <Compile Include="Traits\RenderUnitMuzzleFlash.cs" />
<Compile Include="Traits\RenderUnitPlane.cs" />
<Compile Include="Traits\RenderUnitReload.cs" /> <Compile Include="Traits\RenderUnitReload.cs" />
<Compile Include="Traits\RenderUnitRotor.cs" /> <Compile Include="Traits\RenderUnitRotor.cs" />
<Compile Include="Traits\RenderUnitSpinner.cs" /> <Compile Include="Traits\RenderUnitSpinner.cs" />
@@ -198,6 +197,7 @@
<Compile Include="Traits\Tree.cs" /> <Compile Include="Traits\Tree.cs" />
<Compile Include="Traits\Turreted.cs" /> <Compile Include="Traits\Turreted.cs" />
<Compile Include="Traits\Unit.cs" /> <Compile Include="Traits\Unit.cs" />
<Compile Include="Traits\WithShadow.cs" />
<Compile Include="UnitOrders.cs" /> <Compile Include="UnitOrders.cs" />
<Compile Include="Traits\Util.cs" /> <Compile Include="Traits\Util.cs" />
<Compile Include="UiOverlay.cs" /> <Compile Include="UiOverlay.cs" />

View File

@@ -173,9 +173,6 @@ namespace OpenRa.Game.Traits.Activities
w2 = c2 + f; w2 = c2 + f;
w3 = approachStart; w3 = approachStart;
landPoint = landPos; landPoint = landPos;
var rup = self.traits.Get<RenderUnitPlane>();
rup.wps = new[] { self.CenterLocation, w1, w2, w3, landPoint, c1, c2 };
} }
public IActivity Tick(Actor self) public IActivity Tick(Actor self)

View File

@@ -1,31 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.Graphics;
using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits
{
class RenderUnitPlane : RenderUnit
{
Animation debug = new Animation("litning");
public float2[] wps;
public RenderUnitPlane(Actor self)
: base(self) { debug.PlayRepeating("bright"); debug.Tick(); }
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)
{
var unit = self.traits.Get<Unit>();
yield return Util.CenteredShadow(self, anim.Image, self.CenterLocation);
var p = self.CenterLocation - new float2(0, unit.Altitude);
yield return Util.Centered(self, anim.Image, p);
if (wps != null)
foreach (var w in wps)
yield return Tuple.New(debug.Image, w - .5f * debug.Image.size, 0);
}
}
}

View File

@@ -24,20 +24,11 @@ namespace OpenRa.Game.Traits
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
yield return Util.CenteredShadow(self, anim.Image, self.CenterLocation); yield return Util.Centered(self, anim.Image, self.CenterLocation);
yield return Util.CenteredShadow(self, rotorAnim.Image, self.CenterLocation yield return Util.Centered(self, rotorAnim.Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, 0));
if (self.Info.SecondaryOffset != null)
yield return Util.CenteredShadow(self, (secondRotorAnim ?? rotorAnim).Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.Info.SecondaryOffset, 0));
var p = self.CenterLocation - new float2( 0, unit.Altitude );
yield return Util.Centered(self, anim.Image, p);
yield return Util.Centered(self, rotorAnim.Image, p
+ Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, 0 ) ); + Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, 0 ) );
if (self.Info.SecondaryOffset != null) if (self.Info.SecondaryOffset != null)
yield return Util.Centered(self, (secondRotorAnim ?? rotorAnim).Image, p yield return Util.Centered(self, (secondRotorAnim ?? rotorAnim).Image, self.CenterLocation
+ Util.GetTurretPosition( self, unit, self.Info.SecondaryOffset, 0 ) ); + Util.GetTurretPosition( self, unit, self.Info.SecondaryOffset, 0 ) );
} }
@@ -55,9 +46,9 @@ namespace OpenRa.Game.Traits
if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor")) if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor"))
return; return;
rotorAnim.PlayRepeatingPreservingPosition(isFlying ? "rotor" : "slow-rotor"); rotorAnim.ReplaceAnim(isFlying ? "rotor" : "slow-rotor");
if (secondRotorAnim != null) if (secondRotorAnim != null)
secondRotorAnim.PlayRepeatingPreservingPosition(isFlying ? "rotor2" : "slow-rotor2"); secondRotorAnim.ReplaceAnim(isFlying ? "rotor2" : "slow-rotor2");
} }
} }
} }

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits
{
class WithShadow : IRenderModifier
{
public WithShadow(Actor self) {}
public IEnumerable<Tuple<Sprite, float2, int>> ModifyRender(Actor self, IEnumerable<Tuple<Sprite, float2, int>> r)
{
var unit = self.traits.Get<Unit>();
var shadowSprites = r.Select( a => Tuple.New( a.a, a.b, 8 ));
var flyingSprites = r.Select( a => Tuple.New( a.a, a.b - new float2( 0, unit.Altitude ), a.c ));
return shadowSprites.Concat(flyingSprites);
}
}
}

View File

@@ -155,13 +155,13 @@ HIND
[MIG] [MIG]
Description=Mig Attack Plane Description=Mig Attack Plane
BuiltAt=afld BuiltAt=afld
Traits=Unit, Plane, RenderUnitPlane Traits=Unit, Plane, RenderUnit, WithShadow
InitialFacing=192 InitialFacing=192
LongDesc=Fast Ground-Attack Plane.\n Strong vs Buildings\n Weak vs Infantry, Light Vehicles LongDesc=Fast Ground-Attack Plane.\n Strong vs Buildings\n Weak vs Infantry, Light Vehicles
[YAK] [YAK]
Description=Yak Attack Plane Description=Yak Attack Plane
BuiltAt=afld BuiltAt=afld
Traits=Unit, Plane, RenderUnitPlane Traits=Unit, Plane, RenderUnit, WithShadow
InitialFacing=192 InitialFacing=192
LongDesc=Anti-Tanks & Anti-Infantry Plane.\n Strong vs Infantry, Tanks\n Weak vs Buildings LongDesc=Anti-Tanks & Anti-Infantry Plane.\n Strong vs Infantry, Tanks\n Weak vs Buildings
[TRAN] [TRAN]
@@ -169,21 +169,21 @@ Description=Transport Helicopter
PrimaryOffset=0,14,0,-4 PrimaryOffset=0,14,0,-4
SecondaryOffset=0,-14,0,-2 SecondaryOffset=0,-14,0,-2
BuiltAt=hpad BuiltAt=hpad
Traits=Unit, Helicopter, RenderUnitRotor Traits=Unit, Helicopter, RenderUnitRotor, WithShadow
SecondaryAnim=rotor2 SecondaryAnim=rotor2
InitialFacing=20 InitialFacing=20
LongDesc=Fast Infantry Transport Helicopter.\n Unarmed LongDesc=Fast Infantry Transport Helicopter.\n Unarmed
[HELI] [HELI]
Description=Longbow Description=Longbow
BuiltAt=hpad BuiltAt=hpad
Traits=Unit, Helicopter, RenderUnitRotor Traits=Unit, Helicopter, RenderUnitRotor, WithShadow
PrimaryOffset=0,0,0,-2 PrimaryOffset=0,0,0,-2
InitialFacing=20 InitialFacing=20
LongDesc=Helicopter Gunship with AG Missiles.\n Strong vs Buildings, Tanks\n Weak vs Infantry LongDesc=Helicopter Gunship with AG Missiles.\n Strong vs Buildings, Tanks\n Weak vs Infantry
[HIND] [HIND]
Description=Hind Description=Hind
BuiltAt=hpad BuiltAt=hpad
Traits=Unit, Helicopter, RenderUnitRotor Traits=Unit, Helicopter, RenderUnitRotor, WithShadow
InitialFacing=20 InitialFacing=20
LongDesc=Helicopter Gunship with Chainguns.\n Strong vs Infantry, Light Vehicles.\n Weak vs Tanks LongDesc=Helicopter Gunship with Chainguns.\n Strong vs Infantry, Light Vehicles.\n Weak vs Tanks