Fix make animations.
This commit is contained in:
@@ -69,12 +69,6 @@ namespace OpenRA.Graphics
|
||||
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)
|
||||
{
|
||||
PlayThen(sequenceName, null);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Traits
|
||||
public RenderSimple(Actor self)
|
||||
: this(self, MakeFacingFunc(self))
|
||||
{
|
||||
DefaultAnimation.PlayRepeating("idle");
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
|
||||
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 bool BuildComplete { get; private set; }
|
||||
[Sync] readonly CPos topLeft;
|
||||
readonly Actor self;
|
||||
readonly bool skipMakeAnimation;
|
||||
|
||||
PowerManager PlayerPower;
|
||||
|
||||
@@ -139,7 +141,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
|
||||
|
||||
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info);
|
||||
BuildComplete = init.Contains<SkipMakeAnimsInit>();
|
||||
skipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
||||
}
|
||||
|
||||
public int GetPowerUsage()
|
||||
@@ -180,10 +182,22 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
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;
|
||||
Locked = false;
|
||||
|
||||
foreach (var notify in self.TraitsImplementing<INotifyBuildComplete>())
|
||||
notify.BuildingComplete(self);
|
||||
}
|
||||
|
||||
public void Selling(Actor self)
|
||||
@@ -193,6 +207,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
|
||||
BuildComplete = false;
|
||||
}
|
||||
|
||||
public void Sold(Actor self) { }
|
||||
|
||||
public void BeforeTransform(Actor self)
|
||||
|
||||
@@ -36,8 +36,6 @@ namespace OpenRA.Mods.RA.Render
|
||||
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete
|
||||
{
|
||||
RenderBuildingInfo info;
|
||||
bool buildComplete;
|
||||
bool skipMakeAnimation;
|
||||
|
||||
public RenderBuilding(ActorInitializer init, RenderBuildingInfo info)
|
||||
: this(init, info, () => 0) { }
|
||||
@@ -47,26 +45,12 @@ namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
var self = init.self;
|
||||
this.info = info;
|
||||
skipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
||||
|
||||
DefaultAnimation.Initialize(NormalizeSequence(self, "idle"));
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
|
||||
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)
|
||||
{
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
|
||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class WithMakeAnimationInfo : ITraitInfo, Requires<RenderBuildingInfo>
|
||||
public class WithMakeAnimationInfo : ITraitInfo, Requires<BuildingInfo>, Requires<RenderBuildingInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
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 class WithMakeAnimation : ITick
|
||||
public class WithMakeAnimation
|
||||
{
|
||||
WithMakeAnimationInfo info;
|
||||
RenderBuilding building;
|
||||
bool buildComplete;
|
||||
readonly WithMakeAnimationInfo info;
|
||||
readonly RenderBuilding renderBuilding;
|
||||
|
||||
public WithMakeAnimation(ActorInitializer init, WithMakeAnimationInfo info)
|
||||
{
|
||||
building = init.self.Trait<RenderBuilding>();
|
||||
this.info = info;
|
||||
buildComplete = init.Contains<SkipMakeAnimsInit>();
|
||||
}
|
||||
var self = init.self;
|
||||
renderBuilding = self.Trait<RenderBuilding>();
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (self.IsDead() || buildComplete)
|
||||
return;
|
||||
|
||||
buildComplete = true;
|
||||
|
||||
building.PlayCustomAnimThen(self, info.Sequence, () =>
|
||||
var building = self.Trait<Building>();
|
||||
if (!init.Contains<SkipMakeAnimsInit>())
|
||||
{
|
||||
foreach (var notify in self.TraitsImplementing<INotifyBuildComplete>())
|
||||
notify.BuildingComplete(self);
|
||||
});
|
||||
renderBuilding.PlayCustomAnimThen(self, info.Sequence, () =>
|
||||
{
|
||||
building.NotifyBuildingComplete(self);
|
||||
});
|
||||
}
|
||||
else
|
||||
building.NotifyBuildingComplete(self);
|
||||
}
|
||||
|
||||
public void Reverse(Actor self, Activity activity)
|
||||
{
|
||||
building.PlayCustomAnimBackwards(self, info.Sequence, () => {
|
||||
building.PlayCustomAnim(self, info.Sequence); // avoids visual glitches as we wait for the actor to get destroyed
|
||||
renderBuilding.PlayCustomAnimBackwards(self, info.Sequence, () =>
|
||||
{
|
||||
// avoids visual glitches as we wait for the actor to get destroyed
|
||||
renderBuilding.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0);
|
||||
self.QueueActivity(activity);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user