diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 81761d9c66..e97f5ea310 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -30,40 +30,34 @@ namespace OpenRA.Traits public class RenderSimple : RenderSprites, IAutoSelectionSize { - RenderSimpleInfo Info; + public readonly Animation DefaultAnimation; public RenderSimple(Actor self, Func baseFacing) : base(self) { - Add("", new Animation(self.World, GetImage(self), baseFacing)); - Info = self.Info.Traits.Get(); + DefaultAnimation = new Animation(self.World, GetImage(self), baseFacing); + Add("", DefaultAnimation); } public RenderSimple(Actor self) : this(self, MakeFacingFunc(self)) { - anim.PlayRepeating("idle"); - self.Trait().SetAutodetectedFacings(anim.CurrentSequence.Facings); + DefaultAnimation.PlayRepeating("idle"); + self.Trait().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings); } - public int2 SelectionSize(Actor self) - { - return anims.Values.Where(b => (b.DisableFunc == null || !b.DisableFunc()) - && b.Animation.CurrentSequence != null) - .Select(a => (a.Animation.Image.size*Info.Scale).ToInt2()) - .FirstOrDefault(); - } + public int2 SelectionSize(Actor self) { return AutoSelectionSize(self); } public string NormalizeSequence(Actor self, string baseSequence) { - return NormalizeSequence(anim, self.GetDamageState(), baseSequence); + return NormalizeSequence(DefaultAnimation, self.GetDamageState(), baseSequence); } public void PlayCustomAnim(Actor self, string name) { - if (anim.HasSequence(name)) - anim.PlayThen(NormalizeSequence(self, name), - () => anim.PlayRepeating(NormalizeSequence(self, "idle"))); + if (DefaultAnimation.HasSequence(name)) + DefaultAnimation.PlayThen(NormalizeSequence(self, name), + () => DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"))); } } } diff --git a/OpenRA.Game/Traits/Render/RenderSprites.cs b/OpenRA.Game/Traits/Render/RenderSprites.cs index 50fd4479e5..4fd7aa8dc7 100755 --- a/OpenRA.Game/Traits/Render/RenderSprites.cs +++ b/OpenRA.Game/Traits/Render/RenderSprites.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenRA.Graphics; using OpenRA.FileFormats; using OpenRA.Primitives; @@ -33,7 +34,7 @@ namespace OpenRA.Traits public class RenderSprites : IRender, ITick, INotifyOwnerChanged { - public Dictionary anims = new Dictionary(); + Dictionary anims = new Dictionary(); public static Func MakeFacingFunc(Actor self) { @@ -42,13 +43,6 @@ namespace OpenRA.Traits return () => facing.Facing; } - public Animation anim - { - get { return anims[""].Animation; } - protected set { anims[""] = new AnimationWithOffset(value, - anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].Paused, anims[""].ZOffset); } - } - RenderSpritesInfo Info; string cachedImage = null; bool initializePalette = true; @@ -131,5 +125,14 @@ namespace OpenRA.Traits return baseSequence; } + + // Required by RenderSimple + protected int2 AutoSelectionSize(Actor self) + { + return anims.Values.Where(b => (b.DisableFunc == null || !b.DisableFunc()) + && b.Animation.CurrentSequence != null) + .Select(a => (a.Animation.Image.size*Info.Scale).ToInt2()) + .FirstOrDefault(); + } } } diff --git a/OpenRA.Mods.RA/Activities/MakeAnimation.cs b/OpenRA.Mods.RA/Activities/MakeAnimation.cs index 11f4385553..2ebde3fc79 100644 --- a/OpenRA.Mods.RA/Activities/MakeAnimation.cs +++ b/OpenRA.Mods.RA/Activities/MakeAnimation.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Activities if (started) { // Don't break the actor if someone has overriden the animation prematurely - if (rb.anim.CurrentSequence.Name != "make") + if (rb.DefaultAnimation.CurrentSequence.Name != "make") { complete = true; OnComplete(); diff --git a/OpenRA.Mods.RA/Buildings/DeadBuildingState.cs b/OpenRA.Mods.RA/Buildings/DeadBuildingState.cs index a584fae188..62fc668a87 100644 --- a/OpenRA.Mods.RA/Buildings/DeadBuildingState.cs +++ b/OpenRA.Mods.RA/Buildings/DeadBuildingState.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Cnc { - class DeadBuildingStateInfo : ITraitInfo, Requires, Requires + class DeadBuildingStateInfo : ITraitInfo, Requires, Requires { public readonly int LingerTime = 20; @@ -23,23 +23,23 @@ namespace OpenRA.Mods.Cnc class DeadBuildingState : INotifyKilled { DeadBuildingStateInfo info; - RenderSprites rs; + RenderSimple rs; public DeadBuildingState(Actor self, DeadBuildingStateInfo info) { this.info = info; - rs = self.Trait(); - self.Trait().RemoveOnDeath = !rs.anim.HasSequence("dead"); + rs = self.Trait(); + self.Trait().RemoveOnDeath = !rs.DefaultAnimation.HasSequence("dead"); } public void Killed(Actor self, AttackInfo e) { - if (!rs.anim.HasSequence("dead")) return; + if (!rs.DefaultAnimation.HasSequence("dead")) return; - if (rs.anim.GetSequence("dead").Length > 1) - rs.anim.Play("dead"); + if (rs.DefaultAnimation.GetSequence("dead").Length > 1) + rs.DefaultAnimation.Play("dead"); else - rs.anim.PlayRepeating("dead"); + rs.DefaultAnimation.PlayRepeating("dead"); self.World.AddFrameEndTask( w => w.Add( diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index eb57e2d5ee..ddc36eb7d2 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -49,8 +49,8 @@ namespace OpenRA.Mods.RA.Render this.info = info; // Work around a bogus crash - anim.PlayRepeating(NormalizeSequence(self, "idle")); - self.Trait().SetAutodetectedFacings(anim.CurrentSequence.Facings); + DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); + self.Trait().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings); // Can't call Complete() directly from ctor because other traits haven't been inited yet if (self.Info.Traits.Get().HasMakeAnimation && !init.Contains()) @@ -61,45 +61,45 @@ namespace OpenRA.Mods.RA.Render void Complete(Actor self) { - anim.PlayRepeating(NormalizeSequence(self, "idle")); + DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); foreach (var x in self.TraitsImplementing()) x.BuildingComplete(self); if (info.PauseOnLowPower) { var disabled = self.TraitsImplementing(); - anim.Paused = () => disabled.Any(d => d.Disabled) - && anim.CurrentSequence.Name == NormalizeSequence(self, "idle"); + DefaultAnimation.Paused = () => disabled.Any(d => d.Disabled) + && DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, "idle"); } } public void PlayCustomAnimThen(Actor self, string name, Action a) { - anim.PlayThen(NormalizeSequence(self, name), - () => { anim.PlayRepeating(NormalizeSequence(self, "idle")); a(); }); + DefaultAnimation.PlayThen(NormalizeSequence(self, name), + () => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); a(); }); } public void PlayCustomAnimRepeating(Actor self, string name) { - anim.PlayThen(NormalizeSequence(self, name), + DefaultAnimation.PlayThen(NormalizeSequence(self, name), () => PlayCustomAnimRepeating(self, name)); } public void PlayCustomAnimBackwards(Actor self, string name, Action a) { - anim.PlayBackwardsThen(NormalizeSequence(self, name), - () => { anim.PlayRepeating(NormalizeSequence(self, "idle")); a(); }); + DefaultAnimation.PlayBackwardsThen(NormalizeSequence(self, name), + () => { DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); a(); }); } public void CancelCustomAnim(Actor self) { - anim.PlayRepeating(NormalizeSequence(self, "idle")); + DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); } public virtual void DamageStateChanged(Actor self, AttackInfo e) { - if (anim.CurrentSequence != null) - anim.ReplaceAnim(NormalizeSequence(self, "idle")); + if (DefaultAnimation.CurrentSequence != null) + DefaultAnimation.ReplaceAnim(NormalizeSequence(self, "idle")); } } } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingCharge.cs b/OpenRA.Mods.RA/Render/RenderBuildingCharge.cs index d356a9e97c..91c5f34330 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingCharge.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingCharge.cs @@ -35,8 +35,8 @@ namespace OpenRA.Mods.RA.Render public void PlayCharge(Actor self) { Sound.Play(info.ChargeAudio, self.CenterPosition); - anim.PlayThen(NormalizeSequence(self, info.ChargeSequence), - () => anim.PlayRepeating(NormalizeSequence(self, "idle"))); + DefaultAnimation.PlayThen(NormalizeSequence(self, info.ChargeSequence), + () => DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"))); } } } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingSilo.cs b/OpenRA.Mods.RA/Render/RenderBuildingSilo.cs index 79f7c1e026..7c524b5574 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingSilo.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingSilo.cs @@ -30,9 +30,9 @@ namespace OpenRA.Mods.RA.Render public void BuildingComplete(Actor self) { var animation = (self.GetDamageState() >= DamageState.Heavy) ? "damaged-idle" : "idle"; - anim.PlayFetchIndex(animation, + DefaultAnimation.PlayFetchIndex(animation, () => playerResources.OreCapacity != 0 - ? ((10 * anim.CurrentSequence.Length - 1) * playerResources.Ore) / (10 * playerResources.OreCapacity) + ? ((10 * DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Ore) / (10 * playerResources.OreCapacity) : 0); } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingTurreted.cs b/OpenRA.Mods.RA/Render/RenderBuildingTurreted.cs index 20b5f1f490..0c14873c40 100644 --- a/OpenRA.Mods.RA/Render/RenderBuildingTurreted.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingTurreted.cs @@ -34,13 +34,13 @@ namespace OpenRA.Mods.RA.Render : base(init, info, MakeTurretFacingFunc(init.self)) { t = init.self.TraitsImplementing().FirstOrDefault(); - t.QuantizedFacings = anim.CurrentSequence.Facings; + t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; } public override void DamageStateChanged(Actor self, AttackInfo e) { base.DamageStateChanged(self, e); - t.QuantizedFacings = anim.CurrentSequence.Facings; + t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings; } } } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWall.cs b/OpenRA.Mods.RA/Render/RenderBuildingWall.cs index a967180a99..4878729388 100644 --- a/OpenRA.Mods.RA/Render/RenderBuildingWall.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWall.cs @@ -35,12 +35,12 @@ namespace OpenRA.Mods.RA.Render public void BuildingComplete(Actor self) { - anim.PlayFetchIndex(info.Sequence, () => adjacent); + DefaultAnimation.PlayFetchIndex(info.Sequence, () => adjacent); } public override void DamageStateChanged(Actor self, AttackInfo e) { - anim.PlayFetchIndex(NormalizeSequence(anim, e.DamageState, info.Sequence), () => adjacent); + DefaultAnimation.PlayFetchIndex(NormalizeSequence(DefaultAnimation, e.DamageState, info.Sequence), () => adjacent); } public override void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Render/RenderDisguise.cs b/OpenRA.Mods.RA/Render/RenderDisguise.cs index 85f39b46f6..ed22c510fd 100644 --- a/OpenRA.Mods.RA/Render/RenderDisguise.cs +++ b/OpenRA.Mods.RA/Render/RenderDisguise.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Render if (disguise.AsSprite != intendedSprite) { intendedSprite = disguise.AsSprite; - anim.ChangeImage(intendedSprite ?? GetImage(self), info.StandAnimations.Random(Game.CosmeticRandom)); + DefaultAnimation.ChangeImage(intendedSprite ?? GetImage(self), info.StandAnimations.Random(Game.CosmeticRandom)); UpdatePalette(); } diff --git a/OpenRA.Mods.RA/Render/RenderFlare.cs b/OpenRA.Mods.RA/Render/RenderFlare.cs index 9475849bdb..a794e18e34 100755 --- a/OpenRA.Mods.RA/Render/RenderFlare.cs +++ b/OpenRA.Mods.RA/Render/RenderFlare.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render public RenderFlare(Actor self) : base(self, () => 0) { - anim.PlayThen("open", () => anim.PlayRepeating("idle")); + DefaultAnimation.PlayThen("open", () => DefaultAnimation.PlayRepeating("idle")); } } } diff --git a/OpenRA.Mods.RA/Render/RenderHarvester.cs b/OpenRA.Mods.RA/Render/RenderHarvester.cs index ba4cec2b98..cecbe613ba 100644 --- a/OpenRA.Mods.RA/Render/RenderHarvester.cs +++ b/OpenRA.Mods.RA/Render/RenderHarvester.cs @@ -40,15 +40,15 @@ namespace OpenRA.Mods.RA.Render var desiredState = harv.Fullness * (info.ImagesByFullness.Length - 1) / 100; var desiredImage = info.ImagesByFullness[desiredState]; - if (anim.Name != desiredImage) - anim.ChangeImage(desiredImage, "idle"); + if (DefaultAnimation.Name != desiredImage) + DefaultAnimation.ChangeImage(desiredImage, "idle"); base.Tick(self); } public void Harvested(Actor self, ResourceType resource) { - if (anim.CurrentSequence.Name != "harvest") + if (DefaultAnimation.CurrentSequence.Name != "harvest") PlayCustomAnim(self, "harvest"); } } diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index 358d6ccc38..5d688cc663 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -59,20 +59,20 @@ namespace OpenRA.Mods.RA.Render : base(self, MakeFacingFunc(self)) { this.info = info; - anim.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0); + DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0); State = AnimationState.Waiting; move = self.Trait(); - self.Trait().SetAutodetectedFacings(anim.CurrentSequence.Facings); + self.Trait().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings); } public void Attacking(Actor self, Target target) { State = AnimationState.Attacking; - if (anim.HasSequence(NormalizeInfantrySequence(self, "shoot"))) - anim.PlayThen(NormalizeInfantrySequence(self, "shoot"), () => State = AnimationState.Idle); - else if (anim.HasSequence(NormalizeInfantrySequence(self, "heal"))) - anim.PlayThen(NormalizeInfantrySequence(self, "heal"), () => State = AnimationState.Idle); + if (DefaultAnimation.HasSequence(NormalizeInfantrySequence(self, "shoot"))) + DefaultAnimation.PlayThen(NormalizeInfantrySequence(self, "shoot"), () => State = AnimationState.Idle); + else if (DefaultAnimation.HasSequence(NormalizeInfantrySequence(self, "heal"))) + DefaultAnimation.PlayThen(NormalizeInfantrySequence(self, "heal"), () => State = AnimationState.Idle); } public void Attacking(Actor self, Target target, Armament a, Barrel barrel) @@ -87,12 +87,12 @@ namespace OpenRA.Mods.RA.Render if ((State == AnimationState.Moving || dirty) && !move.IsMoving) { State = AnimationState.Waiting; - anim.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0); + DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0); } else if ((State != AnimationState.Moving || dirty) && move.IsMoving) { State = AnimationState.Moving; - anim.PlayRepeating(NormalizeInfantrySequence(self, "run")); + DefaultAnimation.PlayRepeating(NormalizeInfantrySequence(self, "run")); } dirty = false; @@ -102,7 +102,7 @@ namespace OpenRA.Mods.RA.Render { if (State != AnimationState.Idle && State != AnimationState.IdleAnimating) { - anim.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0); + DefaultAnimation.PlayFetchIndex(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom)), () => 0); State = AnimationState.Idle; if (info.IdleAnimations.Length > 0) @@ -113,12 +113,12 @@ namespace OpenRA.Mods.RA.Render } else if (AllowIdleAnimation(self) && idleDelay > 0 && --idleDelay == 0) { - if (anim.HasSequence(idleSequence)) + if (DefaultAnimation.HasSequence(idleSequence)) { State = AnimationState.IdleAnimating; - anim.PlayThen(idleSequence, () => + DefaultAnimation.PlayThen(idleSequence, () => { - anim.PlayRepeating(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom))); + DefaultAnimation.PlayRepeating(NormalizeInfantrySequence(self, info.StandAnimations.Random(Game.CosmeticRandom))); State = AnimationState.Waiting; }); } diff --git a/OpenRA.Mods.RA/Render/RenderInfantryPanic.cs b/OpenRA.Mods.RA/Render/RenderInfantryPanic.cs index 63322618db..8d3e424ded 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantryPanic.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantryPanic.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render { var prefix = sc != null && sc.Panicking ? "panic-" : ""; - if (anim.HasSequence(prefix + baseSequence)) + if (DefaultAnimation.HasSequence(prefix + baseSequence)) return prefix + baseSequence; else return baseSequence; diff --git a/OpenRA.Mods.RA/Render/RenderLandingCraft.cs b/OpenRA.Mods.RA/Render/RenderLandingCraft.cs index 869ba8566f..37c6b26d2a 100644 --- a/OpenRA.Mods.RA/Render/RenderLandingCraft.cs +++ b/OpenRA.Mods.RA/Render/RenderLandingCraft.cs @@ -51,20 +51,20 @@ namespace OpenRA.Mods.RA.Render void Open() { - if (open || !anim.HasSequence(info.OpenAnim)) + if (open || !DefaultAnimation.HasSequence(info.OpenAnim)) return; open = true; PlayCustomAnimation(self, info.OpenAnim, () => { - if (anim.HasSequence(info.UnloadAnim)) + if (DefaultAnimation.HasSequence(info.UnloadAnim)) PlayCustomAnimRepeating(self, info.UnloadAnim); }); } void Close() { - if (!open || !anim.HasSequence(info.OpenAnim)) + if (!open || !DefaultAnimation.HasSequence(info.OpenAnim)) return; open = false; diff --git a/OpenRA.Mods.RA/Render/RenderUnit.cs b/OpenRA.Mods.RA/Render/RenderUnit.cs index 81774fdcae..42a9d33fde 100644 --- a/OpenRA.Mods.RA/Render/RenderUnit.cs +++ b/OpenRA.Mods.RA/Render/RenderUnit.cs @@ -25,19 +25,19 @@ namespace OpenRA.Mods.RA.Render public void PlayCustomAnimation(Actor self, string newAnim, Action after) { - anim.PlayThen(newAnim, () => { anim.Play("idle"); if (after != null) after(); }); + DefaultAnimation.PlayThen(newAnim, () => { DefaultAnimation.Play("idle"); if (after != null) after(); }); } public void PlayCustomAnimRepeating(Actor self, string name) { - anim.PlayThen(name, + DefaultAnimation.PlayThen(name, () => { PlayCustomAnimRepeating(self, name); }); } public void PlayCustomAnimBackwards(Actor self, string name, Action after) { - anim.PlayBackwardsThen(name, - () => { anim.PlayRepeating("idle"); if (after != null) after(); }); + DefaultAnimation.PlayBackwardsThen(name, + () => { DefaultAnimation.PlayRepeating("idle"); if (after != null) after(); }); } } } diff --git a/OpenRA.Mods.RA/Render/RenderUnitReload.cs b/OpenRA.Mods.RA/Render/RenderUnitReload.cs index b3f9599c4a..bbb497a109 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitReload.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitReload.cs @@ -38,8 +38,8 @@ namespace OpenRA.Mods.RA.Render public override void Tick(Actor self) { var sequence = (armament.IsReloading ? "empty-" : "") + (attack.IsAttacking ? "aim" : "idle"); - if (sequence != anim.CurrentSequence.Name) - anim.ReplaceAnim(sequence); + if (sequence != DefaultAnimation.CurrentSequence.Name) + DefaultAnimation.ReplaceAnim(sequence); base.Tick(self); } diff --git a/OpenRA.Mods.RA/TakeCover.cs b/OpenRA.Mods.RA/TakeCover.cs index d5fe68a797..5e6fdc14c4 100644 --- a/OpenRA.Mods.RA/TakeCover.cs +++ b/OpenRA.Mods.RA/TakeCover.cs @@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA { var prefix = tc != null && tc.IsProne ? "prone-" : ""; - if (anim.HasSequence(prefix + baseSequence)) + if (DefaultAnimation.HasSequence(prefix + baseSequence)) return prefix + baseSequence; else return baseSequence;