Convert RenderUnitSpinner -> RenderUnit + WithSpinner.

Also sets correct offsets for the units that use it.
This commit is contained in:
Paul Chote
2013-03-31 23:43:34 +13:00
parent 800a9ff0c4
commit 7b54bbf0b2
5 changed files with 51 additions and 49 deletions

View File

@@ -317,7 +317,6 @@
<Compile Include="Render\RenderSpy.cs" />
<Compile Include="Render\RenderUnit.cs" />
<Compile Include="Render\RenderUnitReload.cs" />
<Compile Include="Render\RenderUnitSpinner.cs" />
<Compile Include="Render\RenderUnitTurreted.cs" />
<Compile Include="Render\WithBuildingExplosion.cs" />
<Compile Include="Render\WithMuzzleFlash.cs" />
@@ -423,6 +422,7 @@
<Compile Include="Armament.cs" />
<Compile Include="DebugMuzzlePositions.cs" />
<Compile Include="Buildings\BaseProvider.cs" />
<Compile Include="Render\WithSpinner.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -1,41 +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 RenderUnitSpinnerInfo : RenderUnitInfo
{
public readonly int[] Offset = { 0, 0 };
public override object Create(ActorInitializer init) { return new RenderUnitSpinner(init.self); }
}
class RenderUnitSpinner : RenderUnit
{
public RenderUnitSpinner(Actor self)
: base(self)
{
var info = self.Info.Traits.Get<RenderUnitSpinnerInfo>();
var spinnerAnim = new Animation(GetImage(self));
var facing = self.Trait<IFacing>();
spinnerAnim.PlayRepeating("spinner");
var turret = new Turret(info.Offset);
anims.Add("spinner", new AnimationWithOffset(
spinnerAnim,
wr => turret.PxPosition(self, facing).ToFloat2(),
null ) { ZOffset = 1 } );
}
}
}

View File

@@ -0,0 +1,39 @@
#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.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class WithSpinnerInfo : ITraitInfo, Requires<RenderSimpleInfo>
{
public readonly string Name = "spinner";
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
public object Create(ActorInitializer init) { return new WithSpinner(init.self, this); }
}
class WithSpinner
{
public WithSpinner(Actor self, WithSpinnerInfo info)
{
var rs = self.Trait<RenderSimple>();
var spinner = new Animation(rs.GetImage(self));
spinner.PlayRepeating("spinner");
rs.anims.Add(info.Name, new AnimationWithOffset(
spinner,
wr => wr.ScreenPxOffset(rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation)))),
null ) { ZOffset = 1 } );
}
}
}