Support custom fully-open sequences for gates.

This commit is contained in:
Paul Chote
2016-07-02 22:39:34 +01:00
parent 983abee1ed
commit ac6b2a8f62

View File

@@ -26,6 +26,9 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Wall type for connections")] [Desc("Wall type for connections")]
public readonly string Type = "wall"; public readonly string Type = "wall";
[Desc("Override sequence to use when fully open.")]
public readonly string OpenSequence = null;
public override object Create(ActorInitializer init) { return new WithGateSpriteBody(init, this); } public override object Create(ActorInitializer init) { return new WithGateSpriteBody(init, this); }
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
@@ -42,10 +45,11 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, INotifyBuildComplete, IWallConnector class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, INotifyBuildComplete, IWallConnector, ITick
{ {
readonly WithGateSpriteBodyInfo gateInfo; readonly WithGateSpriteBodyInfo gateInfo;
readonly Gate gate; readonly Gate gate;
bool renderOpen;
public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info) public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info)
: base(init, info, () => 0) : base(init, info, () => 0)
@@ -54,6 +58,26 @@ namespace OpenRA.Mods.Common.Traits.Render
gate = init.Self.Trait<Gate>(); gate = init.Self.Trait<Gate>();
} }
void UpdateState(Actor self)
{
if (renderOpen)
DefaultAnimation.PlayRepeating(NormalizeSequence(self, gateInfo.OpenSequence));
else
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame);
}
void ITick.Tick(Actor self)
{
if (gateInfo.OpenSequence == null)
return;
if (gate.Position == gate.OpenPosition ^ renderOpen)
{
renderOpen = gate.Position == gate.OpenPosition;
UpdateState(self);
}
}
int GetGateFrame() int GetGateFrame()
{ {
return int2.Lerp(0, DefaultAnimation.CurrentSequence.Length - 1, gate.Position, gate.OpenPosition); return int2.Lerp(0, DefaultAnimation.CurrentSequence.Length - 1, gate.Position, gate.OpenPosition);
@@ -61,12 +85,12 @@ namespace OpenRA.Mods.Common.Traits.Render
public override void DamageStateChanged(Actor self, AttackInfo e) public override void DamageStateChanged(Actor self, AttackInfo e)
{ {
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame); UpdateState(self);
} }
public override void BuildingComplete(Actor self) public override void BuildingComplete(Actor self)
{ {
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame); UpdateState(self);
UpdateNeighbours(self); UpdateNeighbours(self);
} }