From 7c434507f16a04544212004de1402087beb8579e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 20 Jul 2014 18:28:28 +1200 Subject: [PATCH] Add support for idle overlays in actor previews. --- OpenRA.Mods.RA/Render/WithIdleOverlay.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Render/WithIdleOverlay.cs b/OpenRA.Mods.RA/Render/WithIdleOverlay.cs index 089e4109c7..b4e1eb2012 100644 --- a/OpenRA.Mods.RA/Render/WithIdleOverlay.cs +++ b/OpenRA.Mods.RA/Render/WithIdleOverlay.cs @@ -8,15 +8,17 @@ */ #endregion +using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.RA.Buildings; +using OpenRA.Mods.RA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { [Desc("Renders a decorative animation on units and buildings.")] - public class WithIdleOverlayInfo : ITraitInfo, Requires, Requires + public class WithIdleOverlayInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires, Requires { [Desc("Sequence name to use")] public readonly string Sequence = "idle-overlay"; @@ -33,6 +35,18 @@ namespace OpenRA.Mods.RA.Render public readonly bool PauseOnLowPower = false; public object Create(ActorInitializer init) { return new WithIdleOverlay(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 WithIdleOverlay : INotifyDamageStateChanged, INotifyBuildComplete, INotifySold