Pass WorldRenderer to AnimationWithOffset.OffsetFunc.

This commit is contained in:
Paul Chote
2013-03-31 19:56:11 +13:00
parent 7c21459b48
commit 2f80cd5f92
12 changed files with 16 additions and 16 deletions

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Graphics
public class AnimationWithOffset
{
public Animation Animation;
public Func<float2> OffsetFunc;
public Func<WorldRenderer, float2> OffsetFunc;
public Func<bool> DisableFunc;
public int ZOffset;
@@ -25,18 +25,18 @@ namespace OpenRA.Graphics
{
}
public AnimationWithOffset(Animation a, Func<float2> o, Func<bool> d)
public AnimationWithOffset(Animation a, Func<WorldRenderer, float2> o, Func<bool> d)
{
this.Animation = a;
this.OffsetFunc = o;
this.DisableFunc = d;
}
public Renderable Image(Actor self, PaletteReference pal)
public Renderable Image(Actor self, WorldRenderer wr, PaletteReference pal)
{
var p = self.CenterLocation;
var loc = p.ToFloat2() - 0.5f * Animation.Image.size
+ (OffsetFunc != null ? OffsetFunc() : float2.Zero);
+ (OffsetFunc != null ? OffsetFunc(wr) : float2.Zero);
var r = new Renderable(Animation.Image, loc, pal, p.Y);
return ZOffset != 0 ? r.WithZOffset(ZOffset) : r;

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Traits
foreach (var a in anims.Values)
if (a.DisableFunc == null || !a.DisableFunc())
{
Renderable ret = a.Image(self, palette);
Renderable ret = a.Image(self, wr, palette);
if (Info.Scale != 1f)
ret = ret.WithScale(Info.Scale).WithPos(ret.Pos + 0.5f * ret.Sprite.size * (1 - Info.Scale));
yield return ret;

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc
: 0);
var offset = new float2(-32,-21);
anims.Add("lights", new AnimationWithOffset( lights, () => offset, () => !buildComplete )
anims.Add("lights", new AnimationWithOffset( lights, wr => offset, () => !buildComplete )
{ ZOffset = 24 });
}

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Render
var wake = new Animation(anim.Name);
wake.Play("left-wake");
Func<float2> offset = () => new float2(((anims["wake"].Animation.CurrentSequence.Name == "left-wake") ? 1 : -1),2);
Func<WorldRenderer, float2> offset = wr => new float2(((anims["wake"].Animation.CurrentSequence.Name == "left-wake") ? 1 : -1),2);
anims.Add( "wake", new AnimationWithOffset( wake, offset, () => false ) { ZOffset = -2 } );
}

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc
var rs = self.Trait<RenderSimple>();
var roof = new Animation(rs.GetImage(self));
roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop"));
rs.anims.Add( "fire", new AnimationWithOffset( roof, () => new float2(7,-15), null ) { ZOffset = 24 } );
rs.anims.Add( "fire", new AnimationWithOffset( roof, wr => new float2(7,-15), null ) { ZOffset = 24 } );
}
}
}

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
var anim = new Animation("fire", () => 0);
anim.PlayRepeating(Info.Anim);
rs.anims.Add("fire",
new AnimationWithOffset(anim, () => new float2(0, -3), null));
new AnimationWithOffset(anim, wr => new float2(0, -3), null));
}
public void Tick(Actor self)

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Render
anim.Play("turret");
anims.Add("turret_{0}".F(i++), new AnimationWithOffset(anim,
() => PPos.FromWPosHackZ(WPos.Zero + t.Position(self)).ToFloat2(), null));
wr => PPos.FromWPosHackZ(WPos.Zero + t.Position(self)).ToFloat2(), null));
}
}
}

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Render
var turret = new Turret(info.Offset);
anims.Add("spinner", new AnimationWithOffset(
spinnerAnim,
() => turret.PxPosition(self, facing).ToFloat2(),
wr => turret.PxPosition(self, facing).ToFloat2(),
null ) { ZOffset = 1 } );
}
}

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Render
anim.Play("turret");
anims.Add("turret_{0}".F(i++), new AnimationWithOffset(anim,
() => TurretPosition(self, turret, facing), null));
wr => TurretPosition(self, turret, facing), null));
}
}

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Render
muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new AnimationWithOffset(
muzzleFlash,
() => PPos.FromWPosHackZ(WPos.Zero + a.MuzzleOffset(self, barrel)).ToFloat2(),
wr => PPos.FromWPosHackZ(WPos.Zero + a.MuzzleOffset(self, barrel)).ToFloat2(),
() => !isShowing));
}
}
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Render
{
foreach (var a in muzzleFlashes.Values)
if (a.DisableFunc == null || !a.DisableFunc())
yield return a.Image(self, wr.Palette("effect"));
yield return a.Image(self, wr, wr.Palette("effect"));
}
public void Tick(Actor self)

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Render
var turret = new Turret(info.Offset);
rs.anims.Add(info.Id, new AnimationWithOffset(
rotorAnim,
() => turret.PxPosition(self, facing).ToFloat2(),
wr => turret.PxPosition(self, facing).ToFloat2(),
null ) { ZOffset = 1 } );
}

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA
anim.PlayRepeating(info.Anim);
ru.anims.Add(info.AnimKey, new AnimationWithOffset(
anim, () => pos - new float2(0, alt), null));
anim, wr => pos - new float2(0, alt), null));
}
public void Tick(Actor self)