Add delay support to SpriteEffect
This commit is contained in:
@@ -23,31 +23,46 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
readonly Animation anim;
|
readonly Animation anim;
|
||||||
readonly Func<WPos> posFunc;
|
readonly Func<WPos> posFunc;
|
||||||
readonly bool visibleThroughFog;
|
readonly bool visibleThroughFog;
|
||||||
|
readonly string sequence;
|
||||||
WPos pos;
|
WPos pos;
|
||||||
|
int delay;
|
||||||
|
bool initialized;
|
||||||
|
|
||||||
// Facing is last on these overloads partially for backwards compatibility with previous main ctor revision
|
// Facing is last on these overloads partially for backwards compatibility with previous main ctor revision
|
||||||
// and partially because most effects don't need it.
|
// and partially because most effects don't need it. The latter is also the reason for placement of 'delay'.
|
||||||
public SpriteEffect(WPos pos, World world, string image, string sequence, string palette, bool visibleThroughFog = false, int facing = 0)
|
public SpriteEffect(WPos pos, World world, string image, string sequence, string palette,
|
||||||
: this(() => pos, () => facing, world, image, sequence, palette, visibleThroughFog) { }
|
bool visibleThroughFog = false, int facing = 0, int delay = 0)
|
||||||
|
: this(() => pos, () => facing, world, image, sequence, palette, visibleThroughFog, delay) { }
|
||||||
|
|
||||||
public SpriteEffect(Actor actor, World world, string image, string sequence, string palette, bool visibleThroughFog = false, int facing = 0)
|
public SpriteEffect(Actor actor, World world, string image, string sequence, string palette,
|
||||||
: this(() => actor.CenterPosition, () => facing, world, image, sequence, palette, visibleThroughFog) { }
|
bool visibleThroughFog = false, int facing = 0, int delay = 0)
|
||||||
|
: this(() => actor.CenterPosition, () => facing, world, image, sequence, palette, visibleThroughFog, delay) { }
|
||||||
|
|
||||||
public SpriteEffect(Func<WPos> posFunc, Func<int> facingFunc, World world, string image, string sequence, string palette,
|
public SpriteEffect(Func<WPos> posFunc, Func<int> facingFunc, World world, string image, string sequence, string palette,
|
||||||
bool visibleThroughFog = false)
|
bool visibleThroughFog = false, int delay = 0)
|
||||||
{
|
{
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.posFunc = posFunc;
|
this.posFunc = posFunc;
|
||||||
this.palette = palette;
|
this.palette = palette;
|
||||||
|
this.sequence = sequence;
|
||||||
this.visibleThroughFog = visibleThroughFog;
|
this.visibleThroughFog = visibleThroughFog;
|
||||||
|
this.delay = delay;
|
||||||
pos = posFunc();
|
pos = posFunc();
|
||||||
anim = new Animation(world, image, facingFunc);
|
anim = new Animation(world, image, facingFunc);
|
||||||
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => { w.Remove(this); w.ScreenMap.Remove(this); }));
|
|
||||||
world.ScreenMap.Add(this, pos, anim.Image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
{
|
{
|
||||||
|
if (delay-- > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => { w.Remove(this); w.ScreenMap.Remove(this); }));
|
||||||
|
world.ScreenMap.Add(this, pos, anim.Image);
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
anim.Tick();
|
anim.Tick();
|
||||||
|
|
||||||
pos = posFunc();
|
pos = posFunc();
|
||||||
|
|||||||
Reference in New Issue
Block a user