Fix make animations.

This commit is contained in:
Paul Chote
2014-07-08 16:50:02 +12:00
parent 5650d5fc98
commit 2b91a2363b
5 changed files with 39 additions and 48 deletions

View File

@@ -69,12 +69,6 @@ namespace OpenRA.Graphics
return Render(pos, WVec.Zero, 0, palette, 1f); return Render(pos, WVec.Zero, 0, palette, 1f);
} }
public void Initialize(string sequenceName)
{
CurrentSequence = sequenceProvider.GetSequence(name, sequenceName);
tickAlways = true;
}
public void Play(string sequenceName) public void Play(string sequenceName)
{ {
PlayThen(sequenceName, null); PlayThen(sequenceName, null);

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Traits
public RenderSimple(Actor self) public RenderSimple(Actor self)
: this(self, MakeFacingFunc(self)) : this(self, MakeFacingFunc(self))
{ {
DefaultAnimation.PlayRepeating("idle"); DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings); self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
} }

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Mods.RA.Render;
namespace OpenRA.Mods.RA.Buildings namespace OpenRA.Mods.RA.Buildings
{ {
@@ -100,12 +101,13 @@ namespace OpenRA.Mods.RA.Buildings
} }
} }
public class Building : INotifyDamage, IOccupySpace, INotifyCapture, INotifyBuildComplete, INotifySold, INotifyTransform, ISync, ITechTreePrerequisite, INotifyAddedToWorld, INotifyRemovedFromWorld public class Building : INotifyDamage, IOccupySpace, INotifyCapture, ITick, INotifySold, INotifyTransform, ISync, ITechTreePrerequisite, INotifyAddedToWorld, INotifyRemovedFromWorld
{ {
public readonly BuildingInfo Info; public readonly BuildingInfo Info;
public bool BuildComplete { get; private set; } public bool BuildComplete { get; private set; }
[Sync] readonly CPos topLeft; [Sync] readonly CPos topLeft;
readonly Actor self; readonly Actor self;
readonly bool skipMakeAnimation;
PowerManager PlayerPower; PowerManager PlayerPower;
@@ -139,7 +141,7 @@ namespace OpenRA.Mods.RA.Buildings
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); .Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info); CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info);
BuildComplete = init.Contains<SkipMakeAnimsInit>(); skipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
} }
public int GetPowerUsage() public int GetPowerUsage()
@@ -180,10 +182,22 @@ namespace OpenRA.Mods.RA.Buildings
self.World.ScreenMap.Remove(self); self.World.ScreenMap.Remove(self);
} }
public void BuildingComplete(Actor self) public void Tick(Actor self)
{ {
if (!BuildComplete && (skipMakeAnimation || !self.HasTrait<WithMakeAnimation>()))
NotifyBuildingComplete(self);
}
public void NotifyBuildingComplete(Actor self)
{
if (BuildComplete)
return;
BuildComplete = true; BuildComplete = true;
Locked = false; Locked = false;
foreach (var notify in self.TraitsImplementing<INotifyBuildComplete>())
notify.BuildingComplete(self);
} }
public void Selling(Actor self) public void Selling(Actor self)
@@ -193,6 +207,7 @@ namespace OpenRA.Mods.RA.Buildings
BuildComplete = false; BuildComplete = false;
} }
public void Sold(Actor self) { } public void Sold(Actor self) { }
public void BeforeTransform(Actor self) public void BeforeTransform(Actor self)

View File

@@ -36,8 +36,6 @@ namespace OpenRA.Mods.RA.Render
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete
{ {
RenderBuildingInfo info; RenderBuildingInfo info;
bool buildComplete;
bool skipMakeAnimation;
public RenderBuilding(ActorInitializer init, RenderBuildingInfo info) public RenderBuilding(ActorInitializer init, RenderBuildingInfo info)
: this(init, info, () => 0) { } : this(init, info, () => 0) { }
@@ -47,26 +45,12 @@ namespace OpenRA.Mods.RA.Render
{ {
var self = init.self; var self = init.self;
this.info = info; this.info = info;
skipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
DefaultAnimation.Initialize(NormalizeSequence(self, "idle")); DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings); self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
} }
public override void Tick(Actor self)
{
base.Tick(self);
if (buildComplete)
return;
buildComplete = true;
if (!self.HasTrait<WithMakeAnimation>() || skipMakeAnimation)
foreach (var notify in self.TraitsImplementing<INotifyBuildComplete>())
notify.BuildingComplete(self);
}
public virtual void BuildingComplete(Actor self) public virtual void BuildingComplete(Actor self)
{ {
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render namespace OpenRA.Mods.RA.Render
{ {
public class WithMakeAnimationInfo : ITraitInfo, Requires<RenderBuildingInfo> public class WithMakeAnimationInfo : ITraitInfo, Requires<BuildingInfo>, Requires<RenderBuildingInfo>
{ {
[Desc("Sequence name to use")] [Desc("Sequence name to use")]
public readonly string Sequence = "make"; public readonly string Sequence = "make";
@@ -26,37 +26,35 @@ namespace OpenRA.Mods.RA.Render
public object Create(ActorInitializer init) { return new WithMakeAnimation(init, this); } public object Create(ActorInitializer init) { return new WithMakeAnimation(init, this); }
} }
public class WithMakeAnimation : ITick public class WithMakeAnimation
{ {
WithMakeAnimationInfo info; readonly WithMakeAnimationInfo info;
RenderBuilding building; readonly RenderBuilding renderBuilding;
bool buildComplete;
public WithMakeAnimation(ActorInitializer init, WithMakeAnimationInfo info) public WithMakeAnimation(ActorInitializer init, WithMakeAnimationInfo info)
{ {
building = init.self.Trait<RenderBuilding>();
this.info = info; this.info = info;
buildComplete = init.Contains<SkipMakeAnimsInit>(); var self = init.self;
} renderBuilding = self.Trait<RenderBuilding>();
public void Tick(Actor self) var building = self.Trait<Building>();
{ if (!init.Contains<SkipMakeAnimsInit>())
if (self.IsDead() || buildComplete)
return;
buildComplete = true;
building.PlayCustomAnimThen(self, info.Sequence, () =>
{ {
foreach (var notify in self.TraitsImplementing<INotifyBuildComplete>()) renderBuilding.PlayCustomAnimThen(self, info.Sequence, () =>
notify.BuildingComplete(self); {
}); building.NotifyBuildingComplete(self);
});
}
else
building.NotifyBuildingComplete(self);
} }
public void Reverse(Actor self, Activity activity) public void Reverse(Actor self, Activity activity)
{ {
building.PlayCustomAnimBackwards(self, info.Sequence, () => { renderBuilding.PlayCustomAnimBackwards(self, info.Sequence, () =>
building.PlayCustomAnim(self, info.Sequence); // avoids visual glitches as we wait for the actor to get destroyed {
// avoids visual glitches as we wait for the actor to get destroyed
renderBuilding.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0);
self.QueueActivity(activity); self.QueueActivity(activity);
}); });
} }