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; }
|
||||
}
|
||||
}
|
||||
@@ -18,69 +18,45 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Transform : CancelableActivity
|
||||
{
|
||||
string actor = null;
|
||||
int2 offset;
|
||||
string[] sounds = null;
|
||||
int facing;
|
||||
public readonly string ToActor = null;
|
||||
public int2 Offset = new int2(0,0);
|
||||
public int Facing = 96;
|
||||
public string[] Sounds = {};
|
||||
|
||||
RenderBuilding rb;
|
||||
public Transform(Actor self, string toActor, int2 offset, int facing, string[] sounds)
|
||||
public Transform(Actor self, string toActor)
|
||||
{
|
||||
this.actor = toActor;
|
||||
this.offset = offset;
|
||||
this.sounds = sounds;
|
||||
this.facing = facing;
|
||||
rb = self.TraitOrDefault<RenderBuilding>();
|
||||
this.ToActor = toActor;
|
||||
}
|
||||
|
||||
void DoTransform(Actor self)
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
// Hack: repeat the first frame of the make anim instead
|
||||
// of flashing the full structure for a frame
|
||||
if (rb != null)
|
||||
rb.PlayCustomAnim(self, "make");
|
||||
if (IsCanceled) return NextActivity;
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var selected = w.Selection.Contains(self);
|
||||
|
||||
self.Destroy();
|
||||
foreach (var s in sounds)
|
||||
foreach (var s in Sounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
|
||||
var init = new TypeDictionary
|
||||
{
|
||||
new LocationInit( self.Location + offset ),
|
||||
new LocationInit( self.Location + Offset ),
|
||||
new OwnerInit( self.Owner ),
|
||||
new FacingInit( facing ),
|
||||
new FacingInit( Facing ),
|
||||
};
|
||||
if (self.HasTrait<Health>())
|
||||
init.Add( new HealthInit( self.Trait<Health>().HPFraction ));
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
// TODO: fix potential desync from HPFraction
|
||||
if (health != null)
|
||||
init.Add( new HealthInit( health.HPFraction ));
|
||||
|
||||
var a = w.CreateActor( actor, init );
|
||||
var a = w.CreateActor( ToActor, init );
|
||||
|
||||
if (selected)
|
||||
w.Selection.Add(w, a);
|
||||
});
|
||||
}
|
||||
|
||||
bool started = false;
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (started) return this;
|
||||
|
||||
if (rb == null)
|
||||
DoTransform(self);
|
||||
else
|
||||
{
|
||||
rb.PlayCustomAnimBackwards(self, "make", () => DoTransform(self));
|
||||
|
||||
foreach (var s in self.Info.Traits.Get<BuildingInfo>().SellSounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
|
||||
started = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,6 +341,7 @@
|
||||
<Compile Include="Render\WithShadow.cs" />
|
||||
<Compile Include="AnnounceOnBuild.cs" />
|
||||
<Compile Include="Capturable.cs" />
|
||||
<Compile Include="Activities\MakeAnimation.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -13,6 +13,7 @@ using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -79,7 +80,10 @@ namespace OpenRA.Mods.RA
|
||||
if (self.HasTrait<IFacing>())
|
||||
self.QueueActivity(new Turn(Info.Facing));
|
||||
|
||||
self.QueueActivity(new Transform(self, Info.IntoActor, Info.Offset, Info.Facing, Info.TransformSounds));
|
||||
if (self.HasTrait<RenderBuilding>() && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
|
||||
self.QueueActivity(new MakeAnimation(self, true));
|
||||
|
||||
self.QueueActivity(new Transform(self, Info.IntoActor) {Offset = Info.Offset, Facing = Info.Facing, Sounds = Info.TransformSounds});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user