From 7d59aaa00cbbc9c4f31270f3e30a87573e34872f Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Fri, 21 Aug 2015 16:45:18 +0300 Subject: [PATCH] Add a deploy animation to DeployToUpgrade Play a "deploy"/"undeploy" animation --- .../Traits/Upgrades/DeployToUpgrade.cs | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs index 3599c9883e..7c047661b9 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenRA.Activities; using OpenRA.Mods.Common.Orders; using OpenRA.Traits; @@ -32,6 +33,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Cursor to display when unable to (un)deploy the actor.")] public readonly string DeployBlockedCursor = "deploy-blocked"; + [SequenceReference, Desc("Animation to play for deploying/undeploying.")] + public readonly string DeployAnimation = null; + public object Create(ActorInitializer init) { return new DeployToUpgrade(init.Self, this); } } @@ -41,6 +45,7 @@ namespace OpenRA.Mods.Common.Traits readonly DeployToUpgradeInfo info; readonly UpgradeManager manager; readonly bool checkTerrainType; + readonly Lazy body; bool isUpgraded; @@ -50,6 +55,7 @@ namespace OpenRA.Mods.Common.Traits this.info = info; manager = self.Trait(); checkTerrainType = info.AllowedTerrainTypes.Length > 0; + body = Exts.Lazy(self.TraitOrDefault); } public IEnumerable Orders @@ -75,11 +81,40 @@ namespace OpenRA.Mods.Common.Traits return; if (isUpgraded) - foreach (var up in info.Upgrades) - manager.RevokeUpgrade(self, up, this); + { + // Play undeploy animation and after that revoke the upgrades + self.QueueActivity(new CallFunc(() => + { + if (string.IsNullOrEmpty(info.DeployAnimation)) + { + RevokeUpgrades(); + return; + } + + if (body.Value != null) + body.Value.PlayCustomAnimationBackwards(self, info.DeployAnimation, RevokeUpgrades); + else + RevokeUpgrades(); + })); + } else - foreach (var up in info.Upgrades) - manager.GrantUpgrade(self, up, this); + { + self.CancelActivity(); + + // Grant the upgrade + self.QueueActivity(new CallFunc(GrantUpgrades)); + + // Play deploy animation + self.QueueActivity(new CallFunc(() => + { + if (string.IsNullOrEmpty(info.DeployAnimation)) + return; + + if (body.Value != null) + body.Value.PlayCustomAnimation(self, info.DeployAnimation, + () => body.Value.PlayCustomAnimationRepeating(self, "idle")); + })); + } isUpgraded = !isUpgraded; } @@ -98,5 +133,17 @@ namespace OpenRA.Mods.Common.Traits return info.AllowedTerrainTypes.Contains(terrainType); } + + void GrantUpgrades() + { + foreach (var up in info.Upgrades) + manager.GrantUpgrade(self, up, this); + } + + void RevokeUpgrades() + { + foreach (var up in info.Upgrades) + manager.RevokeUpgrade(self, up, this); + } } } \ No newline at end of file