Add a deploy animation to DeployToUpgrade

Play a "deploy"/"undeploy" animation
This commit is contained in:
Pavel Penev
2015-08-21 16:45:18 +03:00
parent 3678e146cf
commit 7d59aaa00c

View File

@@ -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<ISpriteBody> body;
bool isUpgraded;
@@ -50,6 +55,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info;
manager = self.Trait<UpgradeManager>();
checkTerrainType = info.AllowedTerrainTypes.Length > 0;
body = Exts.Lazy(self.TraitOrDefault<ISpriteBody>);
}
public IEnumerable<IOrderTargeter> 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);
}
}
}