RenderUnitTurreted ported

This commit is contained in:
Chris Forbes
2010-01-11 18:49:28 +13:00
parent 4b19f1dfe5
commit b94e5441dc
5 changed files with 20 additions and 14 deletions

View File

@@ -15,8 +15,7 @@ namespace OpenRa.Game.Effects
public Corpse(Actor fromActor, int death) public Corpse(Actor fromActor, int death)
{ {
var info = fromActor.Info.Traits.WithInterface<RenderSimpleInfo>().First(); anim = new Animation(fromActor.traits.WithInterface<RenderSimple>().FirstOrDefault().GetImage(fromActor));
anim = new Animation(info.Image ?? fromActor.Info.Name);
anim.PlayThen("die{0}".F(death + 1), anim.PlayThen("die{0}".F(death + 1),
() => Game.world.AddFrameEndTask(w => w.Remove(this))); () => Game.world.AddFrameEndTask(w => w.Remove(this)));

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.Graphics; using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
@@ -16,9 +17,14 @@ namespace OpenRa.Game.Traits
public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>(); public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
public Animation anim { get { return anims[ "" ].Animation; } } public Animation anim { get { return anims[ "" ].Animation; } }
public string GetImage(Actor self)
{
return self.Info.Traits.WithInterface<RenderSimpleInfo>().First().Image ?? self.Info.Name;
}
public RenderSimple(Actor self) public RenderSimple(Actor self)
{ {
anims.Add( "", new Animation( self.LegacyInfo.Image ?? self.LegacyInfo.Name ) ); anims.Add( "", new Animation( GetImage(self) ) );
} }
public virtual IEnumerable<Renderable> Render( Actor self ) public virtual IEnumerable<Renderable> Render( Actor self )

View File

@@ -20,7 +20,7 @@ namespace OpenRa.Game.Traits
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
var info = self.Info.Traits.Get<RenderUnitRotorInfo>(); var info = self.Info.Traits.Get<RenderUnitRotorInfo>();
rotorAnim = new Animation(info.Image ?? self.Info.Name); rotorAnim = new Animation(GetImage(self));
rotorAnim.PlayRepeating("rotor"); rotorAnim.PlayRepeating("rotor");
anims.Add( "rotor_1", new AnimationWithOffset( anims.Add( "rotor_1", new AnimationWithOffset(
rotorAnim, rotorAnim,
@@ -29,7 +29,7 @@ namespace OpenRa.Game.Traits
if (info.SecondaryOffset == null) return; if (info.SecondaryOffset == null) return;
secondRotorAnim = new Animation(info.Image ?? self.Info.Name); secondRotorAnim = new Animation(GetImage(self));
secondRotorAnim.PlayRepeating( "rotor2" ); secondRotorAnim.PlayRepeating( "rotor2" );
anims.Add( "rotor_2", new AnimationWithOffset( anims.Add( "rotor_2", new AnimationWithOffset(
secondRotorAnim, secondRotorAnim,

View File

@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
var info = self.Info.Traits.Get<RenderUnitSpinnerInfo>(); var info = self.Info.Traits.Get<RenderUnitSpinnerInfo>();
var spinnerAnim = new Animation( info.Image ?? self.Info.Name ); var spinnerAnim = new Animation( GetImage(self) );
spinnerAnim.PlayRepeating( "spinner" ); spinnerAnim.PlayRepeating( "spinner" );
anims.Add( "spinner", new AnimationWithOffset( anims.Add( "spinner", new AnimationWithOffset(
spinnerAnim, spinnerAnim,

View File

@@ -17,31 +17,32 @@ namespace OpenRa.Game.Traits
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
var turreted = self.traits.Get<Turreted>(); var turreted = self.traits.Get<Turreted>();
var attack = self.traits.WithInterface<AttackBase>().FirstOrDefault(); var attack = self.traits.WithInterface<AttackBase>().FirstOrDefault();
var attackInfo = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
var turretAnim = new Animation(self.LegacyInfo.Name); var turretAnim = new Animation(GetImage(self));
turretAnim.PlayFacing( "turret", () => turreted.turretFacing ); turretAnim.PlayFacing( "turret", () => turreted.turretFacing );
if( self.LegacyInfo.PrimaryOffset != null ) if( attackInfo.PrimaryOffset != null )
anims.Add("turret_1", new AnimationWithOffset( anims.Add("turret_1", new AnimationWithOffset(
turretAnim, turretAnim,
() => Util.GetTurretPosition(self, unit, self.LegacyInfo.PrimaryOffset, attack.primaryRecoil), () => Util.GetTurretPosition(self, unit, attackInfo.PrimaryOffset, attack.primaryRecoil),
null) { ZOffset = 1 }); null) { ZOffset = 1 });
if( self.LegacyInfo.SecondaryOffset != null ) if (attackInfo.SecondaryOffset != null)
anims.Add("turret_2", new AnimationWithOffset( anims.Add("turret_2", new AnimationWithOffset(
turretAnim, turretAnim,
() => Util.GetTurretPosition(self, unit, self.LegacyInfo.SecondaryOffset, attack.secondaryRecoil), () => Util.GetTurretPosition(self, unit, attackInfo.SecondaryOffset, attack.secondaryRecoil),
null) { ZOffset = 1 }); null) { ZOffset = 1 });
if( self.LegacyInfo.MuzzleFlash ) if( attackInfo.MuzzleFlash )
{ {
var muzzleFlash = new Animation( self.LegacyInfo.Name ); var muzzleFlash = new Animation( GetImage(self) );
muzzleFlash.PlayFetchIndex( "muzzle", muzzleFlash.PlayFetchIndex( "muzzle",
() => ( Util.QuantizeFacing( self.traits.Get<Turreted>().turretFacing, 8 ) ) * 6 () => ( Util.QuantizeFacing( self.traits.Get<Turreted>().turretFacing, 8 ) ) * 6
+ (int)( attack.primaryRecoil * 5.9f ) ); /* hack: recoil can be 1.0f, but don't overflow into next anim */ + (int)( attack.primaryRecoil * 5.9f ) ); /* hack: recoil can be 1.0f, but don't overflow into next anim */
anims.Add( "muzzle_flash", new AnimationWithOffset( anims.Add( "muzzle_flash", new AnimationWithOffset(
muzzleFlash, muzzleFlash,
() => Util.GetTurretPosition( self, unit, self.LegacyInfo.PrimaryOffset, attack.primaryRecoil ), () => Util.GetTurretPosition(self, unit, attackInfo.PrimaryOffset, attack.primaryRecoil),
() => attack.primaryRecoil <= 0 ) ); () => attack.primaryRecoil <= 0 ) );
} }
} }