Remove RenderSprites animation keys.

This commit is contained in:
Paul Chote
2015-04-19 17:52:21 +12:00
parent c4a63eee30
commit 614f96046c
25 changed files with 105 additions and 99 deletions

View File

@@ -47,19 +47,19 @@ namespace OpenRA.Mods.Cnc.Traits
left = new Animation(init.World, name, () => turret.TurretFacing); left = new Animation(init.World, name, () => turret.TurretFacing);
left.Play(info.LeftSequence); left.Play(info.LeftSequence);
Add(info.LeftSequence, new AnimationWithOffset(left, null, () => facing.Facing > 128, 0)); Add(new AnimationWithOffset(left, null, () => facing.Facing > 128, 0));
right = new Animation(init.World, name, () => turret.TurretFacing); right = new Animation(init.World, name, () => turret.TurretFacing);
right.Play(info.RightSequence); right.Play(info.RightSequence);
Add(info.RightSequence, new AnimationWithOffset(right, null, () => facing.Facing <= 128, 0)); Add(new AnimationWithOffset(right, null, () => facing.Facing <= 128, 0));
var leftWake = new Animation(init.World, name); var leftWake = new Animation(init.World, name);
leftWake.PlayRepeating(info.WakeLeftSequence); leftWake.PlayRepeating(info.WakeLeftSequence);
Add(info.WakeLeftSequence, new AnimationWithOffset(leftWake, null, () => facing.Facing > 128, -87)); Add(new AnimationWithOffset(leftWake, null, () => facing.Facing > 128, -87));
var rightWake = new Animation(init.World, name); var rightWake = new Animation(init.World, name);
rightWake.PlayRepeating(info.WakeRightSequence); rightWake.PlayRepeating(info.WakeRightSequence);
Add(info.WakeRightSequence, new AnimationWithOffset(rightWake, null, () => facing.Facing <= 128, -87)); Add(new AnimationWithOffset(rightWake, null, () => facing.Facing <= 128, -87));
} }
public void DamageStateChanged(Actor self, AttackInfo e) public void DamageStateChanged(Actor self, AttackInfo e)

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.Traits
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var roof = new Animation(self.World, rs.GetImage(self), () => self.Trait<IFacing>().Facing); var roof = new Animation(self.World, rs.GetImage(self), () => self.Trait<IFacing>().Facing);
roof.Play(info.Sequence); roof.Play(info.Sequence);
rs.Add("roof", new AnimationWithOffset(roof, null, null, 1024)); rs.Add(new AnimationWithOffset(roof, null, null, 1024));
} }
} }
} }

View File

