put AnimationWithOffset in its own file
This commit is contained in:
51
OpenRA.Game/Graphics/AnimationWithOffset.cs
Normal file
51
OpenRA.Game/Graphics/AnimationWithOffset.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#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.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Graphics
|
||||||
|
{
|
||||||
|
public class AnimationWithOffset
|
||||||
|
{
|
||||||
|
public Animation Animation;
|
||||||
|
public Func<float2> OffsetFunc;
|
||||||
|
public Func<bool> DisableFunc;
|
||||||
|
public int ZOffset;
|
||||||
|
|
||||||
|
public AnimationWithOffset(Animation a)
|
||||||
|
: this(a, null, null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public AnimationWithOffset(Animation a, Func<float2> o, Func<bool> d)
|
||||||
|
{
|
||||||
|
this.Animation = a;
|
||||||
|
this.OffsetFunc = o;
|
||||||
|
this.DisableFunc = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Renderable Image(Actor self, string pal)
|
||||||
|
{
|
||||||
|
var p = self.CenterLocation;
|
||||||
|
var loc = p - 0.5f * Animation.Image.size
|
||||||
|
+ (OffsetFunc != null ? OffsetFunc() : float2.Zero);
|
||||||
|
var r = new Renderable(Animation.Image, loc, pal, p.Y);
|
||||||
|
|
||||||
|
return ZOffset != 0 ? r.WithZOffset(ZOffset) : r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator AnimationWithOffset(Animation a)
|
||||||
|
{
|
||||||
|
return new AnimationWithOffset(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -185,6 +185,7 @@
|
|||||||
<Compile Include="Widgets\DropDownButtonWidget.cs" />
|
<Compile Include="Widgets\DropDownButtonWidget.cs" />
|
||||||
<Compile Include="Download.cs" />
|
<Compile Include="Download.cs" />
|
||||||
<Compile Include="ActorMap.cs" />
|
<Compile Include="ActorMap.cs" />
|
||||||
|
<Compile Include="Graphics\AnimationWithOffset.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -105,40 +105,5 @@ namespace OpenRA.Traits
|
|||||||
anim.PlayThen(NormalizeSequence(self, name),
|
anim.PlayThen(NormalizeSequence(self, name),
|
||||||
() => anim.PlayRepeating(NormalizeSequence(self, "idle")));
|
() => anim.PlayRepeating(NormalizeSequence(self, "idle")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AnimationWithOffset
|
|
||||||
{
|
|
||||||
public Animation Animation;
|
|
||||||
public Func<float2> OffsetFunc;
|
|
||||||
public Func<bool> DisableFunc;
|
|
||||||
public int ZOffset;
|
|
||||||
|
|
||||||
public AnimationWithOffset(Animation a)
|
|
||||||
: this(a, null, null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnimationWithOffset(Animation a, Func<float2> o, Func<bool> d)
|
|
||||||
{
|
|
||||||
this.Animation = a;
|
|
||||||
this.OffsetFunc = o;
|
|
||||||
this.DisableFunc = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Renderable Image(Actor self, string pal)
|
|
||||||
{
|
|
||||||
var p = self.CenterLocation;
|
|
||||||
var loc = p - 0.5f * Animation.Image.size
|
|
||||||
+ (OffsetFunc != null ? OffsetFunc() : float2.Zero);
|
|
||||||
var r = new Renderable(Animation.Image, loc, pal, p.Y);
|
|
||||||
|
|
||||||
return ZOffset != 0 ? r.WithZOffset(ZOffset) : r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator AnimationWithOffset(Animation a)
|
|
||||||
{
|
|
||||||
return new AnimationWithOffset(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc
|
|||||||
var rs = self.Trait<RenderSimple>();
|
var rs = self.Trait<RenderSimple>();
|
||||||
var roof = new Animation(rs.GetImage(self));
|
var roof = new Animation(rs.GetImage(self));
|
||||||
roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop"));
|
roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop"));
|
||||||
rs.anims.Add( "fire", new RenderSimple.AnimationWithOffset( roof, () => new float2(7,-15), null ) { ZOffset = 24 } );
|
rs.anims.Add( "fire", new AnimationWithOffset( roof, () => new float2(7,-15), null ) { ZOffset = 24 } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc
|
|||||||
var rs = self.Trait<RenderSimple>();
|
var rs = self.Trait<RenderSimple>();
|
||||||
var roof = new Animation(rs.GetImage(self), () => self.Trait<IFacing>().Facing);
|
var roof = new Animation(rs.GetImage(self), () => self.Trait<IFacing>().Facing);
|
||||||
roof.Play("roof");
|
roof.Play("roof");
|
||||||
rs.anims.Add( "roof", new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 24 } );
|
rs.anims.Add( "roof", new AnimationWithOffset( roof ) { ZOffset = 24 } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA
|
|||||||
var anim = new Animation("fire", () => 0);
|
var anim = new Animation("fire", () => 0);
|
||||||
anim.PlayRepeating(self.Info.Traits.Get<BurnsInfo>().Anim);
|
anim.PlayRepeating(self.Info.Traits.Get<BurnsInfo>().Anim);
|
||||||
self.Trait<RenderSimple>().anims.Add("fire",
|
self.Trait<RenderSimple>().anims.Add("fire",
|
||||||
new RenderSimple.AnimationWithOffset(anim, () => new float2(0, -3), null));
|
new AnimationWithOffset(anim, () => new float2(0, -3), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (--ticks <= 0)
|
if (--ticks <= 0)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
: base(init, info)
|
: base(init, info)
|
||||||
{
|
{
|
||||||
roof = new Animation(GetImage(init.self));
|
roof = new Animation(GetImage(init.self));
|
||||||
var offset = new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 24 };
|
var offset = new AnimationWithOffset( roof ) { ZOffset = 24 };
|
||||||
offset.DisableFunc = () => !buildComplete;
|
offset.DisableFunc = () => !buildComplete;
|
||||||
anims.Add("roof", offset);
|
anims.Add("roof", offset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
|
|
||||||
class WithMuzzleFlash : INotifyAttack, IRender, ITick
|
class WithMuzzleFlash : INotifyAttack, IRender, ITick
|
||||||
{
|
{
|
||||||
Dictionary<string, RenderSimple.AnimationWithOffset> muzzleFlashes = new Dictionary<string, RenderSimple.AnimationWithOffset>();
|
Dictionary<string, AnimationWithOffset> muzzleFlashes = new Dictionary<string, AnimationWithOffset>();
|
||||||
bool isShowing;
|
bool isShowing;
|
||||||
|
|
||||||
public WithMuzzleFlash(Actor self)
|
public WithMuzzleFlash(Actor self)
|
||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
var muzzleFlash = new Animation(render.GetImage(self), getFacing);
|
var muzzleFlash = new Animation(render.GetImage(self), getFacing);
|
||||||
muzzleFlash.Play("muzzle");
|
muzzleFlash.Play("muzzle");
|
||||||
|
|
||||||
muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new RenderSimple.AnimationWithOffset(
|
muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new AnimationWithOffset(
|
||||||
muzzleFlash,
|
muzzleFlash,
|
||||||
() => Combat.GetBarrelPosition(self, facing, turret, barrel),
|
() => Combat.GetBarrelPosition(self, facing, turret, barrel),
|
||||||
() => !isShowing));
|
() => !isShowing));
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
|
|
||||||
rotorAnim = new Animation(rs.GetImage(self));
|
rotorAnim = new Animation(rs.GetImage(self));
|
||||||
rotorAnim.PlayRepeating("rotor");
|
rotorAnim.PlayRepeating("rotor");
|
||||||
rs.anims.Add(info.Id, new RenderSimple.AnimationWithOffset(
|
rs.anims.Add(info.Id, new AnimationWithOffset(
|
||||||
rotorAnim,
|
rotorAnim,
|
||||||
() => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)),
|
() => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)),
|
||||||
null ) { ZOffset = 1 } );
|
null ) { ZOffset = 1 } );
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
var rs = self.Trait<RenderSimple>();
|
var rs = self.Trait<RenderSimple>();
|
||||||
|
|
||||||
anim = new Animation("smoke_m");
|
anim = new Animation("smoke_m");
|
||||||
rs.anims.Add("smoke", new RenderSimple.AnimationWithOffset(
|
rs.anims.Add("smoke", new AnimationWithOffset(
|
||||||
anim, null, () => !isSmoking));
|
anim, null, () => !isSmoking));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
|
|||||||
var anim = new Animation(ru.GetImage(self), () => (int)facing);
|
var anim = new Animation(ru.GetImage(self), () => (int)facing);
|
||||||
anim.PlayRepeating(info.Anim);
|
anim.PlayRepeating(info.Anim);
|
||||||
|
|
||||||
ru.anims.Add(info.AnimKey, new RenderSimple.AnimationWithOffset(
|
ru.anims.Add(info.AnimKey, new AnimationWithOffset(
|
||||||
anim, () => pos - new float2(0, alt), null));
|
anim, () => pos - new float2(0, alt), null));
|
||||||
|
|
||||||
info = null;
|
info = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user