From 152ff32ded11ce2024dc5fbeea4cb78c87e4a391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Fri, 1 Jan 2016 15:31:58 +0100 Subject: [PATCH] add the Tiberian Sun harvester unload overlay --- .../Activities/VoxelHarvesterDockSequence.cs | 35 ++++++++++- OpenRA.Mods.TS/OpenRA.Mods.TS.csproj | 1 + .../Traits/Render/WithDockingOverlay.cs | 59 +++++++++++++++++++ mods/ts/rules/shared-structures.yaml | 1 + mods/ts/sequences/structures.yaml | 8 ++- 5 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 OpenRA.Mods.TS/Traits/Render/WithDockingOverlay.cs diff --git a/OpenRA.Mods.TS/Activities/VoxelHarvesterDockSequence.cs b/OpenRA.Mods.TS/Activities/VoxelHarvesterDockSequence.cs index c586124321..6c718fc8f4 100644 --- a/OpenRA.Mods.TS/Activities/VoxelHarvesterDockSequence.cs +++ b/OpenRA.Mods.TS/Activities/VoxelHarvesterDockSequence.cs @@ -10,6 +10,7 @@ using OpenRA.Activities; using OpenRA.Mods.Common.Activities; +using OpenRA.Mods.Common.Traits; using OpenRA.Mods.TS.Traits; namespace OpenRA.Mods.TS.Activities @@ -17,24 +18,52 @@ namespace OpenRA.Mods.TS.Activities public class VoxelHarvesterDockSequence : HarvesterDockSequence { readonly WithVoxelUnloadBody body; + readonly WithDockingOverlay spriteOverlay; public VoxelHarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength) : base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength) { body = self.Trait(); + spriteOverlay = refinery.TraitOrDefault(); } public override Activity OnStateDock(Actor self) { body.Docked = true; - dockingState = State.Loop; + + if (spriteOverlay != null && !spriteOverlay.Visible) + { + spriteOverlay.Visible = true; + spriteOverlay.WithOffset.Animation.PlayThen(spriteOverlay.Info.Sequence, () => { + dockingState = State.Loop; + spriteOverlay.Visible = false; + }); + } + else + dockingState = State.Loop; + return this; } public override Activity OnStateUndock(Actor self) { - body.Docked = false; - dockingState = State.Complete; + dockingState = State.Wait; + + if (spriteOverlay != null && !spriteOverlay.Visible) + { + spriteOverlay.Visible = true; + spriteOverlay.WithOffset.Animation.PlayBackwardsThen(spriteOverlay.Info.Sequence, () => { + dockingState = State.Complete; + body.Docked = false; + spriteOverlay.Visible = false; + }); + } + else + { + dockingState = State.Complete; + body.Docked = false; + } + return this; } } diff --git a/OpenRA.Mods.TS/OpenRA.Mods.TS.csproj b/OpenRA.Mods.TS/OpenRA.Mods.TS.csproj index 0e35f2499b..26839244af 100644 --- a/OpenRA.Mods.TS/OpenRA.Mods.TS.csproj +++ b/OpenRA.Mods.TS/OpenRA.Mods.TS.csproj @@ -69,6 +69,7 @@ + diff --git a/OpenRA.Mods.TS/Traits/Render/WithDockingOverlay.cs b/OpenRA.Mods.TS/Traits/Render/WithDockingOverlay.cs new file mode 100644 index 0000000000..8a11e4818e --- /dev/null +++ b/OpenRA.Mods.TS/Traits/Render/WithDockingOverlay.cs @@ -0,0 +1,59 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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.Graphics; +using OpenRA.Mods.Common.Traits; +using OpenRA.Traits; + +namespace OpenRA.Mods.TS.Traits +{ + [Desc("Rendered on the refinery when a voxel harvester is docking and undocking.")] + public class WithDockingOverlayInfo : ITraitInfo, Requires, Requires + { + [Desc("Sequence name to use")] + [SequenceReference] public readonly string Sequence = "unload-overlay"; + + [Desc("Position relative to body")] + public readonly WVec Offset = WVec.Zero; + + [Desc("Custom palette name")] + [PaletteReference("IsPlayerPalette")] public readonly string Palette = null; + + [Desc("Custom palette is a player palette BaseName")] + public readonly bool IsPlayerPalette = false; + + public object Create(ActorInitializer init) { return new WithDockingOverlay(init.Self, this); } + } + + public class WithDockingOverlay + { + public readonly WithDockingOverlayInfo Info; + public readonly AnimationWithOffset WithOffset; + + public bool Visible; + + public WithDockingOverlay(Actor self, WithDockingOverlayInfo info) + { + Info = info; + + var rs = self.Trait(); + var body = self.Trait(); + + var overlay = new Animation(self.World, rs.GetImage(self)); + overlay.Play(info.Sequence); + + WithOffset = new AnimationWithOffset(overlay, + () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), + () => !Visible); + + rs.Add(WithOffset, info.Palette, info.IsPlayerPalette); + } + } +} \ No newline at end of file diff --git a/mods/ts/rules/shared-structures.yaml b/mods/ts/rules/shared-structures.yaml index 025cb0da39..a95b7e5014 100644 --- a/mods/ts/rules/shared-structures.yaml +++ b/mods/ts/rules/shared-structures.yaml @@ -94,6 +94,7 @@ PROC: WithDockedOverlay@FLAME: Sequence: flame Palette: effect + WithDockingOverlay@UNLOAD: Power: Amount: -30 ProvidesPrerequisite@buildingname: diff --git a/mods/ts/sequences/structures.yaml b/mods/ts/sequences/structures.yaml index 22bbce2af9..7953c39ac0 100644 --- a/mods/ts/sequences/structures.yaml +++ b/mods/ts/sequences/structures.yaml @@ -1038,7 +1038,6 @@ nahpad: Offset: 0, 0 UseTilesetCode: false -# TODO: unused narefn_a proc.gdi: Defaults: ntrefn Offset: -12, -42 @@ -1057,6 +1056,9 @@ proc.gdi: ShadowStart: 20 flame: ntrefn_b Length: * + unload-overlay: narefn_a + Length: * + ZOffset: 1024 idle-redlights: ntrefn_c Length: 16 Tick: 120 @@ -1078,7 +1080,6 @@ proc.gdi: Offset: 0, 0 UseTilesetCode: false -# TODO: unused narefn_a proc.nod: Defaults: ntrefn Offset: -12, -42 @@ -1097,6 +1098,9 @@ proc.nod: ShadowStart: 20 flame: ntrefn_b Length: * + unload-overlay: narefn_a + Length: * + ZOffset: 1024 idle-redlights: ntrefn_c Length: 16 Tick: 120