@@ -69,6 +69,7 @@ namespace OpenRA.Mods.Common.Traits
readonly BibInfo info; readonly BibInfo info;
readonly RenderSprites rs; readonly RenderSprites rs;
readonly BuildingInfo bi; readonly BuildingInfo bi;
readonly List<AnimationWithOffset> anims = new List<AnimationWithOffset>();
public Bib(Actor self, BibInfo info) public Bib(Actor self, BibInfo info)
{ {
@@ -103,17 +104,17 @@ namespace OpenRA.Mods.Common.Traits
// Z-order is one set to the top of the footprint // Z-order is one set to the top of the footprint
var offset = self.World.Map.CenterOfCell(cell) - self.World.Map.CenterOfCell(location) - centerOffset; var offset = self.World.Map.CenterOfCell(cell) - self.World.Map.CenterOfCell(location) - centerOffset;
var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512)); var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512));
rs.Add("bib_{0}".F(i), awo, info.Palette); anims.Add(awo);
rs.Add(awo, info.Palette);
} }
} }
public void RemovedFromWorld(Actor self) public void RemovedFromWorld(Actor self)
{ {
var width = bi.Dimensions.X; foreach (var a in anims)
var rows = info.HasMinibib ? 1 : 2; rs.Remove(a);
for (var i = 0; i < rows * width; i++) anims.Clear();
rs.Remove("bib_{0}".F(i));
} }
} }

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
var anim = new Animation(self.World, "fire", () => 0); var anim = new Animation(self.World, "fire", () => 0);
anim.IsDecoration = true; anim.IsDecoration = true;
anim.PlayRepeating(info.Anim); anim.PlayRepeating(info.Anim);
self.Trait<RenderSprites>().Add("fire", anim); self.Trait<RenderSprites>().Add(anim);
} }
public void Tick(Actor self) public void Tick(Actor self)

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info; this.info = info;
DefaultAnimation = new Animation(init.World, GetImage(init.Self), baseFacing); DefaultAnimation = new Animation(init.World, GetImage(init.Self), baseFacing);
Add("", DefaultAnimation); Add(DefaultAnimation);
} }
public RenderSimple(ActorInitializer init, RenderSimpleInfo info) public RenderSimple(ActorInitializer init, RenderSimpleInfo info)

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits
readonly string race; readonly string race;
readonly RenderSpritesInfo info; readonly RenderSpritesInfo info;
readonly Dictionary<string, AnimationWrapper> anims = new Dictionary<string, AnimationWrapper>(); readonly List<AnimationWrapper> anims = new List<AnimationWrapper>();
string cachedImage; string cachedImage;
public static Func<int> MakeFacingFunc(Actor self) public static Func<int> MakeFacingFunc(Actor self)
@@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Traits
public void UpdatePalette() public void UpdatePalette()
{ {
foreach (var anim in anims.Values) foreach (var anim in anims)
anim.OwnerChanged(); anim.OwnerChanged();
} }
@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr) public virtual IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
{ {
foreach (var a in anims.Values) foreach (var a in anims)
{ {
if (!a.IsVisible) if (!a.IsVisible)
continue; continue;
@@ -177,11 +177,11 @@ namespace OpenRA.Mods.Common.Traits
public virtual void Tick(Actor self) public virtual void Tick(Actor self)
{ {
foreach (var a in anims.Values) foreach (var a in anims)
a.Animation.Animation.Tick(); a.Animation.Animation.Tick();
} }
public void Add(string key, AnimationWithOffset anim, string palette = null, bool isPlayerPalette = false) public void Add(AnimationWithOffset anim, string palette = null, bool isPlayerPalette = false)
{ {
// Use defaults // Use defaults
if (palette == null) if (palette == null)
@@ -190,12 +190,12 @@ namespace OpenRA.Mods.Common.Traits
isPlayerPalette = info.Palette == null; isPlayerPalette = info.Palette == null;
} }
anims.Add(key, new AnimationWrapper(anim, palette, isPlayerPalette)); anims.Add(new AnimationWrapper(anim, palette, isPlayerPalette));
} }
public void Remove(string key) public void Remove(AnimationWithOffset anim)
{ {
anims.Remove(key); anims.RemoveAll(a => a.Animation == anim);
} }
public static string NormalizeSequence(Animation anim, DamageState state, string sequence) public static string NormalizeSequence(Animation anim, DamageState state, string sequence)
@@ -228,7 +228,7 @@ namespace OpenRA.Mods.Common.Traits
// Required by RenderSimple // Required by RenderSimple
protected int2 AutoSelectionSize(Actor self) protected int2 AutoSelectionSize(Actor self)
{ {
return anims.Values.Where(b => b.IsVisible return anims.Where(b => b.IsVisible
&& b.Animation.Animation.CurrentSequence != null) && b.Animation.Animation.CurrentSequence != null)
.Select(a => (a.Animation.Animation.Image.Size * info.Scale).ToInt2()) .Select(a => (a.Animation.Animation.Image.Size * info.Scale).ToInt2())
.FirstOrDefault(); .FirstOrDefault();

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
anim = new Animation(self.World, rs.GetImage(self), () => turreted.TurretFacing); anim = new Animation(self.World, rs.GetImage(self), () => turreted.TurretFacing);
anim.Play(info.Sequence); anim.Play(info.Sequence);
rs.Add("barrel_{0}".F(info.Barrel), new AnimationWithOffset( rs.Add(new AnimationWithOffset(
anim, () => BarrelOffset(), null, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 0))); anim, () => BarrelOffset(), null, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 0)));
// Restrict turret facings to match the sprite // Restrict turret facings to match the sprite

View File

@@ -44,12 +44,13 @@ namespace OpenRA.Mods.Common.Traits
buildComplete = !self.HasTrait<Building>(); // always render instantly for units buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self)); overlay = new Animation(self.World, rs.GetImage(self));
var anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete);
overlay.Play(info.Sequence); overlay.Play(info.Sequence);
rs.Add("crane_overlay_{0}".F(info.Sequence), rs.Add(anim, info.Palette, info.IsPlayerPalette);
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete),
info.Palette, info.IsPlayerPalette);
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
var images = info.XmasImages.Any() && DateTime.Today.Month == 12 ? info.XmasImages : info.Images; var images = info.XmasImages.Any() && DateTime.Today.Month == 12 ? info.XmasImages : info.Images;
anim = new Animation(self.World, images.Random(Game.CosmeticRandom)); anim = new Animation(self.World, images.Random(Game.CosmeticRandom));
anim.Play("idle"); anim.Play("idle");
rs.Add("crate", anim); rs.Add(anim);
} }
public void OnLanded() public void OnLanded()

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var fire = new Animation(self.World, rs.GetImage(self)); var fire = new Animation(self.World, rs.GetImage(self));
fire.PlayThen(info.StartSequence, () => fire.PlayRepeating(info.LoopSequence)); fire.PlayThen(info.StartSequence, () => fire.PlayRepeating(info.LoopSequence));
rs.Add("fire", new AnimationWithOffset(fire, null, null, 1024)); rs.Add(new AnimationWithOffset(fire, null, null, 1024));
} }
} }
} }

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
anim = new Animation(self.World, rs.GetImage(self), RenderSimple.MakeFacingFunc(self)); anim = new Animation(self.World, rs.GetImage(self), RenderSimple.MakeFacingFunc(self));
anim.IsDecoration = true; anim.IsDecoration = true;
anim.Play(info.Sequence); anim.Play(info.Sequence);
rs.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim, rs.Add(new AnimationWithOffset(anim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !visible, () => !visible,
() => false, () => false,

View File

@@ -68,13 +68,14 @@ namespace OpenRA.Mods.Common.Traits
buildComplete = !self.HasTrait<Building>(); // always render instantly for units buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self)); overlay = new Animation(self.World, rs.GetImage(self));
overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence)); overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, self.GetDamageState(), info.Sequence));
rs.Add("idle_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, var anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => IsTraitDisabled || !buildComplete, () => IsTraitDisabled || !buildComplete,
() => info.PauseOnLowPower && self.IsDisabled(), () => info.PauseOnLowPower && self.IsDisabled(),
p => WithTurret.ZOffsetFromCenter(self, p, 1)), p => WithTurret.ZOffsetFromCenter(self, p, 1));
info.Palette, info.IsPlayerPalette);
rs.Add(anim, info.Palette, info.IsPlayerPalette);
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
DefaultAnimation = new Animation(init.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self)); DefaultAnimation = new Animation(init.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self));
rs.Add("", DefaultAnimation); rs.Add(DefaultAnimation);
DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(init.Self, info.StandSequences.Random(Game.CosmeticRandom)), () => 0); DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(init.Self, info.StandSequences.Random(Game.CosmeticRandom)), () => 0);
state = AnimationState.Waiting; state = AnimationState.Waiting;

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.TS.Traits
var buildingInfo = self.Info.Traits.Get<BuildingInfo>(); var buildingInfo = self.Info.Traits.Get<BuildingInfo>();
var offset = FootprintUtils.CenterOffset(self.World, buildingInfo).Y + 512; var offset = FootprintUtils.CenterOffset(self.World, buildingInfo).Y + 512;
renderSprites.Add("door_overlay_{0}".F(info.Sequence), new AnimationWithOffset(door, null, () => !buildComplete, offset)); renderSprites.Add(new AnimationWithOffset(door, null, () => !buildComplete, offset));
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)

