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">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -185,6 +185,7 @@
|
||||
<Compile Include="Widgets\DropDownButtonWidget.cs" />
|
||||
<Compile Include="Download.cs" />
|
||||
<Compile Include="ActorMap.cs" />
|
||||
<Compile Include="Graphics\AnimationWithOffset.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -105,40 +105,5 @@ namespace OpenRA.Traits
|
||||
anim.PlayThen(NormalizeSequence(self, name),
|
||||
() => 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 roof = new Animation(rs.GetImage(self));
|
||||
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 roof = new Animation(rs.GetImage(self), () => self.Trait<IFacing>().Facing);
|
||||
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);
|
||||
anim.PlayRepeating(self.Info.Traits.Get<BurnsInfo>().Anim);
|
||||
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)
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
: base(init, info)
|
||||
{
|
||||
roof = new Animation(GetImage(init.self));
|
||||
var offset = new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 24 };
|
||||
var offset = new AnimationWithOffset( roof ) { ZOffset = 24 };
|
||||
offset.DisableFunc = () => !buildComplete;
|
||||
anims.Add("roof", offset);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
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;
|
||||
|
||||
public WithMuzzleFlash(Actor self)
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
var muzzleFlash = new Animation(render.GetImage(self), getFacing);
|
||||
muzzleFlash.Play("muzzle");
|
||||
|
||||
muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new RenderSimple.AnimationWithOffset(
|
||||
muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new AnimationWithOffset(
|
||||
muzzleFlash,
|
||||
() => Combat.GetBarrelPosition(self, facing, turret, barrel),
|
||||
() => !isShowing));
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
rotorAnim = new Animation(rs.GetImage(self));
|
||||
rotorAnim.PlayRepeating("rotor");
|
||||
rs.anims.Add(info.Id, new RenderSimple.AnimationWithOffset(
|
||||
rs.anims.Add(info.Id, new AnimationWithOffset(
|
||||
rotorAnim,
|
||||
() => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)),
|
||||
null ) { ZOffset = 1 } );
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
|
||||
anim = new Animation("smoke_m");
|
||||
rs.anims.Add("smoke", new RenderSimple.AnimationWithOffset(
|
||||
rs.anims.Add("smoke", new AnimationWithOffset(
|
||||
anim, null, () => !isSmoking));
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
|
||||
var anim = new Animation(ru.GetImage(self), () => (int)facing);
|
||||
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));
|
||||
|
||||
info = null;
|
||||
|
||||
Reference in New Issue
Block a user