Streamline resource anim traits

- Replaces WithSiloAnimation with
  WithResourceLevelSpriteBody.

PlayFetchIndex on a With*Animation trait conflicts
with the animation concept, as it's bound to conflict
with pretty much all 'normal' animation traits and
blocks progress on the animation priority system.

We also already have multiple similar SpriteBody traits,
like WithGateSpriteBody and WithWallSpriteBody.

- Rename WithResources to WithResourceLevelOverlay

Make name more accurate and consistent with sprite body
equivalent.
Also fix TS silo yaml setup (bleed setup stems from times
before WithResources was introduced).
This commit is contained in:
reaperrr
2018-12-14 00:18:16 +01:00
committed by Paul Chote
parent 305d82f887
commit be310ab6a6
10 changed files with 173 additions and 77 deletions

View File

@@ -0,0 +1,62 @@
#region Copyright & License Information
/*
* Copyright 2007-2018 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Displays the fill status of PlayerResources with an extra sprite overlay on the actor.")]
class WithResourceLevelOverlayInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "resources";
public override object Create(ActorInitializer init) { return new WithResourceLevelOverlay(init.Self, this); }
}
class WithResourceLevelOverlay : ConditionalTrait<WithResourceLevelOverlayInfo>, INotifyOwnerChanged, INotifyDamageStateChanged
{
readonly AnimationWithOffset anim;
readonly RenderSprites rs;
readonly WithSpriteBody wsb;
PlayerResources playerResources;
public WithResourceLevelOverlay(Actor self, WithResourceLevelOverlayInfo info)
: base(info)
{
rs = self.Trait<RenderSprites>();
wsb = self.Trait<WithSpriteBody>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
var a = new Animation(self.World, rs.GetImage(self));
a.PlayFetchIndex(info.Sequence, () =>
playerResources.ResourceCapacity != 0 ?
((10 * a.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity) :
0);
anim = new AnimationWithOffset(a, null, () => IsTraitDisabled, 1024);
rs.Add(anim);
}
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
if (anim.Animation.CurrentSequence != null)
anim.Animation.ReplaceAnim(wsb.NormalizeSequence(self, Info.Sequence));
}
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
}
}
}