Kill RenderUnitRotor in favour of RenderUnit + WithRotor.

This commit is contained in:
Paul Chote
2011-03-23 08:05:09 +13:00
parent c7e2619a98
commit 3071cd8240
8 changed files with 76 additions and 83 deletions

View File

@@ -15,12 +15,12 @@ using OpenRA.Graphics;
namespace OpenRA.Mods.Cnc
{
class WithRoofInfo : ITraitInfo
public class WithRoofInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo>
{
public object Create(ActorInitializer init) { return new WithRoof(init.self); }
}
class WithRoof
public class WithRoof
{
public WithRoof(Actor self)
{

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -221,7 +221,6 @@
<Compile Include="Render\RenderFlare.cs" />
<Compile Include="Render\RenderInfantry.cs" />
<Compile Include="Render\RenderUnitReload.cs" />
<Compile Include="Render\RenderUnitRotor.cs" />
<Compile Include="Render\RenderUnitSpinner.cs" />
<Compile Include="Repairable.cs" />
<Compile Include="RepairsUnits.cs" />
@@ -267,8 +266,6 @@
<Compile Include="Widgets\StrategicProgressWidget.cs" />
<Compile Include="Widgets\WorldCommandWidget.cs" />
<Compile Include="Widgets\WorldTooltipWidget.cs" />
<Compile Include="WithMuzzleFlash.cs" />
<Compile Include="WithShadow.cs" />
<Compile Include="NukePaletteEffect.cs" />
<Compile Include="GainsExperience.cs" />
<Compile Include="GivesExperience.cs" />
@@ -333,6 +330,9 @@
<Compile Include="Widgets\SidebarButtonWidget.cs" />
<Compile Include="Widgets\RadarWidget.cs" />
<Compile Include="ActorExts.cs" />
<Compile Include="Render\WithRotor.cs" />
<Compile Include="Render\WithMuzzleFlash.cs" />
<Compile Include="Render\WithShadow.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -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");
}
}
}

View File

@@ -12,7 +12,7 @@ using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Render
{
class WithMuzzleFlashInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo>
{

View 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");
}
}
}

View File

@@ -12,7 +12,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Render
{
class WithShadowInfo : TraitInfo<WithShadow> {}

View File

@@ -473,9 +473,12 @@ TRAN:
Type: Light
RevealsShroud:
Range: 8
RenderUnitRotor:
PrimaryOffset: 0,14,0,-4
SecondaryOffset: 0,-14,0,-2
RenderUnit:
WithRotor@PRIMARY:
Offset: 0,14,0,-4
WithRotor@SECONDARY:
Id: rotor_2
Offset: 0,-14,0,-2
WithShadow:
Cargo:
Types: Infantry
@@ -508,9 +511,10 @@ HELI:
PrimaryWeapon: HighV.Heli
PrimaryOffset: 0,-10,0,3
FacingTolerance: 20
RenderUnit:
WithRotor:
Offset: 0,0,0,-2
WithMuzzleFlash:
RenderUnitRotor:
PrimaryOffset: 0,0,0,-2
WithShadow:
FallsToEarth:
AutoTarget:

View File

@@ -830,9 +830,12 @@ TRAN:
ROT: 5
Speed: 12
LandableTerrainTypes: Clear,Rough,Road,Ore,Beach
RenderUnitRotor:
PrimaryOffset: 0,14,0,-8
SecondaryOffset: 0,-14,0,-5
RenderUnit:
WithRotor@PRIMARY:
Offset: 0,14,0,-8
WithRotor@SECONDARY:
Id: rotor_2
Offset: 0,-14,0,-5
WithShadow:
Cargo:
Types: Infantry
@@ -872,9 +875,10 @@ HELI:
InitialFacing: 20
ROT: 4
Speed: 16
RenderUnitRotor:
PrimaryOffset: 0,0,0,-2
RenderUnit:
Smokes: no
WithRotor:
Offset: 0,0,0,-2
WithShadow:
LimitedAmmo:
Ammo: 8
@@ -915,8 +919,9 @@ HIND:
InitialFacing: 20
ROT: 4
Speed: 12
RenderUnitRotor:
RenderUnit:
Smokes: no
WithRotor:
WithShadow:
LimitedAmmo:
Ammo: 24