View File

@@ -54,11 +54,12 @@ namespace OpenRA.Mods.Common.Traits
overlay = new Animation(self.World, rs.GetImage(self)); overlay = new Animation(self.World, rs.GetImage(self));
overlay.PlayRepeating(info.Sequence); overlay.PlayRepeating(info.Sequence);
rs.Add("production_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, var anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !IsProducing || !buildComplete), () => !IsProducing || !buildComplete);
info.Palette, info.IsPlayerPalette);
rs.Add(anim, info.Palette, info.IsPlayerPalette);
} }
public void Tick(Actor self) public void Tick(Actor self)

View File

@@ -48,13 +48,14 @@ namespace OpenRA.Mods.Common.Traits
buildComplete = !self.HasTrait<Building>(); // always render instantly for units buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self)); overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence); overlay.Play(info.Sequence);
rs.Add("repair_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, var anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete, () => !buildComplete,
() => info.PauseOnLowPower && self.IsDisabled(), () => info.PauseOnLowPower && self.IsDisabled(),
p => WithTurret.ZOffsetFromCenter(self, p, 1)), p => WithTurret.ZOffsetFromCenter(self, p, 1));
info.Palette, info.IsPlayerPalette);
rs.Add(anim, info.Palette, info.IsPlayerPalette);
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)

View File

