From eb6d9f6f69827f7d33393947a0600faacd8cb329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 18 Apr 2014 11:25:42 +0200 Subject: [PATCH] only show welding overlays when factories are producing closes #3756 --- OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj | 1 + .../Render/WithProductionOverlay.cs | 95 +++++++++++++++++++ mods/d2k/rules/structures.yaml | 12 +-- mods/d2k/sequences/structures.yaml | 20 ++-- 4 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 OpenRA.Mods.D2k/Render/WithProductionOverlay.cs diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index 3fa3718043..1cd3725cac 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -83,6 +83,7 @@ + diff --git a/OpenRA.Mods.D2k/Render/WithProductionOverlay.cs b/OpenRA.Mods.D2k/Render/WithProductionOverlay.cs new file mode 100644 index 0000000000..8d4351e172 --- /dev/null +++ b/OpenRA.Mods.D2k/Render/WithProductionOverlay.cs @@ -0,0 +1,95 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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 System.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Mods.RA.Buildings; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Render +{ + public class WithProductionOverlayInfo : ITraitInfo, Requires, Requires + { + [Desc("Sequence name to use")] + public readonly string Sequence = "production-overlay"; + + [Desc("Position relative to body")] + public readonly WVec Offset = WVec.Zero; + + public object Create(ActorInitializer init) { return new WithProductionOverlay(init.self, this); } + } + + public class WithProductionOverlay : INotifyDamageStateChanged, ITick, INotifyBuildComplete, INotifySold + { + Animation overlay; + ProductionQueue queue; + bool buildComplete; + + bool IsProducing + { + get { return queue != null && queue.CurrentItem() != null && !queue.CurrentPaused; } + } + + public WithProductionOverlay(Actor self, WithProductionOverlayInfo info) + { + var rs = self.Trait(); + var body = self.Trait(); + + buildComplete = !self.HasTrait(); // always render instantly for units + + overlay = new Animation(rs.GetImage(self)); + overlay.PlayRepeating(info.Sequence); + rs.anims.Add("production_overlay_{0}".F(info.Sequence), + new AnimationWithOffset(overlay, + () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), + () => !IsProducing || !buildComplete)); + } + + public void Tick(Actor self) + { + // search for the queue here once so we don't rely on order of trait initialization + if (queue == null) + { + var production = self.TraitOrDefault(); + + var perBuildingQueues = self.TraitsImplementing(); + queue = perBuildingQueues.FirstOrDefault(q => production.Info.Produces.Contains(q.Info.Type)); + + if (queue == null) + { + var perPlayerQueues = self.Owner.PlayerActor.TraitsImplementing(); + queue = perPlayerQueues.FirstOrDefault(q => production.Info.Produces.Contains(q.Info.Type)); + } + + if (queue == null) + throw new InvalidOperationException("Can't find production queues."); + } + } + + public void BuildingComplete(Actor self) + { + buildComplete = true; + } + + public void Sold(Actor self) { } + public void Selling(Actor self) + { + buildComplete = false; + } + + public void DamageStateChanged(Actor self, AttackInfo e) + { + overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name)); + } + } +} \ No newline at end of file diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index b32e2388a1..6e9ef558e9 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -260,8 +260,8 @@ CONCRETEB: ProductionBar: ProvidesCustomPrerequisite: Prerequisite: Light - WithIdleOverlay@WELDING: - Sequence: idle-welding + WithProductionOverlay@WELDING: + Sequence: production-welding ^HEAVY: Inherits: ^Building @@ -300,8 +300,8 @@ CONCRETEB: ProductionBar: ProvidesCustomPrerequisite: Prerequisite: Heavy - WithIdleOverlay@WELDING: - Sequence: idle-welding + WithProductionOverlay@WELDING: + Sequence: production-welding ^RADAR: Inherits: ^Building @@ -603,8 +603,8 @@ WALL: Range: 4c0 ProvidesCustomPrerequisite: Prerequisite: Hitech - WithIdleOverlay@WELDING: - Sequence: idle-welding +# WithProductionOverlay@WELDING: +# Sequence: production-welding ^RESEARCH: Inherits: ^Building diff --git a/mods/d2k/sequences/structures.yaml b/mods/d2k/sequences/structures.yaml index f92d6b34a7..b6674bdce2 100644 --- a/mods/d2k/sequences/structures.yaml +++ b/mods/d2k/sequences/structures.yaml @@ -514,7 +514,7 @@ hightecha: damaged-idle: DATA Start: 2565 Offset: -48,80 - idle-welding: DATA + production-welding: DATA Start: 4614 Length: 30 Offset: -48,80 @@ -690,7 +690,7 @@ lighta: damaged-idle-top: DATA Start: 2675 Offset: -48,64 - idle-welding: DATA + production-welding: DATA Start: 4644 Length: 30 Offset: -48,64 @@ -739,7 +739,7 @@ heavya: damaged-idle-top: DATA Start: 2520 Offset: -48,80 - idle-welding: DATA + production-welding: DATA Start: 4674 Length: 47 Offset: -48,80 @@ -1005,7 +1005,7 @@ hightechh: damaged-idle: DATA Start: 2725 Offset: -48,80 - idle-welding: DATA + production-welding: DATA Start: 4614 Length: 30 Offset: -48,80 @@ -1090,7 +1090,7 @@ lighth: damaged-idle-top: DATA Start: 2835 Offset: -48,64 - idle-welding: DATA + production-welding: DATA Start: 4644 Length: 30 Offset: -48,64 @@ -1139,7 +1139,7 @@ heavyh: damaged-idle-top: DATA Start: 2680 Offset: -48,80 - idle-welding: DATA + production-welding: DATA Start: 4674 Length: 47 Offset: -48,80 @@ -1406,7 +1406,7 @@ hightecho: damaged-idle: DATA Start: 2885 Offset: -48,80 - idle-welding: DATA + production-welding: DATA Start: 4614 Length: 30 Offset: -48,80 @@ -1483,7 +1483,7 @@ lighto: damaged-idle-top: DATA Start: 2995 Offset: -48,64 - idle-welding: DATA + production-welding: DATA Start: 4644 Length: 30 Offset: -48,64 @@ -1532,7 +1532,7 @@ heavyo: damaged-idle-top: DATA Start: 2840 Offset: -48,80 - idle-welding: DATA + production-welding: DATA Start: 4674 Length: 47 Offset: -48,80 @@ -1647,7 +1647,7 @@ heavyc: # TODO: unused damaged-idle-top: DATA Start: 3003 Offset: -48,64 - idle-welding: DATA + production-welding: DATA Start: 4674 Length: 47 Offset: -48,80