new trait WithMakeAnimation

This commit is contained in:
Matthias Mailänder
2014-07-03 20:46:38 +02:00
parent 87fd576b26
commit 394d635dae
22 changed files with 156 additions and 122 deletions

View File

@@ -1,71 +0,0 @@
#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 System;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class MakeAnimation : Activity
{
readonly bool Reversed;
readonly Action OnComplete;
RenderBuilding rb;
public MakeAnimation(Actor self, Action onComplete) : this(self, false, onComplete) {}
public MakeAnimation(Actor self, bool reversed, Action onComplete)
{
Reversed = reversed;
OnComplete = onComplete;
}
bool complete = false;
bool started = false;
public override Activity Tick(Actor self)
{
if (self.IsDead())
return NextActivity;
if (started)
{
// Don't break the actor if someone has overriden the animation prematurely
if (rb.DefaultAnimation.CurrentSequence.Name != "make")
{
complete = true;
OnComplete();
}
return complete ? NextActivity : this;
}
started = true;
rb = self.Trait<RenderBuilding>();
if (Reversed)
{
// TODO: These don't belong here
var bi = self.Info.Traits.GetOrDefault<BuildingInfo>();
if (bi != null)
foreach (var s in bi.SellSounds)
Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
rb.PlayCustomAnimBackwards(self, "make", () => { OnComplete(); complete = true;});
}
else
rb.PlayCustomAnimThen(self, "make", () => { OnComplete(); complete = true;});
return this;
}
// Cannot be cancelled
public override void Cancel(Actor self) { }
}
}

View File

@@ -76,8 +76,8 @@ namespace OpenRA.Mods.RA.Activities
init.Add(new RuntimeCargoInit(cargo.Passengers.ToArray()));
var a = w.CreateActor(ToActor, init);
foreach (var nt in self.TraitsImplementing<INotifyTransformed>())
nt.OnTransformed(a);
foreach (var nt in self.TraitsImplementing<INotifyTransform>())
nt.AfterTransform(a);
if (selected)
w.Selection.Add(w, a);

View File

@@ -34,8 +34,9 @@ namespace OpenRA.Mods.RA.Buildings
public readonly bool RequiresBaseProvider = false;
public readonly bool AllowInvalidPlacement = false;
public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"};
public readonly string[] SellSounds = {"cashturn.aud"};
public readonly string[] BuildSounds = { "placbldg.aud", "build5.aud" };
public readonly string[] SellSounds = { "cashturn.aud" };
public readonly string[] UndeploySounds = { "cashturn.aud" };
public object Create(ActorInitializer init) { return new Building(init, this); }
@@ -99,7 +100,7 @@ namespace OpenRA.Mods.RA.Buildings
}
}
public class Building : INotifyDamage, IOccupySpace, INotifyCapture, INotifyBuildComplete, INotifySold, ISync, ITechTreePrerequisite, INotifyAddedToWorld, INotifyRemovedFromWorld
public class Building : INotifyDamage, IOccupySpace, INotifyCapture, INotifyBuildComplete, INotifySold, INotifyTransform, ISync, ITechTreePrerequisite, INotifyAddedToWorld, INotifyRemovedFromWorld
{
public readonly BuildingInfo Info;
public bool BuildComplete { get; private set; }
@@ -185,7 +186,21 @@ namespace OpenRA.Mods.RA.Buildings
Locked = false;
}
public void Selling(Actor self) { BuildComplete = false; }
public void Selling(Actor self)
{
foreach (var s in Info.SellSounds)
Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
BuildComplete = false;
}
public void Sold(Actor self) { }
public void BeforeTransform(Actor self)
{
foreach (var s in Info.UndeploySounds)
Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
}
public void OnTransform(Actor self) { }
public void AfterTransform(Actor self) { }
}
}

View File

