From cb4e4d7bd9603d2d6098ae448d4f5bb25d39d4a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Tue, 13 Aug 2013 16:14:13 +0200 Subject: [PATCH] added idle render overlays for d2k and ts buildings --- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + OpenRA.Mods.RA/Render/WithIdleOverlay.cs | 50 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 OpenRA.Mods.RA/Render/WithIdleOverlay.cs diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 6f78829aae..1657810019 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -465,6 +465,7 @@ + diff --git a/OpenRA.Mods.RA/Render/WithIdleOverlay.cs b/OpenRA.Mods.RA/Render/WithIdleOverlay.cs new file mode 100644 index 0000000000..db9e79b741 --- /dev/null +++ b/OpenRA.Mods.RA/Render/WithIdleOverlay.cs @@ -0,0 +1,50 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 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 OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Render +{ + public class WithIdleOverlayInfo : ITraitInfo, Requires + { + [Desc("Sequence name to use")] + public readonly string Sequence = "idle-overlay"; + + [Desc("Position relative to body")] + public readonly WVec Offset = WVec.Zero; + + public object Create(ActorInitializer init) { return new WithIdleOverlay(init.self, this); } + } + + public class WithIdleOverlay : INotifyDamageStateChanged + { + Animation overlay; + + public WithIdleOverlay(Actor self, WithIdleOverlayInfo info) + { + var rs = self.Trait(); + var body = self.Trait(); + + overlay = new Animation(rs.GetImage(self)); + overlay.PlayRepeating(info.Sequence); + rs.anims.Add("idle_overlay_{0}".F(info.Sequence), + new AnimationWithOffset(overlay, + () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), + null, p => WithTurret.ZOffsetFromCenter(self, p, 1))); + } + + public void DamageStateChanged(Actor self, AttackInfo e) + { + overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name)); + } + } +} \ No newline at end of file