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

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

View File

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

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits
var rs = self.Trait<RenderSprites>();
anim = new Animation(self.World, rs.GetImage(self), () => turreted.TurretFacing);
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)));
// 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
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);
rs.Add("crane_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete),
info.Palette, info.IsPlayerPalette);
rs.Add(anim, info.Palette, info.IsPlayerPalette);
}
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;
anim = new Animation(self.World, images.Random(Game.CosmeticRandom));
anim.Play("idle");
rs.Add("crate", anim);
rs.Add(anim);
}
public void OnLanded()

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
var rs = self.Trait<RenderSprites>();
var fire = new Animation(self.World, rs.GetImage(self));
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.IsDecoration = true;
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))),
() => !visible,
() => false,

View File

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

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
var rs = self.Trait<RenderSprites>();
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);
state = AnimationState.Waiting;

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.TS.Traits
var buildingInfo = self.Info.Traits.Get<BuildingInfo>();
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)

View File

@@ -54,11 +54,12 @@ namespace OpenRA.Mods.Common.Traits
overlay = new Animation(self.World, rs.GetImage(self));
overlay.PlayRepeating(info.Sequence);
rs.Add("production_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !IsProducing || !buildComplete),
info.Palette, info.IsPlayerPalette);
var anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !IsProducing || !buildComplete);
rs.Add(anim, info.Palette, info.IsPlayerPalette);
}
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
overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence);
rs.Add("repair_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete,
() => info.PauseOnLowPower && self.IsDisabled(),
p => WithTurret.ZOffsetFromCenter(self, p, 1)),
info.Palette, info.IsPlayerPalette);
var anim = new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete,
() => info.PauseOnLowPower && self.IsDisabled(),
p => WithTurret.ZOffsetFromCenter(self, p, 1));
rs.Add(anim, info.Palette, info.IsPlayerPalette);
}
public void BuildingComplete(Actor self)

View File

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

View File

@@ -28,9 +28,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Position relative to body")]
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 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.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))),
null, () => false, p => ZOffsetFromCenter(self, p, 1)));
}

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
var rs = self.Trait<RenderSprites>();
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)

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
anim = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing);
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)));
// Restrict turret facings to match the sprite