@@ -100,7 +100,6 @@
<Compile Include="Activities\Infiltrate.cs" />
<Compile Include="Activities\LayMines.cs" />
<Compile Include="Activities\Leap.cs" />
<Compile Include="Activities\MakeAnimation.cs" />
<Compile Include="Activities\MoveAdjacentTo.cs" />
<Compile Include="Activities\RAHarvesterDockSequence.cs" />
<Compile Include="Activities\Rearm.cs" />
@@ -519,6 +518,7 @@
<Compile Include="Lint\CheckMapCordon.cs" />
<Compile Include="World\ResourceLayer.cs" />
<Compile Include="Parachutable.cs" />
<Compile Include="Render\WithMakeAnimation.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -140,7 +140,10 @@ namespace OpenRA.Mods.RA
public void Killed(Actor killed, AttackInfo e) { if (killed == self) ClearQueue(); }
public void Selling(Actor self) { }
public void Sold(Actor self) { ClearQueue(); }
public void BeforeTransform(Actor self) { }
public void OnTransform(Actor self) { ClearQueue(); }
public void AfterTransform(Actor self) { }
void CacheProduceables(Actor playerActor)
{

View File

@@ -19,7 +19,6 @@ namespace OpenRA.Mods.RA.Render
{
public class RenderBuildingInfo : RenderSimpleInfo, Requires<BuildingInfo>, IPlaceBuildingDecoration
{
public readonly bool HasMakeAnimation = true;
public readonly bool PauseOnLowPower = false;
public override object Create(ActorInitializer init) { return new RenderBuilding(init, this);}
@@ -34,9 +33,11 @@ namespace OpenRA.Mods.RA.Render
}
}
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete
{
RenderBuildingInfo info;
bool buildComplete;
bool skipMakeAnimation;
public RenderBuilding(ActorInitializer init, RenderBuildingInfo info)
: this(init, info, () => 0) { }
@@ -46,24 +47,27 @@ namespace OpenRA.Mods.RA.Render
{
var self = init.self;
this.info = info;
skipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
// Work around a bogus crash
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
// Can't call Complete() directly from ctor because other traits haven't been inited yet
if (self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation && !init.Contains<SkipMakeAnimsInit>())
self.QueueActivity(new MakeAnimation(self, () => Complete(self)));
else
self.QueueActivity(new CallFunc(() => Complete(self)));
}
void Complete(Actor self)
public override void TickRender(WorldRenderer wr, Actor self)
{
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
foreach (var x in self.TraitsImplementing<INotifyBuildComplete>())
x.BuildingComplete(self);
base.TickRender(wr, self);
if (buildComplete)
return;
buildComplete = true;
if (!self.HasTrait<WithMakeAnimation>() || skipMakeAnimation)
foreach (var notify in self.TraitsImplementing<INotifyBuildComplete>())
notify.BuildingComplete(self);
}
public virtual void BuildingComplete(Actor self)
{
if (info.PauseOnLowPower)
{
var disabled = self.TraitsImplementing<IDisable>();

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Render
playerResources = init.self.Owner.PlayerActor.Trait<PlayerResources>();
}
public void BuildingComplete(Actor self)
public override void BuildingComplete(Actor self)
{
var animation = (self.GetDamageState() >= DamageState.Heavy) ? "damaged-idle" : "idle";

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render
public override object Create(ActorInitializer init) { return new RenderBuildingWall(init, this); }
}
class RenderBuildingWall : RenderBuilding, INotifyBuildComplete, INotifyAddedToWorld, INotifyRemovedFromWorld
class RenderBuildingWall : RenderBuilding, INotifyAddedToWorld, INotifyRemovedFromWorld
{
readonly RenderBuildingWallInfo info;
int adjacent = 0;
@@ -34,9 +34,10 @@ namespace OpenRA.Mods.RA.Render
this.info = info;
}
public void BuildingComplete(Actor self)
public override void BuildingComplete(Actor self)
{
DefaultAnimation.PlayFetchIndex(info.Sequence, () => adjacent);
UpdateNeighbours(self);
}
public override void DamageStateChanged(Actor self, AttackInfo e)

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Render
() => !buildComplete, offset));
}
public void BuildingComplete( Actor self )
public override void BuildingComplete(Actor self)
{
roof.Play(NormalizeSequence(self,
self.GetDamageState() > DamageState.Heavy ? "damaged-idle-top" : "idle-top"));

View File

@@ -0,0 +1,64 @@
#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 (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);
});
}
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* 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,
@@ -34,15 +34,16 @@ namespace OpenRA.Mods.RA
if (!self.Trait<Building>().Lock())
return;
self.CancelActivity();
foreach (var ns in self.TraitsImplementing<INotifySold>())
ns.Selling(self);
self.CancelActivity();
var rb = self.TraitOrDefault<RenderBuilding>();
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make")));
self.QueueActivity(new Sell());
var makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
if (makeAnimation != null)
makeAnimation.Reverse(self, new Sell());
else
self.QueueActivity(new Sell());
}
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* 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,
@@ -47,8 +47,7 @@ namespace OpenRA.Mods.RA
}
public interface INotifyParachuteLanded { void OnLanded(); }
public interface INotifyTransform { void OnTransform(Actor self); }
public interface INotifyTransformed { void OnTransformed(Actor toActor); }
public interface INotifyTransform { void BeforeTransform(Actor self); void OnTransform(Actor self); void AfterTransform(Actor toActor); }
public interface INotifyAttack { void Attacking(Actor self, Target target, Armament a, Barrel barrel); }
public interface INotifyChat { bool OnChat(string from, string message); }
}

