Simplify and fix animation glitches.
This commit is contained in:
committed by
Matthias Mailänder
parent
75624560d2
commit
8f93d7b5d7
@@ -47,7 +47,7 @@ namespace OpenRA.Graphics
|
|||||||
this.facingFunc = facingFunc;
|
this.facingFunc = facingFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CurrentFrame { get { return backwards ? CurrentSequence.Start + CurrentSequence.Length - frame - 1 : frame; } }
|
public int CurrentFrame { get { return backwards ? CurrentSequence.Start + CurrentSequence.Length - frame - 1 : frame; } }
|
||||||
public Sprite Image { get { return CurrentSequence.GetSprite(CurrentFrame, facingFunc()); } }
|
public Sprite Image { get { return CurrentSequence.GetSprite(CurrentFrame, facingFunc()); } }
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WPos pos, WVec offset, int zOffset, PaletteReference palette, float scale)
|
public IEnumerable<IRenderable> Render(WPos pos, WVec offset, int zOffset, PaletteReference palette, float scale)
|
||||||
@@ -139,6 +139,24 @@ namespace OpenRA.Graphics
|
|||||||
tickFunc = () => frame = func();
|
tickFunc = () => frame = func();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void PlayFetchDirection(string sequenceName, Func<int> direction)
|
||||||
|
{
|
||||||
|
tickAlways = false;
|
||||||
|
CurrentSequence = sequenceProvider.GetSequence(name, sequenceName);
|
||||||
|
timeUntilNextFrame = CurrentSequence != null ? CurrentSequence.Tick : defaultTick;
|
||||||
|
|
||||||
|
frame = 0;
|
||||||
|
tickFunc = () =>
|
||||||
|
{
|
||||||
|
var d = direction();
|
||||||
|
if (d > 0 && ++frame >= CurrentSequence.Length)
|
||||||
|
frame = 0;
|
||||||
|
|
||||||
|
if (d < 0 && --frame < 0)
|
||||||
|
frame = CurrentSequence.Length - 1;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
int timeUntilNextFrame;
|
int timeUntilNextFrame;
|
||||||
Action tickFunc;
|
Action tickFunc;
|
||||||
|
|
||||||
|
|||||||
@@ -20,15 +20,14 @@ namespace OpenRA.Mods.TS.Traits
|
|||||||
[Desc("Play an animation when a unit exits or blocks the exit after production finished.")]
|
[Desc("Play an animation when a unit exits or blocks the exit after production finished.")]
|
||||||
class WithProductionDoorOverlayInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>, Requires<BuildingInfo>
|
class WithProductionDoorOverlayInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>, Requires<BuildingInfo>
|
||||||
{
|
{
|
||||||
public readonly string Sequence = "idle-door";
|
public readonly string Sequence = "build-door";
|
||||||
public readonly string BuildSequence = "build-door";
|
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new WithProductionDoorOverlay(init.Self, this); }
|
public object Create(ActorInitializer init) { return new WithProductionDoorOverlay(init.Self, this); }
|
||||||
|
|
||||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
var anim = new Animation(init.World, image, () => 0);
|
var anim = new Animation(init.World, image, () => 0);
|
||||||
anim.PlayRepeating(Sequence);
|
anim.PlayFetchIndex(Sequence, () => 0);
|
||||||
|
|
||||||
var bi = init.Actor.Traits.Get<BuildingInfo>();
|
var bi = init.Actor.Traits.Get<BuildingInfo>();
|
||||||
var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512; // Additional 512 units move from center -> top of cell
|
var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512; // Additional 512 units move from center -> top of cell
|
||||||
@@ -38,20 +37,19 @@ namespace OpenRA.Mods.TS.Traits
|
|||||||
|
|
||||||
class WithProductionDoorOverlay : INotifyBuildComplete, ITick, INotifyProduction, INotifySold, INotifyDamageStateChanged
|
class WithProductionDoorOverlay : INotifyBuildComplete, ITick, INotifyProduction, INotifySold, INotifyDamageStateChanged
|
||||||
{
|
{
|
||||||
readonly WithProductionDoorOverlayInfo info;
|
|
||||||
readonly RenderSprites renderSprites;
|
|
||||||
readonly Animation door;
|
readonly Animation door;
|
||||||
|
|
||||||
bool isOpen;
|
int desiredFrame;
|
||||||
|
|
||||||
CPos openExit;
|
CPos openExit;
|
||||||
bool buildComplete;
|
bool buildComplete;
|
||||||
|
|
||||||
public WithProductionDoorOverlay(Actor self, WithProductionDoorOverlayInfo info)
|
public WithProductionDoorOverlay(Actor self, WithProductionDoorOverlayInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
var renderSprites = self.Trait<RenderSprites>();
|
||||||
renderSprites = self.Trait<RenderSprites>();
|
|
||||||
door = new Animation(self.World, renderSprites.GetImage(self));
|
door = new Animation(self.World, renderSprites.GetImage(self));
|
||||||
door.Play(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.Sequence));
|
door.PlayFetchDirection(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.Sequence),
|
||||||
|
() => desiredFrame - door.CurrentFrame);
|
||||||
|
|
||||||
var buildingInfo = self.Info.Traits.Get<BuildingInfo>();
|
var buildingInfo = self.Info.Traits.Get<BuildingInfo>();
|
||||||
|
|
||||||
@@ -66,12 +64,8 @@ namespace OpenRA.Mods.TS.Traits
|
|||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (isOpen && !self.World.ActorMap.GetUnitsAt(openExit).Any(a => a != self))
|
if (desiredFrame > 0 && !self.World.ActorMap.GetUnitsAt(openExit).Any(a => a != self))
|
||||||
{
|
desiredFrame = 0;
|
||||||
isOpen = false;
|
|
||||||
door.PlayBackwardsThen(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.BuildSequence),
|
|
||||||
() => door.Play(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.Sequence)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DamageStateChanged(Actor self, AttackInfo e)
|
public void DamageStateChanged(Actor self, AttackInfo e)
|
||||||
@@ -82,7 +76,8 @@ namespace OpenRA.Mods.TS.Traits
|
|||||||
|
|
||||||
public void UnitProduced(Actor self, Actor other, CPos exit)
|
public void UnitProduced(Actor self, Actor other, CPos exit)
|
||||||
{
|
{
|
||||||
door.PlayThen(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.BuildSequence), () => { isOpen = true; openExit = exit; });
|
openExit = exit;
|
||||||
|
desiredFrame = door.CurrentSequence.Length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Selling(Actor self) { buildComplete = false; }
|
public void Selling(Actor self) { buildComplete = false; }
|
||||||
|
|||||||
@@ -849,8 +849,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
node.Value.Nodes.RemoveAll(p => p.Key == "-RenderBuilding");
|
node.Value.Nodes.RemoveAll(p => p.Key == "-RenderBuilding");
|
||||||
|
|
||||||
var doorOverlay = new MiniYamlNode("WithProductionDoorOverlay", "");
|
var doorOverlay = new MiniYamlNode("WithProductionDoorOverlay", "");
|
||||||
doorOverlay.Value.Nodes.Add(new MiniYamlNode("Sequence", "idle-top"));
|
doorOverlay.Value.Nodes.Add(new MiniYamlNode("Sequence", "build-top"));
|
||||||
doorOverlay.Value.Nodes.Add(new MiniYamlNode("BuildSequence", "build-top"));
|
|
||||||
node.Value.Nodes.Add(doorOverlay);
|
node.Value.Nodes.Add(doorOverlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,8 +364,7 @@ WEAP:
|
|||||||
Range: 4c0
|
Range: 4c0
|
||||||
Bib:
|
Bib:
|
||||||
WithProductionDoorOverlay:
|
WithProductionDoorOverlay:
|
||||||
Sequence: idle-top
|
Sequence: build-top
|
||||||
BuildSequence: build-top
|
|
||||||
RallyPoint:
|
RallyPoint:
|
||||||
RallyPoint: 0,3
|
RallyPoint: 0,3
|
||||||
Exit@1:
|
Exit@1:
|
||||||
|
|||||||
@@ -147,9 +147,6 @@ weap:
|
|||||||
damaged-build-top: weap2
|
damaged-build-top: weap2
|
||||||
Start: 10
|
Start: 10
|
||||||
Length: 10
|
Length: 10
|
||||||
idle-top: weap2
|
|
||||||
damaged-idle-top: weap2
|
|
||||||
Start: 4
|
|
||||||
make: weapmake
|
make: weapmake
|
||||||
Length: *
|
Length: *
|
||||||
Tick: 80
|
Tick: 80
|
||||||
|
|||||||
@@ -762,8 +762,7 @@ WEAP:
|
|||||||
Range: 4c0
|
Range: 4c0
|
||||||
Bib:
|
Bib:
|
||||||
WithProductionDoorOverlay:
|
WithProductionDoorOverlay:
|
||||||
Sequence: idle-top
|
Sequence: build-top
|
||||||
BuildSequence: build-top
|
|
||||||
RallyPoint:
|
RallyPoint:
|
||||||
Exit@1:
|
Exit@1:
|
||||||
SpawnOffset: 213,-128,0
|
SpawnOffset: 213,-128,0
|
||||||
|
|||||||
@@ -236,9 +236,6 @@ weap:
|
|||||||
damaged-build-top: weap2
|
damaged-build-top: weap2
|
||||||
Start: 4
|
Start: 4
|
||||||
Length: 4
|
Length: 4
|
||||||
idle-top: weap2
|
|
||||||
damaged-idle-top: weap2
|
|
||||||
Start: 4
|
|
||||||
bib: bib2
|
bib: bib2
|
||||||
Length: *
|
Length: *
|
||||||
UseTilesetExtension: true
|
UseTilesetExtension: true
|
||||||
|
|||||||
@@ -182,9 +182,6 @@ gaweap:
|
|||||||
damaged-build-door: gtweap_d
|
damaged-build-door: gtweap_d
|
||||||
Length: 9
|
Length: 9
|
||||||
ShadowStart: 9
|
ShadowStart: 9
|
||||||
idle-door: gtweap_d
|
|
||||||
damaged-idle-door: gtweap_d
|
|
||||||
Start: 1
|
|
||||||
make: gtweapmk
|
make: gtweapmk
|
||||||
Length: 20
|
Length: 20
|
||||||
Tick: 80
|
Tick: 80
|
||||||
@@ -323,9 +320,6 @@ naweap:
|
|||||||
Start: 10
|
Start: 10
|
||||||
Length: 10
|
Length: 10
|
||||||
ShadowStart: 20
|
ShadowStart: 20
|
||||||
idle-door: ntweap_b
|
|
||||||
damaged-idle-door: ntweap_b
|
|
||||||
Start: 1
|
|
||||||
make: ntweapmk
|
make: ntweapmk
|
||||||
Length: 22
|
Length: 22
|
||||||
Tick: 80
|
Tick: 80
|
||||||
|
|||||||
Reference in New Issue
Block a user