Add a deploy animation to DeployToUpgrade
Play a "deploy"/"undeploy" animation
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.Activities;
|
||||||
using OpenRA.Mods.Common.Orders;
|
using OpenRA.Mods.Common.Orders;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -32,6 +33,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Cursor to display when unable to (un)deploy the actor.")]
|
[Desc("Cursor to display when unable to (un)deploy the actor.")]
|
||||||
public readonly string DeployBlockedCursor = "deploy-blocked";
|
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); }
|
public object Create(ActorInitializer init) { return new DeployToUpgrade(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly DeployToUpgradeInfo info;
|
readonly DeployToUpgradeInfo info;
|
||||||
readonly UpgradeManager manager;
|
readonly UpgradeManager manager;
|
||||||
readonly bool checkTerrainType;
|
readonly bool checkTerrainType;
|
||||||
|
readonly Lazy<ISpriteBody> body;
|
||||||
|
|
||||||
bool isUpgraded;
|
bool isUpgraded;
|
||||||
|
|
||||||
@@ -50,6 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
manager = self.Trait<UpgradeManager>();
|
manager = self.Trait<UpgradeManager>();
|
||||||
checkTerrainType = info.AllowedTerrainTypes.Length > 0;
|
checkTerrainType = info.AllowedTerrainTypes.Length > 0;
|
||||||
|
body = Exts.Lazy(self.TraitOrDefault<ISpriteBody>);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IOrderTargeter> Orders
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
@@ -75,11 +81,40 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (isUpgraded)
|
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
|
else
|
||||||
foreach (var up in info.Upgrades)
|
RevokeUpgrades();
|
||||||
manager.GrantUpgrade(self, up, this);
|
}));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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;
|
isUpgraded = !isUpgraded;
|
||||||
}
|
}
|
||||||
@@ -98,5 +133,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
return info.AllowedTerrainTypes.Contains(terrainType);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user