Overlay rendering

- also, sequences for HBOX and PBOX
This commit is contained in:
Bob
2009-10-10 21:23:33 +13:00
parent 4fa05a6d40
commit b880f7d1bc
10 changed files with 152 additions and 76 deletions

View File

@@ -21,7 +21,7 @@ namespace OpenRa.Game
public Actor( string name, int2 location, Player owner )
{
unitInfo = Rules.UnitInfo.Get( name );
Location = location;
Location = location;
CenterLocation = new float2( 12, 12 ) + 24 * (float2)Location;
Owner = owner;
@@ -90,11 +90,11 @@ namespace OpenRa.Game
case "ftur":
traits.Add( new Traits.Building( this ) );
traits.Add( new Traits.RenderBuilding( this ) );
break;
case "weap":
traits.Add( new Traits.Building( this ) );
traits.Add( new Traits.RenderWarFactory( this ) );
break;
break;
case "weap":
traits.Add( new Traits.Building( this ) );
traits.Add( new Traits.RenderWarFactory( this ) );
break;
case "gun":
case "agun":
case "sam":
@@ -117,8 +117,8 @@ namespace OpenRa.Game
{
foreach( var tick in traits.WithInterface<Traits.ITick>() )
tick.Tick( this, game, dt );
}
}
public float2 CenterLocation;
public float2 SelectedSize { get { return Render().FirstOrDefault().First.size; } }
@@ -191,45 +191,45 @@ namespace OpenRa.Game
{
anim.PlayThen( "make", () => anim.PlayFetchIndex( "idle", () => self.traits.Get<Turreted>().turretFacing ) );
}
}
class RenderWarFactory : RenderBuilding
{
public Animation roof;
bool doneBuilding;
public RenderWarFactory( Actor self )
: base( self )
{
roof = new Animation( self.unitInfo.Name );
anim.PlayThen( "make", () =>
{
doneBuilding = true;
anim.Play( "idle" );
roof.Play( "idle-top" );
} );
}
public override IEnumerable<Pair<Sprite, float2>> Render( Actor self )
{
yield return Pair.New( anim.Image, 24f * (float2)self.Location );
if( doneBuilding )
yield return Pair.New( roof.Image, 24f * (float2)self.Location );
}
public override void Tick( Actor self, Game game, int dt )
{
base.Tick( self, game, dt );
roof.Tick( dt );
}
}
class RenderWarFactory : RenderBuilding
{
public Animation roof;
bool doneBuilding;
public RenderWarFactory( Actor self )
: base( self )
{
roof = new Animation( self.unitInfo.Name );
anim.PlayThen( "make", () =>
{
doneBuilding = true;
anim.Play( "idle" );
roof.Play( "idle-top" );
} );
}
public override IEnumerable<Pair<Sprite, float2>> Render( Actor self )
{
yield return Pair.New( anim.Image, 24f * (float2)self.Location );
if( doneBuilding )
yield return Pair.New( roof.Image, 24f * (float2)self.Location );
}
public override void Tick( Actor self, Game game, int dt )
{
base.Tick( self, game, dt );
roof.Tick( dt );
}
}
class RenderUnit : RenderSimple
{
public RenderUnit( Actor self )
: base( self )
{
anim.PlayFetchIndex( "idle", () => self.traits.Get<Mobile>().facing );
{
public RenderUnit( Actor self )
: base( self )
{
anim.PlayFetchIndex( "idle", () => self.traits.Get<Mobile>().facing );
}
protected static Pair<Sprite, float2> Centered( Sprite s, float2 location )
@@ -319,20 +319,20 @@ namespace OpenRa.Game
}
return highest;
}
void UpdateCenterLocation()
{
float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f;
self.CenterLocation = new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction );
}
void UpdateCenterLocation()
{
float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f;
self.CenterLocation = new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction );
}
public void Tick( Actor self, Game game, int dt )
{
Move( self, game, dt );
{
Move( self, game, dt );
UpdateCenterLocation();
}
}
void Move( Actor self, Game game, int dt )
{
if( fromCell != toCell )
@@ -424,16 +424,16 @@ namespace OpenRa.Game
class Building : ITick
{
public Building( Actor self )
{
{
}
bool first = true;
public void Tick( Actor self, Game game, int dt )
{
if( first && self.Owner == game.LocalPlayer )
{
self.Owner.TechTree.Build( self.unitInfo.Name, true );
self.CenterLocation = 24 * (float2)self.Location + 0.5f * self.SelectedSize;
{
if( first && self.Owner == game.LocalPlayer )
{
self.Owner.TechTree.Build( self.unitInfo.Name, true );
self.CenterLocation = 24 * (float2)self.Location + 0.5f * self.SelectedSize;
}
first = false;
}