From 0424b56af181df48c866405d9901b7746fa20ba3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 22 Jun 2013 17:56:24 +1200 Subject: [PATCH] Add WithHarvestAnimation for TS and D2K harvester animations. --- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + OpenRA.Mods.RA/Render/WithHarvestAnimation.cs | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 OpenRA.Mods.RA/Render/WithHarvestAnimation.cs diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 515a2c40e6..afcdaf3229 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -454,6 +454,7 @@ + diff --git a/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs b/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs new file mode 100644 index 0000000000..81c10a6455 --- /dev/null +++ b/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs @@ -0,0 +1,62 @@ +#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 System.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Render +{ + class WithHarvestAnimationInfo : ITraitInfo, Requires, Requires + { + [Desc("Sequence name to use")] + public readonly string Sequence = "harvest"; + + [Desc("Position relative to body")] + public readonly WVec Offset = WVec.Zero; + + [Desc("Additional draw-order offset")] + public readonly int ZOffset = 0; + + public object Create(ActorInitializer init) { return new WithHarvestAnimation(init.self, this); } + } + + class WithHarvestAnimation : INotifyHarvest + { + WithHarvestAnimationInfo info; + Animation anim; + bool visible; + + public WithHarvestAnimation(Actor self, WithHarvestAnimationInfo info) + { + this.info = info; + var rs = self.Trait(); + var body = self.Trait(); + + anim = new Animation(rs.GetImage(self), RenderSimple.MakeFacingFunc(self)); + anim.Play(info.Sequence); + rs.anims.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim, + () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), + () => !visible, + p => WithTurret.ZOffsetFromCenter(self, p, info.ZOffset))); + } + + public void Harvested(Actor self, ResourceType resource) + { + if (visible) + return; + + visible = true; + anim.PlayThen(info.Sequence, () => visible = false); + } + } +}