View File

@@ -88,11 +88,15 @@ namespace OpenRA.Mods.RA
if (self.HasTrait<IFacing>())
self.QueueActivity(new Turn(info.Facing));
var rb = self.TraitOrDefault<RenderBuilding>();
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make")));
foreach (var nt in self.TraitsImplementing<INotifyTransform>())
nt.BeforeTransform(self);
self.QueueActivity(new Transform(self, info.IntoActor) { Offset = info.Offset, Facing = info.Facing, Sounds = info.TransformSounds, Race = race });
var transform = new Transform(self, info.IntoActor) { Offset = info.Offset, Facing = info.Facing, Sounds = info.TransformSounds, Race = race };
var makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
if (makeAnimation != null)
makeAnimation.Reverse(self, transform);
else
self.QueueActivity(transform);
}
public void ResolveOrder(Actor self, Order order)

View File

@@ -252,6 +252,20 @@ namespace OpenRA.Utility
node.Key = "StoresResources";
}
// make animation is now it's own trait
if (engineVersion < 20140621)
{
if (depth == 1 && (node.Key.StartsWith("RenderBuilding")))
node.Value.Nodes.RemoveAll(n => n.Key == "HasMakeAnimation");
if (node.Value.Nodes.Any(n => n.Key.StartsWith("RenderBuilding"))
&& !node.Value.Nodes.Any(n => n.Key == "RenderBuildingWall")
&& !node.Value.Nodes.Any(n => n.Key == "WithMakeAnimation"))
{
node.Value.Nodes.Add(new MiniYamlNode("WithMakeAnimation", new MiniYaml("")));
}
}
// ParachuteAttachment was merged into Parachutable
if (engineVersion < 20140701)
{

View File

@@ -355,6 +355,7 @@
LuaScriptEvents:
Demolishable:
ScriptTriggers:
WithMakeAnimation:
^BaseBuilding:
Inherits: ^Building
@@ -395,6 +396,7 @@
StartsRevealed: true
LuaScriptEvents:
ScriptTriggers:
WithMakeAnimation:
^TechBuilding:
Inherits: ^CivBuilding
@@ -418,6 +420,7 @@
Palette: terrain
EditorAppearance:
UseTerrainPalette: true
WithMakeAnimation:
^CivFieldHusk:
AppearsOnRadar:
@@ -436,6 +439,7 @@
StartsRevealed: true
LuaScriptEvents:
ScriptTriggers:
WithMakeAnimation:
^Wall:
AppearsOnRadar:
@@ -456,7 +460,6 @@
LineBuildNode:
Types: wall
RenderBuildingWall:
HasMakeAnimation: false
Palette: staticterrain
GivesExperience:
EditorAppearance:
@@ -493,6 +496,7 @@
StartsRevealed: true
LuaScriptEvents:
ScriptTriggers:
WithMakeAnimation:
^TibTree:
Tooltip:
@@ -510,6 +514,7 @@
FrozenUnderFog:
StartsRevealed: true
LuaScriptEvents:
WithMakeAnimation:
^Rock:
Tooltip:
@@ -529,6 +534,7 @@
StartsRevealed: true
LuaScriptEvents:
ScriptTriggers:
WithMakeAnimation:
^Husk:
Health:

View File

@@ -94,4 +94,5 @@ MISS:
Cost: 2000
Bib:
HasMinibib: Yes
WithMakeAnimation:

View File

@@ -67,19 +67,16 @@ T01:
EditorTilesetFilter:
ExcludeTilesets: DESERT
T02:
Inherits: ^Tree
EditorTilesetFilter:
ExcludeTilesets: DESERT
T03:
Inherits: ^Tree
EditorTilesetFilter:
ExcludeTilesets: DESERT
T04:
Inherits: ^Tree
@@ -88,19 +85,16 @@ T05:
EditorTilesetFilter:
ExcludeTilesets: DESERT
T06:
Inherits: ^Tree
EditorTilesetFilter:
ExcludeTilesets: DESERT
T07:
Inherits: ^Tree
EditorTilesetFilter:
ExcludeTilesets: DESERT
T08:
Inherits: ^Tree
Building:

View File

@@ -280,4 +280,5 @@
Pieces: 3, 7
Range: 2c0, 5c0
ScriptTriggers:
WithMakeAnimation:

View File

@@ -116,6 +116,7 @@ SPICEBLOOM:
RadarColorFromTerrain:
Terrain: Spice
BodyOrientation:
WithMakeAnimation:
CAMERA:
Immobile:

View File

@@ -426,7 +426,6 @@ CONCRETEB:
TargetableBuilding:
TargetTypes: Ground
RenderBuildingWall:
HasMakeAnimation: false
Image: walla
EditorAppearance:
RelativeToTopLeft: yes
@@ -476,7 +475,6 @@ WALL:
RenderRangeCircle:
-RenderBuilding:
RenderBuildingWall:
HasMakeAnimation: false
BodyOrientation:
QuantizedFacings: 32
WithTurret:
@@ -528,7 +526,6 @@ WALL:
RenderRangeCircle:
-RenderBuilding:
RenderBuildingWall:
HasMakeAnimation: false
BodyOrientation:
QuantizedFacings: 32
WithTurret:
@@ -720,7 +717,6 @@ PALACEC:
Footprint: xxx xxx
Dimensions: 3,2
RenderBuilding:
HasMakeAnimation: false
HEAVYC:
Inherits: ^HEAVY

View File

@@ -274,6 +274,7 @@
DamagedSound: kaboom1.aud
DestroyedSound: kaboom22.aud
RenderBuilding:
WithMakeAnimation:
WithBuildingExplosion:
RepairableBuilding:
EngineerRepairable:
@@ -324,7 +325,6 @@
TargetableBuilding:
TargetTypes: Ground, DetonateAttack
RenderBuildingWall:
HasMakeAnimation: false
Palette: terrain
GivesExperience:
EditorAppearance:
@@ -352,6 +352,7 @@
Name: Civilian Building
ProximityCaptor:
Types: CivilianBuilding
-WithMakeAnimation:
-AcceptsSupplies:
-GivesBuildableArea:
-Sellable:

View File

@@ -40,6 +40,7 @@
LuaScriptEvents:
Demolishable:
ScriptTriggers:
WithMakeAnimation:
^Wall:
AppearsOnRadar:
@@ -65,7 +66,6 @@
TargetableBuilding:
TargetTypes: Ground, C4
RenderBuildingWall:
HasMakeAnimation: no
GivesExperience:
EditorAppearance:
RelativeToTopLeft: yes