Pull the make animation crap out of Transforms
This commit is contained in:
56
OpenRA.Mods.RA/Activities/MakeAnimation.cs
Normal file
56
OpenRA.Mods.RA/Activities/MakeAnimation.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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.FileFormats;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class MakeAnimation : CancelableActivity
|
||||
{
|
||||
readonly bool Reversed;
|
||||
readonly RenderBuilding rb;
|
||||
|
||||
public MakeAnimation(Actor self) : this(self, false) {}
|
||||
public MakeAnimation(Actor self, bool reversed)
|
||||
{
|
||||
Reversed = reversed;
|
||||
rb = self.Trait<RenderBuilding>();
|
||||
}
|
||||
|
||||
bool complete = false;
|
||||
bool started = false;
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (!started)
|
||||
{
|
||||
started = true;
|
||||
if (Reversed)
|
||||
{
|
||||
foreach (var s in self.Info.Traits.Get<BuildingInfo>().SellSounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
|
||||
// PlayCustomAnim is required to stop a frame of the normal state after the anim completes
|
||||
rb.PlayCustomAnimBackwards(self, "make", () => {rb.PlayCustomAnim(self, "make"); complete = true;});
|
||||
}
|
||||
else
|
||||
rb.PlayCustomAnimThen(self, "make", () => complete = true);
|
||||
}
|
||||
return complete ? NextActivity : this;
|
||||
}
|
||||
|
||||
// Not actually cancellable
|
||||
protected override bool OnCancel( Actor self ) { return false; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user