Added WithAttackAnimation trait

Interacts with WithUnitBody.

Upgrade rule for RenderUnitReload -> RenderSprites + WithUnitBody + WithAttackAnimation

Use WithAttackAnimation for RA V2 launcher
Remove RenderUnitReload
This commit is contained in:
reaperrr
2015-05-11 02:16:37 +02:00
parent b21ca9b7e7
commit 4d79cce491
6 changed files with 102 additions and 57 deletions

View File

@@ -387,6 +387,7 @@
<Compile Include="Traits\Render\WithBarrel.cs" />
<Compile Include="Traits\Render\WithBuildingExplosion.cs" />
<Compile Include="Traits\Render\WithActiveAnimation.cs" />
<Compile Include="Traits\Render\WithAttackAnimation.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
<Compile Include="Traits\Render\WithChargeOverlay.cs" />

View File

@@ -0,0 +1,73 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 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 System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
public class WithAttackAnimationInfo : ITraitInfo, Requires<WithFacingSpriteBodyInfo>, Requires<ArmamentInfo>, Requires<AttackBaseInfo>
{
[Desc("Armament name")]
public readonly string Armament = "primary";
[Desc("Displayed while attacking.")]
public readonly string AttackSequence = null;
[Desc("Displayed while targeting.")]
public readonly string AimSequence = null;
[Desc("Shown while reloading.")]
public readonly string ReloadPrefix = null;
public object Create(ActorInitializer init) { return new WithAttackAnimation(init, this); }
}
public class WithAttackAnimation : ITick, INotifyAttack
{
readonly WithAttackAnimationInfo info;
readonly AttackBase attack;
readonly Armament armament;
readonly WithFacingSpriteBody wfsb;
public WithAttackAnimation(ActorInitializer init, WithAttackAnimationInfo info)
{
this.info = info;
attack = init.Self.Trait<AttackBase>();
armament = init.Self.TraitsImplementing<Armament>()
.Single(a => a.Info.Name == info.Armament);
wfsb = init.Self.Trait<WithFacingSpriteBody>();
}
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
{
if (!string.IsNullOrEmpty(info.AttackSequence))
wfsb.PlayCustomAnimation(self, info.AttackSequence);
}
public void Tick(Actor self)
{
if (string.IsNullOrEmpty(info.AimSequence) && string.IsNullOrEmpty(info.ReloadPrefix))
return;
var sequence = wfsb.Info.Sequence;
if (!string.IsNullOrEmpty(info.AimSequence) && attack.IsAttacking)
sequence = info.AimSequence;
var prefix = (armament.IsReloading && !string.IsNullOrEmpty(info.ReloadPrefix)) ? info.ReloadPrefix : "";
if (!string.IsNullOrEmpty(prefix) && sequence != (prefix + sequence))
sequence = prefix + sequence;
wfsb.DefaultAnimation.ReplaceAnim(sequence);
}
}
}

View File

@@ -1045,6 +1045,27 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (rru != null)
rru.Key = "-WithFacingSpriteBody";
}
// For RenderUnitReload
var rur = node.Value.Nodes.Where(x => x.Key == "RenderUnitReload");
if (rur.Any())
{
rur.Do(x => x.Key = "RenderSprites");
node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", ""));
node.Value.Nodes.Add(new MiniYamlNode("WithFacingSpriteBody", "", new List<MiniYamlNode>
{
new MiniYamlNode("Sequence", "idle")
}));
node.Value.Nodes.Add(new MiniYamlNode("WithAttackAnimation", "", new List<MiniYamlNode>
{
new MiniYamlNode("AimSequence", "aim"),
new MiniYamlNode("ReloadPrefix", "empty-")
}));
var rrur = node.Value.Nodes.FirstOrDefault(n => n.Key == "-RenderUnitReload");
if (rrur != null)
rrur.Key = "-WithFacingSpriteBody";
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);

View File

@@ -88,7 +88,6 @@
<Compile Include="Traits\Render\RenderJammerCircle.cs" />
<Compile Include="Traits\Render\RenderLandingCraft.cs" />
<Compile Include="Traits\Render\RenderShroudCircle.cs" />
<Compile Include="Traits\Render\RenderUnitReload.cs" />
<Compile Include="Traits\SupportPowers\ChronoshiftPower.cs" />
<Compile Include="Traits\SupportPowers\GpsPower.cs" />
<Compile Include="Traits\SupportPowers\ParatroopersPower.cs" />

View File

@@ -1,55 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 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 System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
class RenderUnitReloadInfo : RenderUnitInfo, Requires<ArmamentInfo>, Requires<AttackBaseInfo>
{
[Desc("Armament name")]
public readonly string Armament = "primary";
[Desc("Displayed while targeting.")]
public readonly string AimSequence = "aim";
[Desc("Shown while reloading.")]
public readonly string EmptyPrefix = "empty-";
public override object Create(ActorInitializer init) { return new RenderUnitReload(init, this); }
}
class RenderUnitReload : RenderUnit
{
readonly AttackBase attack;
readonly Armament armament;
readonly RenderUnitReloadInfo info;
public RenderUnitReload(ActorInitializer init, RenderUnitReloadInfo info)
: base(init, info)
{
this.info = info;
attack = init.Self.Trait<AttackBase>();
armament = init.Self.TraitsImplementing<Armament>()
.Single(a => a.Info.Name == info.Armament);
}
public override void Tick(Actor self)
{
var sequence = (armament.IsReloading ? info.EmptyPrefix : "") + (attack.IsAttacking ? info.AimSequence : info.Sequence);
if (sequence != DefaultAnimation.CurrentSequence.Name)
DefaultAnimation.ReplaceAnim(sequence);
base.Tick(self);
}
}
}

View File

@@ -20,11 +20,17 @@ V2RL:
Armament:
Weapon: SCUD
AttackFrontal:
RenderUnitReload:
RenderSprites:
AutoTarget:
Explodes:
Weapon: SCUD
EmptyWeapon: UnitExplodeSmall
AutoSelectionSize:
WithFacingSpriteBody:
Sequence: idle
WithAttackAnimation:
AimSequence: aim
ReloadPrefix: empty-
1TNK:
Inherits: ^Tank