From 4a0b7bb00372f3089770d2483c1371a978c92a01 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 17 Jul 2011 16:53:29 +1200 Subject: [PATCH] put AnimationWithOffset in its own file --- OpenRA.Game/Graphics/AnimationWithOffset.cs | 51 +++++++++++++++++++ OpenRA.Game/OpenRA.Game.csproj | 3 +- OpenRA.Game/Traits/Render/RenderSimple.cs | 35 ------------- OpenRA.Mods.Cnc/WithFire.cs | 2 +- OpenRA.Mods.Cnc/WithRoof.cs | 2 +- OpenRA.Mods.RA/Burns.cs | 2 +- .../Render/RenderBuildingWarFactory.cs | 2 +- OpenRA.Mods.RA/Render/WithMuzzleFlash.cs | 4 +- OpenRA.Mods.RA/Render/WithRotor.cs | 2 +- OpenRA.Mods.RA/Render/WithSmoke.cs | 2 +- OpenRA.Mods.RA/ThrowsParticles.cs | 2 +- 11 files changed, 62 insertions(+), 45 deletions(-) create mode 100644 OpenRA.Game/Graphics/AnimationWithOffset.cs diff --git a/OpenRA.Game/Graphics/AnimationWithOffset.cs b/OpenRA.Game/Graphics/AnimationWithOffset.cs new file mode 100644 index 0000000000..4f55ede6dc --- /dev/null +++ b/OpenRA.Game/Graphics/AnimationWithOffset.cs @@ -0,0 +1,51 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using OpenRA.Traits; + +namespace OpenRA.Graphics +{ + public class AnimationWithOffset + { + public Animation Animation; + public Func OffsetFunc; + public Func DisableFunc; + public int ZOffset; + + public AnimationWithOffset(Animation a) + : this(a, null, null) + { + } + + public AnimationWithOffset(Animation a, Func o, Func d) + { + this.Animation = a; + this.OffsetFunc = o; + this.DisableFunc = d; + } + + public Renderable Image(Actor self, string pal) + { + var p = self.CenterLocation; + var loc = p - 0.5f * Animation.Image.size + + (OffsetFunc != null ? OffsetFunc() : float2.Zero); + var r = new Renderable(Animation.Image, loc, pal, p.Y); + + return ZOffset != 0 ? r.WithZOffset(ZOffset) : r; + } + + public static implicit operator AnimationWithOffset(Animation a) + { + return new AnimationWithOffset(a); + } + } +} + diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index feb8b8b4b9..c9c034fc8a 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -1,4 +1,4 @@ - + Debug @@ -185,6 +185,7 @@ + diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 0787e82158..3ee337babb 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -105,40 +105,5 @@ namespace OpenRA.Traits anim.PlayThen(NormalizeSequence(self, name), () => anim.PlayRepeating(NormalizeSequence(self, "idle"))); } - - public class AnimationWithOffset - { - public Animation Animation; - public Func OffsetFunc; - public Func DisableFunc; - public int ZOffset; - - public AnimationWithOffset(Animation a) - : this(a, null, null) - { - } - - public AnimationWithOffset(Animation a, Func o, Func d) - { - this.Animation = a; - this.OffsetFunc = o; - this.DisableFunc = d; - } - - public Renderable Image(Actor self, string pal) - { - var p = self.CenterLocation; - var loc = p - 0.5f * Animation.Image.size - + (OffsetFunc != null ? OffsetFunc() : float2.Zero); - var r = new Renderable(Animation.Image, loc, pal, p.Y); - - return ZOffset != 0 ? r.WithZOffset(ZOffset) : r; - } - - public static implicit operator AnimationWithOffset(Animation a) - { - return new AnimationWithOffset(a); - } - } } } diff --git a/OpenRA.Mods.Cnc/WithFire.cs b/OpenRA.Mods.Cnc/WithFire.cs index c9d96e1f80..7a3df42e72 100644 --- a/OpenRA.Mods.Cnc/WithFire.cs +++ b/OpenRA.Mods.Cnc/WithFire.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc var rs = self.Trait(); var roof = new Animation(rs.GetImage(self)); roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop")); - rs.anims.Add( "fire", new RenderSimple.AnimationWithOffset( roof, () => new float2(7,-15), null ) { ZOffset = 24 } ); + rs.anims.Add( "fire", new AnimationWithOffset( roof, () => new float2(7,-15), null ) { ZOffset = 24 } ); } } } diff --git a/OpenRA.Mods.Cnc/WithRoof.cs b/OpenRA.Mods.Cnc/WithRoof.cs index 337f5f7697..210adbff7e 100644 --- a/OpenRA.Mods.Cnc/WithRoof.cs +++ b/OpenRA.Mods.Cnc/WithRoof.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc var rs = self.Trait(); var roof = new Animation(rs.GetImage(self), () => self.Trait().Facing); roof.Play("roof"); - rs.anims.Add( "roof", new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 24 } ); + rs.anims.Add( "roof", new AnimationWithOffset( roof ) { ZOffset = 24 } ); } } } diff --git a/OpenRA.Mods.RA/Burns.cs b/OpenRA.Mods.RA/Burns.cs index a47f0f0680..9b09817913 100644 --- a/OpenRA.Mods.RA/Burns.cs +++ b/OpenRA.Mods.RA/Burns.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA var anim = new Animation("fire", () => 0); anim.PlayRepeating(self.Info.Traits.Get().Anim); self.Trait().anims.Add("fire", - new RenderSimple.AnimationWithOffset(anim, () => new float2(0, -3), null)); + new AnimationWithOffset(anim, () => new float2(0, -3), null)); } if (--ticks <= 0) diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index c479ea0a5d..3724dd1814 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Render : base(init, info) { roof = new Animation(GetImage(init.self)); - var offset = new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 24 }; + var offset = new AnimationWithOffset( roof ) { ZOffset = 24 }; offset.DisableFunc = () => !buildComplete; anims.Add("roof", offset); } diff --git a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs index 7449085f19..c2ce4a0082 100644 --- a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render class WithMuzzleFlash : INotifyAttack, IRender, ITick { - Dictionary muzzleFlashes = new Dictionary(); + Dictionary muzzleFlashes = new Dictionary(); bool isShowing; public WithMuzzleFlash(Actor self) @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Render var muzzleFlash = new Animation(render.GetImage(self), getFacing); muzzleFlash.Play("muzzle"); - muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new RenderSimple.AnimationWithOffset( + muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new AnimationWithOffset( muzzleFlash, () => Combat.GetBarrelPosition(self, facing, turret, barrel), () => !isShowing)); diff --git a/OpenRA.Mods.RA/Render/WithRotor.cs b/OpenRA.Mods.RA/Render/WithRotor.cs index 02e066d112..d65cba2071 100755 --- a/OpenRA.Mods.RA/Render/WithRotor.cs +++ b/OpenRA.Mods.RA/Render/WithRotor.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render rotorAnim = new Animation(rs.GetImage(self)); rotorAnim.PlayRepeating("rotor"); - rs.anims.Add(info.Id, new RenderSimple.AnimationWithOffset( + rs.anims.Add(info.Id, new AnimationWithOffset( rotorAnim, () => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)), null ) { ZOffset = 1 } ); diff --git a/OpenRA.Mods.RA/Render/WithSmoke.cs b/OpenRA.Mods.RA/Render/WithSmoke.cs index c48de88cd1..9f84e056d7 100644 --- a/OpenRA.Mods.RA/Render/WithSmoke.cs +++ b/OpenRA.Mods.RA/Render/WithSmoke.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Render var rs = self.Trait(); anim = new Animation("smoke_m"); - rs.anims.Add("smoke", new RenderSimple.AnimationWithOffset( + rs.anims.Add("smoke", new AnimationWithOffset( anim, null, () => !isSmoking)); } diff --git a/OpenRA.Mods.RA/ThrowsParticles.cs b/OpenRA.Mods.RA/ThrowsParticles.cs index 5ccb2f80ac..2eb32fcb88 100644 --- a/OpenRA.Mods.RA/ThrowsParticles.cs +++ b/OpenRA.Mods.RA/ThrowsParticles.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA var anim = new Animation(ru.GetImage(self), () => (int)facing); anim.PlayRepeating(info.Anim); - ru.anims.Add(info.AnimKey, new RenderSimple.AnimationWithOffset( + ru.anims.Add(info.AnimKey, new AnimationWithOffset( anim, () => pos - new float2(0, alt), null)); info = null;