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:
@@ -465,7 +465,7 @@
|
|||||||
<Compile Include="Traits\Render\WithAimAnimation.cs" />
|
<Compile Include="Traits\Render\WithAimAnimation.cs" />
|
||||||
<Compile Include="Traits\Render\WithAttackOverlay.cs" />
|
<Compile Include="Traits\Render\WithAttackOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithMoveAnimation.cs" />
|
<Compile Include="Traits\Render\WithMoveAnimation.cs" />
|
||||||
<Compile Include="Traits\Render\WithSiloAnimation.cs" />
|
<Compile Include="Traits\Render\WithResourceLevelSpriteBody.cs" />
|
||||||
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
|
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
|
||||||
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
|
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
|
||||||
<Compile Include="Traits\Render\WithCrateBody.cs" />
|
<Compile Include="Traits\Render\WithCrateBody.cs" />
|
||||||
@@ -485,7 +485,7 @@
|
|||||||
<Compile Include="Traits\Render\WithRangeCircle.cs" />
|
<Compile Include="Traits\Render\WithRangeCircle.cs" />
|
||||||
<Compile Include="Traits\Render\WithResupplyAnimation.cs" />
|
<Compile Include="Traits\Render\WithResupplyAnimation.cs" />
|
||||||
<Compile Include="Traits\Render\WithRepairOverlay.cs" />
|
<Compile Include="Traits\Render\WithRepairOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithResources.cs" />
|
<Compile Include="Traits\Render\WithResourceLevelOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithShadow.cs" />
|
<Compile Include="Traits\Render\WithShadow.cs" />
|
||||||
<Compile Include="Traits\Render\WithSpriteBody.cs" />
|
<Compile Include="Traits\Render\WithSpriteBody.cs" />
|
||||||
<Compile Include="Traits\Render\WithSpriteTurret.cs" />
|
<Compile Include="Traits\Render\WithSpriteTurret.cs" />
|
||||||
@@ -949,6 +949,7 @@
|
|||||||
<Compile Include="UpdateRules\Rules\20180923\DefineLevelUpImageDefault.cs" />
|
<Compile Include="UpdateRules\Rules\20180923\DefineLevelUpImageDefault.cs" />
|
||||||
<Compile Include="UpdateRules\Rules\20180923\RemovedAutoCarryallCircleTurnSpeed.cs" />
|
<Compile Include="UpdateRules\Rules\20180923\RemovedAutoCarryallCircleTurnSpeed.cs" />
|
||||||
<Compile Include="UpdateRules\Rules\20180923\ReplacedWithChargeAnimation.cs" />
|
<Compile Include="UpdateRules\Rules\20180923\ReplacedWithChargeAnimation.cs" />
|
||||||
|
<Compile Include="UpdateRules\Rules\20180923\RefactorResourceLevelAnimating.cs" />
|
||||||
<Compile Include="Traits\Player\PlayerResources.cs" />
|
<Compile Include="Traits\Player\PlayerResources.cs" />
|
||||||
<Compile Include="UtilityCommands\DumpSequenceSheetsCommand.cs" />
|
<Compile Include="UtilityCommands\DumpSequenceSheetsCommand.cs" />
|
||||||
<Compile Include="Traits\Render\WithBuildingRepairDecoration.cs" />
|
<Compile Include="Traits\Render\WithBuildingRepairDecoration.cs" />
|
||||||
|
|||||||
@@ -15,16 +15,15 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits.Render
|
namespace OpenRA.Mods.Common.Traits.Render
|
||||||
{
|
{
|
||||||
[Desc("Displays the fill status of PlayerResources with an extra sprite overlay on the actor.")]
|
[Desc("Displays the fill status of PlayerResources with an extra sprite overlay on the actor.")]
|
||||||
class WithResourcesInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
|
class WithResourceLevelOverlayInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
|
||||||
{
|
{
|
||||||
[Desc("Sequence name to use")]
|
[Desc("Sequence name to use")]
|
||||||
[SequenceReference] public readonly string Sequence = "resources";
|
[SequenceReference] public readonly string Sequence = "resources";
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new WithResources(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new WithResourceLevelOverlay(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename to WithResourcesOverlay to conform with our naming conventions
|
class WithResourceLevelOverlay : ConditionalTrait<WithResourceLevelOverlayInfo>, INotifyOwnerChanged, INotifyDamageStateChanged
|
||||||
class WithResources : ConditionalTrait<WithResourcesInfo>, INotifyOwnerChanged, INotifyDamageStateChanged
|
|
||||||
{
|
{
|
||||||
readonly AnimationWithOffset anim;
|
readonly AnimationWithOffset anim;
|
||||||
readonly RenderSprites rs;
|
readonly RenderSprites rs;
|
||||||
@@ -32,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
PlayerResources playerResources;
|
PlayerResources playerResources;
|
||||||
|
|
||||||
public WithResources(Actor self, WithResourcesInfo info)
|
public WithResourceLevelOverlay(Actor self, WithResourceLevelOverlayInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
rs = self.Trait<RenderSprites>();
|
rs = self.Trait<RenderSprites>();
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
#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 System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits.Render
|
||||||
|
{
|
||||||
|
[Desc("Render trait for buildings that change the sprite according to the remaining resource storage capacity across all depots.")]
|
||||||
|
public class WithResourceLevelSpriteBodyInfo : WithSpriteBodyInfo
|
||||||
|
{
|
||||||
|
[Desc("Internal resource stages. Does not have to match number of sequence frames.")]
|
||||||
|
public readonly int Stages = 10;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new WithResourceLevelSpriteBody(init, this); }
|
||||||
|
|
||||||
|
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
|
{
|
||||||
|
if (!EnabledByDefault)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
var anim = new Animation(init.World, image);
|
||||||
|
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
|
||||||
|
|
||||||
|
yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WithResourceLevelSpriteBody : WithSpriteBody, INotifyOwnerChanged
|
||||||
|
{
|
||||||
|
readonly WithResourceLevelSpriteBodyInfo info;
|
||||||
|
PlayerResources playerResources;
|
||||||
|
|
||||||
|
public WithResourceLevelSpriteBody(ActorInitializer init, WithResourceLevelSpriteBodyInfo info)
|
||||||
|
: base(init, info, () => 0)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||||
|
ConfigureAnimation(init.Self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureAnimation(Actor self)
|
||||||
|
{
|
||||||
|
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence),
|
||||||
|
() => playerResources.ResourceCapacity != 0
|
||||||
|
? ((info.Stages * DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (info.Stages * playerResources.ResourceCapacity)
|
||||||
|
: 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
|
{
|
||||||
|
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void TraitEnabled(Actor self)
|
||||||
|
{
|
||||||
|
// Do nothing - we just want to disable the default WithSpriteBody implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void CancelCustomAnimation(Actor self)
|
||||||
|
{
|
||||||
|
ConfigureAnimation(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#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 System.Linq;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits.Render
|
|
||||||
{
|
|
||||||
[Desc("Render trait for buildings that change the sprite according to the remaining resource storage capacity across all depots.")]
|
|
||||||
class WithSiloAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
|
|
||||||
{
|
|
||||||
[Desc("Sequence to use for resources-dependent 'stages'."), SequenceReference]
|
|
||||||
public readonly string Sequence = "stages";
|
|
||||||
|
|
||||||
[Desc("Internal resource stages. Does not have to match number of sequence frames.")]
|
|
||||||
public readonly int Stages = 10;
|
|
||||||
|
|
||||||
[Desc("Which sprite body to play the animation on.")]
|
|
||||||
public readonly string Body = "body";
|
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new WithSiloAnimation(init, this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
class WithSiloAnimation : ConditionalTrait<WithSiloAnimationInfo>, INotifyOwnerChanged
|
|
||||||
{
|
|
||||||
readonly WithSpriteBody wsb;
|
|
||||||
PlayerResources playerResources;
|
|
||||||
|
|
||||||
public WithSiloAnimation(ActorInitializer init, WithSiloAnimationInfo info)
|
|
||||||
: base(info)
|
|
||||||
{
|
|
||||||
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
|
|
||||||
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayAnimation(Actor self)
|
|
||||||
{
|
|
||||||
wsb.DefaultAnimation.PlayFetchIndex(wsb.NormalizeSequence(self, Info.Sequence),
|
|
||||||
() => playerResources.ResourceCapacity != 0
|
|
||||||
? ((Info.Stages * wsb.DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (Info.Stages * playerResources.ResourceCapacity)
|
|
||||||
: 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
|
||||||
{
|
|
||||||
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
|
|
||||||
PlayAnimation(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self) { PlayAnimation(self); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
#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 System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||||
|
{
|
||||||
|
public class RefactorResourceLevelAnimating : UpdateRule
|
||||||
|
{
|
||||||
|
public override string Name { get { return "Streamlined traits animating player resource level"; } }
|
||||||
|
public override string Description
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Replaced WithSiloAnimation with WithResourceLevelSpriteBody and\n" +
|
||||||
|
"renamed WithResources to WithResourceLevelOverlay.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly List<string> locations = new List<string>();
|
||||||
|
|
||||||
|
public override IEnumerable<string> AfterUpdate(ModData modData)
|
||||||
|
{
|
||||||
|
if (locations.Any())
|
||||||
|
yield return "WithSiloAnimation has been replaced by WithResourceLevelSpriteBody.\n" +
|
||||||
|
"You may need to disable/remove any previous (including inherited) *SpriteBody traits\n" +
|
||||||
|
"on the following actors:\n" +
|
||||||
|
UpdateUtils.FormatMessageList(locations);
|
||||||
|
|
||||||
|
locations.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
|
||||||
|
{
|
||||||
|
foreach (var wr in actorNode.ChildrenMatching("WithResources"))
|
||||||
|
wr.RenameKey("WithResourceLevelOverlay");
|
||||||
|
|
||||||
|
var siloAnims = actorNode.ChildrenMatching("WithSiloAnimation");
|
||||||
|
foreach (var sa in siloAnims)
|
||||||
|
{
|
||||||
|
// If it's a trait removal, we only rename it.
|
||||||
|
if (sa.IsRemoval())
|
||||||
|
{
|
||||||
|
sa.RenameKey("WithResourceLevelSpriteBody");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sequence = sa.LastChildMatching("Sequence");
|
||||||
|
var body = sa.LastChildMatching("Body");
|
||||||
|
|
||||||
|
if (sequence == null)
|
||||||
|
{
|
||||||
|
var newSequenceNode = new MiniYamlNode("Sequence", "stages");
|
||||||
|
sa.AddNode(newSequenceNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null)
|
||||||
|
sa.RemoveNode(body);
|
||||||
|
|
||||||
|
sa.RenameKey("WithResourceLevelSpriteBody");
|
||||||
|
locations.Add("{0} ({1})".F(actorNode.Key, sa.Location.Filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -112,6 +112,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
new RemovedAutoCarryallCircleTurnSpeed(),
|
new RemovedAutoCarryallCircleTurnSpeed(),
|
||||||
new RemoveAttackIgnoresVisibility(),
|
new RemoveAttackIgnoresVisibility(),
|
||||||
new ReplacedWithChargeAnimation(),
|
new ReplacedWithChargeAnimation(),
|
||||||
|
new RefactorResourceLevelAnimating(),
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ PROC:
|
|||||||
SpawnOffset: 1,2
|
SpawnOffset: 1,2
|
||||||
Facing: 64
|
Facing: 64
|
||||||
WithBuildingBib:
|
WithBuildingBib:
|
||||||
WithResources:
|
WithResourceLevelOverlay:
|
||||||
RequiresCondition: !build-incomplete
|
RequiresCondition: !build-incomplete
|
||||||
Power:
|
Power:
|
||||||
Amount: -40
|
Amount: -40
|
||||||
@@ -257,8 +257,9 @@ SILO:
|
|||||||
Range: 4c0
|
Range: 4c0
|
||||||
WithBuildingBib:
|
WithBuildingBib:
|
||||||
HasMinibib: Yes
|
HasMinibib: Yes
|
||||||
WithSiloAnimation:
|
-WithSpriteBody:
|
||||||
RequiresCondition: !build-incomplete
|
WithResourceLevelSpriteBody:
|
||||||
|
Sequence: stages
|
||||||
StoresResources:
|
StoresResources:
|
||||||
PipCount: 10
|
PipCount: 10
|
||||||
PipColor: Green
|
PipColor: Green
|
||||||
|
|||||||
@@ -353,8 +353,9 @@ silo:
|
|||||||
fremen: silo.atreides
|
fremen: silo.atreides
|
||||||
harkonnen: silo.harkonnen
|
harkonnen: silo.harkonnen
|
||||||
corrino: silo.harkonnen
|
corrino: silo.harkonnen
|
||||||
WithSiloAnimation:
|
-WithSpriteBody:
|
||||||
RequiresCondition: !build-incomplete
|
WithResourceLevelSpriteBody:
|
||||||
|
Sequence: stages
|
||||||
StoresResources:
|
StoresResources:
|
||||||
PipColor: green
|
PipColor: green
|
||||||
PipCount: 5
|
PipCount: 5
|
||||||
|
|||||||
@@ -1273,8 +1273,9 @@ SILO:
|
|||||||
Notification: CreditsStolen
|
Notification: CreditsStolen
|
||||||
WithBuildingBib:
|
WithBuildingBib:
|
||||||
HasMinibib: Yes
|
HasMinibib: Yes
|
||||||
WithSiloAnimation:
|
-WithSpriteBody:
|
||||||
RequiresCondition: !build-incomplete
|
WithResourceLevelSpriteBody:
|
||||||
|
Sequence: stages
|
||||||
StoresResources:
|
StoresResources:
|
||||||
PipCount: 5
|
PipCount: 5
|
||||||
Capacity: 3000
|
Capacity: 3000
|
||||||
|
|||||||
@@ -160,10 +160,10 @@ GASILO:
|
|||||||
FactionImages:
|
FactionImages:
|
||||||
gdi: gasilo.gdi
|
gdi: gasilo.gdi
|
||||||
nod: gasilo.nod
|
nod: gasilo.nod
|
||||||
WithSiloAnimation:
|
WithResourceLevelOverlay@FILLSTAGE:
|
||||||
RequiresCondition: !build-incomplete
|
|
||||||
WithIdleOverlay@UNDERLAY:
|
|
||||||
RequiresCondition: !build-incomplete
|
RequiresCondition: !build-incomplete
|
||||||
|
Sequence: stages
|
||||||
|
WithSpriteBody:
|
||||||
Sequence: idle-underlay
|
Sequence: idle-underlay
|
||||||
WithIdleOverlay@LIGHTS:
|
WithIdleOverlay@LIGHTS:
|
||||||
RequiresCondition: !build-incomplete
|
RequiresCondition: !build-incomplete
|
||||||
|
|||||||
Reference in New Issue
Block a user