Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8171 from reaperrr/withunitbody1
Introduce WithFacingSpriteBody and related With*Animation traits
- Loading branch information
Showing
41 changed files
with
754 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#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; | ||
using OpenRA.Traits; | ||
|
||
namespace OpenRA.Mods.Common.Traits | ||
{ | ||
public class AutoSelectionSizeInfo : ITraitInfo, Requires<RenderSpritesInfo> | ||
{ | ||
public object Create(ActorInitializer init) { return new AutoSelectionSize(this); } | ||
} | ||
|
||
public class AutoSelectionSize : IAutoSelectionSize | ||
{ | ||
public AutoSelectionSize(AutoSelectionSizeInfo info) { } | ||
|
||
public int2 SelectionSize(Actor self) | ||
{ | ||
var rs = self.Trait<RenderSprites>(); | ||
return rs.AutoSelectionSize(self); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#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; | ||
using System.Collections.Generic; | ||
using OpenRA.Graphics; | ||
using OpenRA.Mods.Common.Graphics; | ||
using OpenRA.Traits; | ||
|
||
namespace OpenRA.Mods.Common.Traits | ||
{ | ||
public class WithFacingSpriteBodyInfo : WithSpriteBodyInfo, Requires<IBodyOrientationInfo>, Requires<IFacingInfo> | ||
{ | ||
public override object Create(ActorInitializer init) { return new WithFacingSpriteBody(init, this); } | ||
|
||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) | ||
{ | ||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>(); | ||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0; | ||
|
||
var anim = new Animation(init.World, image, () => facing); | ||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence)); | ||
|
||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale); | ||
} | ||
|
||
public override int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race) | ||
{ | ||
var rsi = ai.Traits.Get<RenderSpritesInfo>(); | ||
return sequenceProvider.GetSequence(rsi.GetImage(ai, sequenceProvider, race), Sequence).Facings; | ||
} | ||
} | ||
|
||
public class WithFacingSpriteBody : WithSpriteBody | ||
{ | ||
public WithFacingSpriteBody(ActorInitializer init, WithFacingSpriteBodyInfo info) | ||
: base(init, info, RenderSprites.MakeFacingFunc(init.Self)) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.