@@ -24,9 +24,10 @@ namespace OpenRA.Mods.Common.Traits
class WithResources : INotifyBuildComplete, INotifySold, INotifyOwnerChanged, INotifyDamageStateChanged class WithResources : INotifyBuildComplete, INotifySold, INotifyOwnerChanged, INotifyDamageStateChanged
{ {
WithResourcesInfo info; readonly WithResourcesInfo info;
Animation anim; readonly AnimationWithOffset anim;
RenderSimple rs; readonly RenderSimple rs;
PlayerResources playerResources; PlayerResources playerResources;
bool buildComplete; bool buildComplete;
@@ -36,15 +37,14 @@ namespace OpenRA.Mods.Common.Traits
rs = self.Trait<RenderSimple>(); rs = self.Trait<RenderSimple>();
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>(); playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
anim = new Animation(self.World, rs.GetImage(self)); var a = new Animation(self.World, rs.GetImage(self));
anim.PlayFetchIndex(info.Sequence, a.PlayFetchIndex(info.Sequence, () =>
() => playerResources.ResourceCapacity != 0 ?
playerResources.ResourceCapacity != 0 ? ((10 * a.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity) :
((10 * anim.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity) : 0);
0);
rs.Add("resources_{0}".F(info.Sequence), new AnimationWithOffset( anim = new AnimationWithOffset(a, null, () => !buildComplete, 1024);
anim, null, () => !buildComplete, 1024)); rs.Add(anim);
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)
@@ -54,8 +54,8 @@ namespace OpenRA.Mods.Common.Traits
public void DamageStateChanged(Actor self, AttackInfo e) public void DamageStateChanged(Actor self, AttackInfo e)
{ {
if (anim.CurrentSequence != null) if (anim.Animation.CurrentSequence != null)
anim.ReplaceAnim(rs.NormalizeSequence(self, info.Sequence)); anim.Animation.ReplaceAnim(rs.NormalizeSequence(self, info.Sequence));
} }
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
playerResources = newOwner.PlayerActor.Trait<PlayerResources>(); playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
} }
public void Selling(Actor self) { rs.Remove("resources_{0}".F(info.Sequence)); } public void Selling(Actor self) { rs.Remove(anim); }
public void Sold(Actor self) { } public void Sold(Actor self) { }
} }
} }

View File

@@ -28,9 +28,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Position relative to body")] [Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero; public readonly WVec Offset = WVec.Zero;
[Desc("Change this when using this trait multiple times on the same actor.")]
public readonly string Id = "rotor";
public object Create(ActorInitializer init) { return new WithRotor(init.Self, this); } public object Create(ActorInitializer init) { return new WithRotor(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)
@@ -61,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
rotorAnim = new Animation(self.World, rs.GetImage(self)); rotorAnim = new Animation(self.World, rs.GetImage(self));
rotorAnim.PlayRepeating(info.Sequence); rotorAnim.PlayRepeating(info.Sequence);
rs.Add(info.Id, new AnimationWithOffset(rotorAnim, rs.Add(new AnimationWithOffset(rotorAnim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
null, () => false, p => ZOffsetFromCenter(self, p, 1))); null, () => false, p => ZOffsetFromCenter(self, p, 1)));
} }

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
anim = new Animation(self.World, info.Sequence); anim = new Animation(self.World, info.Sequence);
rs.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking)); rs.Add(new AnimationWithOffset(anim, null, () => !isSmoking));
} }
public void Damaged(Actor self, AttackInfo e) public void Damaged(Actor self, AttackInfo e)

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
anim = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing); anim = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing);
anim.Play(info.Sequence); anim.Play(info.Sequence);
rs.Add("turret_{0}_{1}".F(info.Turret, info.Sequence), new AnimationWithOffset( rs.Add(new AnimationWithOffset(
anim, () => TurretOffset(self), () => IsTraitDisabled, () => false, p => ZOffsetFromCenter(self, p, 1))); anim, () => TurretOffset(self), () => IsTraitDisabled, () => false, p => ZOffsetFromCenter(self, p, 1)));
// Restrict turret facings to match the sprite // Restrict turret facings to match the sprite

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits
var anim = new Animation(init.World, rs.GetImage(self), () => (int)facing); var anim = new Animation(init.World, rs.GetImage(self), () => (int)facing);
anim.PlayRepeating(info.Anim); anim.PlayRepeating(info.Anim);
rs.Add(info.Anim, new AnimationWithOffset(anim, () => pos, null)); rs.Add(new AnimationWithOffset(anim, () => pos, null));
} }
public void Tick(Actor self) public void Tick(Actor self)

View File

