Introduce WithSpriteBody trait
Add upgrade rules Add ISpriteBody
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class RenderFlareInfo : RenderSimpleInfo
|
||||
{
|
||||
public readonly string OpenSequence = "open";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new RenderFlare(init, this); }
|
||||
}
|
||||
|
||||
class RenderFlare : RenderSimple
|
||||
{
|
||||
public RenderFlare(ActorInitializer init, RenderFlareInfo info)
|
||||
: base(init, info, () => 0)
|
||||
{
|
||||
DefaultAnimation.PlayThen(info.OpenSequence, () => DefaultAnimation.PlayRepeating(info.Sequence));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override object Create(ActorInitializer init) { return new RenderUnit(init, this); }
|
||||
}
|
||||
|
||||
public class RenderUnit : RenderSimple
|
||||
public class RenderUnit : RenderSimple, ISpriteBody
|
||||
{
|
||||
readonly RenderUnitInfo info;
|
||||
|
||||
@@ -28,18 +28,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
||||
public void PlayCustomAnimation(Actor self, string newAnimation, Action after)
|
||||
{
|
||||
DefaultAnimation.PlayThen(newAnim, () => { DefaultAnimation.Play(info.Sequence); if (after != null) after(); });
|
||||
DefaultAnimation.PlayThen(newAnimation, () => { DefaultAnimation.Play(info.Sequence); if (after != null) after(); });
|
||||
}
|
||||
|
||||
public void PlayCustomAnimRepeating(Actor self, string name)
|
||||
public void PlayCustomAnimationRepeating(Actor self, string name)
|
||||
{
|
||||
DefaultAnimation.PlayThen(name,
|
||||
() => PlayCustomAnimRepeating(self, name));
|
||||
() => PlayCustomAnimationRepeating(self, name));
|
||||
}
|
||||
|
||||
public void PlayCustomAnimBackwards(Actor self, string name, Action after)
|
||||
public void PlayCustomAnimationBackwards(Actor self, string name, Action after)
|
||||
{
|
||||
DefaultAnimation.PlayBackwardsThen(name,
|
||||
() => { DefaultAnimation.PlayRepeating(info.Sequence); if (after != null) after(); });
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Renders a flame sprite on top of the actor.")]
|
||||
class WithFireInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
public readonly string StartSequence = "fire-start";
|
||||
public readonly string LoopSequence = "fire-loop";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithFire(init.Self, this); }
|
||||
}
|
||||
|
||||
class WithFire
|
||||
{
|
||||
public WithFire(Actor self, WithFireInfo info)
|
||||
{
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var fire = new Animation(self.World, rs.GetImage(self));
|
||||
fire.PlayThen(info.StartSequence, () => fire.PlayRepeating(info.LoopSequence));
|
||||
rs.Add(new AnimationWithOffset(fire, null, null, 1024));
|
||||
}
|
||||
}
|
||||
}
|
||||
70
OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs
Normal file
70
OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Default trait for rendering sprite-based actors.")]
|
||||
class WithSpriteBodyInfo : UpgradableTraitInfo, ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
[Desc("Animation to play when the actor is created.")]
|
||||
public readonly string StartSequence = null;
|
||||
|
||||
[Desc("Animation to play when the actor is idle.")]
|
||||
public readonly string Sequence = "idle";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithSpriteBody(init, this); }
|
||||
}
|
||||
|
||||
class WithSpriteBody : UpgradableTrait<WithSpriteBodyInfo>, ISpriteBody
|
||||
{
|
||||
readonly Animation body;
|
||||
readonly WithSpriteBodyInfo info;
|
||||
|
||||
public WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.info = info;
|
||||
|
||||
var rs = init.Self.Trait<RenderSprites>();
|
||||
body = new Animation(init.Self.World, rs.GetImage(init.Self));
|
||||
PlayCustomAnimation(init.Self, info.StartSequence, () => body.PlayRepeating(info.Sequence));
|
||||
rs.Add(new AnimationWithOffset(body, null, () => IsTraitDisabled));
|
||||
}
|
||||
|
||||
public void PlayCustomAnimation(Actor self, string newAnimation, Action after)
|
||||
{
|
||||
body.PlayThen(newAnimation, () =>
|
||||
{
|
||||
body.Play(info.Sequence);
|
||||
if (after != null)
|
||||
after();
|
||||
});
|
||||
}
|
||||
|
||||
public void PlayCustomAnimationRepeating(Actor self, string name)
|
||||
{
|
||||
body.PlayThen(name, () => PlayCustomAnimationRepeating(self, name));
|
||||
}
|
||||
|
||||
public void PlayCustomAnimationBackwards(Actor self, string name, Action after)
|
||||
{
|
||||
body.PlayBackwardsThen(name, () =>
|
||||
{
|
||||
body.PlayRepeating(info.Sequence);
|
||||
if (after != null)
|
||||
after();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user