Files
OpenRA/OpenRA.Mods.RA/Render/WithMakeAnimation.cs
2014-07-06 08:24:08 +02:00

68 lines
1.8 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2014 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 System;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class WithMakeAnimationInfo : ITraitInfo, Requires<RenderBuildingInfo>
{
[Desc("Sequence name to use")]
public readonly string Sequence = "make";
public object Create(ActorInitializer init) { return new WithMakeAnimation(init, this); }
}
public class WithMakeAnimation : ITickRender
{
WithMakeAnimationInfo info;
RenderBuilding building;
bool buildComplete;
public WithMakeAnimation(ActorInitializer init, WithMakeAnimationInfo info)
{
building = init.self.Trait<RenderBuilding>();
this.info = info;
buildComplete = init.Contains<SkipMakeAnimsInit>();
}
public void TickRender(WorldRenderer wr, Actor self)
{
if (wr.world.Paused == World.PauseState.Paused)
return;
if (self.IsDead() || buildComplete)
return;
buildComplete = true;
building.PlayCustomAnimThen(self, info.Sequence, () =>
{
foreach (var notify in self.TraitsImplementing<INotifyBuildComplete>())
notify.BuildingComplete(self);
});
}
public void Reverse(Actor self, Activity activity)
{
building.PlayCustomAnimBackwards(self, info.Sequence, () => {
building.PlayCustomAnim(self, info.Sequence); // avoids visual glitches as we wait for the actor to get destroyed
self.QueueActivity(activity);
});
}
}
}