@@ -45,8 +45,7 @@ namespace OpenRA.Mods.D2k.Traits
overlay = new Animation(init.World, renderSprites.GetImage(init.Self)); overlay = new Animation(init.World, renderSprites.GetImage(init.Self));
var key = "attack_overlay_{0}".F(info.Sequence); renderSprites.Add(new AnimationWithOffset(overlay, null, () => !attacking),
renderSprites.Add(key, new AnimationWithOffset(overlay, null, () => !attacking),
info.Palette, info.IsPlayerPalette); info.Palette, info.IsPlayerPalette);
} }

View File

@@ -38,16 +38,15 @@ namespace OpenRA.Mods.D2k.Traits
if (init.Contains<SkipMakeAnimsInit>()) if (init.Contains<SkipMakeAnimsInit>())
return; return;
var key = "make_overlay_{0}".F(info.Sequence);
var rs = init.Self.Trait<RenderSprites>(); var rs = init.Self.Trait<RenderSprites>();
var overlay = new Animation(init.World, rs.GetImage(init.Self)); var overlay = new Animation(init.World, rs.GetImage(init.Self));
var anim = new AnimationWithOffset(overlay, null, () => !buildComplete);
// Remove the animation once it is complete // Remove the animation once it is complete
overlay.PlayThen(info.Sequence, () => init.World.AddFrameEndTask(w => rs.Remove(key))); overlay.PlayThen(info.Sequence, () => init.World.AddFrameEndTask(w => rs.Remove(anim)));
rs.Add(key, new AnimationWithOffset(overlay, null, () => !buildComplete), rs.Add(anim, info.Palette, info.IsPlayerPalette);
info.Palette, info.IsPlayerPalette);
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)

View File

@@ -35,9 +35,11 @@ namespace OpenRA.Mods.D2k.Traits
public class WithDeliveryOverlay : INotifyBuildComplete, INotifySold, INotifyDelivery public class WithDeliveryOverlay : INotifyBuildComplete, INotifySold, INotifyDelivery
{ {
WithDeliveryOverlayInfo info; readonly WithDeliveryOverlayInfo info;
Animation overlay; readonly AnimationWithOffset anim;
bool buildComplete, delivering;
bool buildComplete;
bool delivering;
public WithDeliveryOverlay(Actor self, WithDeliveryOverlayInfo info) public WithDeliveryOverlay(Actor self, WithDeliveryOverlayInfo info)
{ {
@@ -46,21 +48,23 @@ namespace OpenRA.Mods.D2k.Traits
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>(); var body = self.Trait<IBodyOrientation>();
buildComplete = !self.HasTrait<Building>(); // always render instantly for units // always render instantly for units
buildComplete = !self.HasTrait<Building>();
overlay = new Animation(self.World, rs.GetImage(self)); var overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence); overlay.Play(info.Sequence);
rs.Add("delivery_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete), () => !buildComplete);
info.Palette, info.IsPlayerPalette);
rs.Add(anim, info.Palette, info.IsPlayerPalette);
} }
void PlayDeliveryOverlay() void PlayDeliveryOverlay()
{ {
if (delivering) if (delivering)
overlay.PlayThen(info.Sequence, PlayDeliveryOverlay); anim.Animation.PlayThen(info.Sequence, PlayDeliveryOverlay);
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)

View File

@@ -35,9 +35,10 @@ namespace OpenRA.Mods.D2k.Traits
public class WithDockingOverlay : INotifyDocking, INotifyBuildComplete, INotifySold public class WithDockingOverlay : INotifyDocking, INotifyBuildComplete, INotifySold
{ {
WithDockingOverlayInfo info; readonly WithDockingOverlayInfo info;
Animation overlay; readonly AnimationWithOffset anim;
bool buildComplete, docked; bool buildComplete;
bool docked;
public WithDockingOverlay(Actor self, WithDockingOverlayInfo info) public WithDockingOverlay(Actor self, WithDockingOverlayInfo info)
{ {
@@ -48,19 +49,20 @@ namespace OpenRA.Mods.D2k.Traits
buildComplete = !self.HasTrait<Building>(); // always render instantly for units buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self)); var overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence); overlay.Play(info.Sequence);
rs.Add("docking_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete), () => !buildComplete);
info.Palette, info.IsPlayerPalette);
rs.Add(anim, info.Palette, info.IsPlayerPalette);
} }
void PlayDockingOverlay() void PlayDockingOverlay()
{ {
if (docked) if (docked)
overlay.PlayThen(info.Sequence, PlayDockingOverlay); anim.Animation.PlayThen(info.Sequence, PlayDockingOverlay);
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)