From 3903b9b2b517de69d011f95b744fad33f279d8c7 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 20 Jul 2014 22:49:55 +1200 Subject: [PATCH] Add support for rotors in actor previews. --- OpenRA.Mods.RA/Render/WithRotor.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Render/WithRotor.cs b/OpenRA.Mods.RA/Render/WithRotor.cs index 31e196bd14..25b8559e84 100755 --- a/OpenRA.Mods.RA/Render/WithRotor.cs +++ b/OpenRA.Mods.RA/Render/WithRotor.cs @@ -8,13 +8,16 @@ */ #endregion +using System; +using System.Collections.Generic; using OpenRA.Graphics; +using OpenRA.Mods.RA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { [Desc("Displays a helicopter rotor overlay.")] - public class WithRotorInfo : ITraitInfo, Requires, Requires + public class WithRotorInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires, Requires { [Desc("Sequence name to use when flying")] public readonly string Sequence = "rotor"; @@ -29,6 +32,18 @@ namespace OpenRA.Mods.RA.Render public readonly string Id = "rotor"; public object Create(ActorInitializer init) { return new WithRotor(init.self, this); } + + public IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) + { + var body = init.Actor.Traits.Get(); + var facing = init.Contains() ? init.Get() : 0; + var anim = new Animation(init.World, image, () => facing); + anim.PlayRepeating(Sequence); + + var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings); + var offset = body.LocalToWorld(Offset.Rotate(orientation)); + yield return new SpriteActorPreview(anim, offset, offset.Y + offset.Z + 1, p, rs.Scale); + } } public class WithRotor : ITick