move render{building,buildingturreted,unit} into mods.ra; move all render traits into mods.ra.render
This commit is contained in:
@@ -87,8 +87,6 @@
|
||||
<Compile Include="Traits\Player\PlayerResources.cs" />
|
||||
<Compile Include="Traits\Player\TechTreeCache.cs" />
|
||||
<Compile Include="Traits\Modifiers\HiddenUnderFog.cs" />
|
||||
<Compile Include="Traits\Render\RenderBuilding.cs" />
|
||||
<Compile Include="Traits\Render\RenderBuildingTurreted.cs" />
|
||||
<Compile Include="Traits\World\Shroud.cs" />
|
||||
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
|
||||
@@ -189,7 +187,6 @@
|
||||
<Compile Include="Traits\Production.cs" />
|
||||
<Compile Include="Traits\RallyPoint.cs" />
|
||||
<Compile Include="Traits\Render\RenderSimple.cs" />
|
||||
<Compile Include="Traits\Render\RenderUnit.cs" />
|
||||
<Compile Include="Traits\StoresOre.cs" />
|
||||
<Compile Include="Traits\Cloak.cs" />
|
||||
<Compile Include="Traits\TraitsInterfaces.cs" />
|
||||
|
||||
@@ -83,11 +83,10 @@ namespace OpenRA.Traits
|
||||
.Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( unit.Category ) )
|
||||
.ToList();
|
||||
var producer = producers.Where( x => x.Trait.IsPrimary ).Concat( producers )
|
||||
.Select( x => x.Actor )
|
||||
.FirstOrDefault();
|
||||
|
||||
if( producer != null )
|
||||
producer.traits.Get<RenderBuilding>().PlayCustomAnim( producer, "build" );
|
||||
if( producer.Actor != null )
|
||||
producer.Actor.traits.WithInterface<RenderSimple>().First().PlayCustomAnim( producer.Actor, "build" );
|
||||
}
|
||||
|
||||
static int GetNumBuildables(Player p)
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Effects;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class RenderBuildingInfo : RenderSimpleInfo
|
||||
{
|
||||
public readonly bool HasMakeAnimation = true;
|
||||
public override object Create(ActorInitializer init) { return new RenderBuilding(init.self);}
|
||||
}
|
||||
|
||||
public class RenderBuilding : RenderSimple, INotifyDamage, INotifySold
|
||||
{
|
||||
public RenderBuilding( Actor self )
|
||||
: this( self, () => 0 )
|
||||
{
|
||||
}
|
||||
|
||||
public RenderBuilding(Actor self, Func<int> baseFacing)
|
||||
: base(self, baseFacing)
|
||||
{
|
||||
if( Game.skipMakeAnims || !self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation )
|
||||
anim.PlayThen( "idle", () => self.World.AddFrameEndTask( _ => Complete( self ) ) );
|
||||
else
|
||||
anim.PlayThen( "make", () => self.World.AddFrameEndTask( _ => Complete( self ) ) );
|
||||
}
|
||||
|
||||
void Complete( Actor self )
|
||||
{
|
||||
anim.PlayRepeating( GetPrefix(self) + "idle" );
|
||||
foreach( var x in self.traits.WithInterface<INotifyBuildComplete>() )
|
||||
x.BuildingComplete( self );
|
||||
}
|
||||
|
||||
protected string GetPrefix(Actor self)
|
||||
{
|
||||
return self.GetDamageState() == DamageState.Half ? "damaged-" : "";
|
||||
}
|
||||
|
||||
public void PlayCustomAnim(Actor self, string name)
|
||||
{
|
||||
if (anim.HasSequence(name))
|
||||
anim.PlayThen(GetPrefix(self) + name,
|
||||
() => anim.PlayRepeating(GetPrefix(self) + "idle"));
|
||||
}
|
||||
|
||||
public void PlayCustomAnimThen(Actor self, string name, Action a)
|
||||
{
|
||||
anim.PlayThen(GetPrefix(self) + name,
|
||||
() => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); });
|
||||
}
|
||||
|
||||
public void PlayCustomAnimBackwards(Actor self, string name, Action a)
|
||||
{
|
||||
var hasSequence = anim.HasSequence(GetPrefix(self) + name);
|
||||
anim.PlayBackwardsThen(hasSequence ? GetPrefix(self) + name : name,
|
||||
() => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); });
|
||||
}
|
||||
|
||||
public virtual void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (!e.DamageStateChanged)
|
||||
return;
|
||||
|
||||
switch( e.DamageState )
|
||||
{
|
||||
case DamageState.Normal:
|
||||
anim.ReplaceAnim("idle");
|
||||
break;
|
||||
case DamageState.Half:
|
||||
anim.ReplaceAnim("damaged-idle");
|
||||
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound, self.CenterLocation);
|
||||
break;
|
||||
case DamageState.Dead:
|
||||
self.World.AddFrameEndTask(w => w.Add(new Explosion(w, self.CenterLocation.ToInt2(), "building", false)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Selling( Actor self )
|
||||
{
|
||||
if( !Game.skipMakeAnims && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation )
|
||||
anim.PlayBackwardsThen( "make", null );
|
||||
|
||||
foreach (var s in self.Info.Traits.Get<BuildingInfo>().SellSounds)
|
||||
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
|
||||
}
|
||||
|
||||
public void Sold(Actor self) {}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class RenderBuildingTurretedInfo : RenderBuildingInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingTurreted(init.self); }
|
||||
}
|
||||
|
||||
class RenderBuildingTurreted : RenderBuilding, INotifyBuildComplete
|
||||
{
|
||||
public RenderBuildingTurreted(Actor self)
|
||||
: base(self, () => self.traits.Get<Turreted>().turretFacing)
|
||||
{
|
||||
}
|
||||
|
||||
public void BuildingComplete( Actor self )
|
||||
{
|
||||
anim.Play( "idle" );
|
||||
}
|
||||
|
||||
public override void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (!e.DamageStateChanged) return;
|
||||
|
||||
switch (e.DamageState)
|
||||
{
|
||||
case DamageState.Normal:
|
||||
anim.Play( "idle" );
|
||||
break;
|
||||
case DamageState.Half:
|
||||
anim.Play( "damaged-idle" );
|
||||
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound, self.CenterLocation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,18 @@ namespace OpenRA.Traits
|
||||
a.Animation.Tick();
|
||||
}
|
||||
|
||||
protected virtual string GetPrefix(Actor self)
|
||||
{
|
||||
return self.GetDamageState() == DamageState.Half ? "damaged-" : "";
|
||||
}
|
||||
|
||||
public void PlayCustomAnim(Actor self, string name)
|
||||
{
|
||||
if (anim.HasSequence(name))
|
||||
anim.PlayThen(GetPrefix(self) + name,
|
||||
() => anim.PlayRepeating(GetPrefix(self) + "idle"));
|
||||
}
|
||||
|
||||
public class AnimationWithOffset
|
||||
{
|
||||
public Animation Animation;
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class RenderUnitInfo : RenderSimpleInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderUnit(init.self); }
|
||||
}
|
||||
|
||||
public class RenderUnit : RenderSimple, INotifyDamage
|
||||
{
|
||||
public RenderUnit(Actor self)
|
||||
: base(self, () => self.traits.Get<Unit>().Facing)
|
||||
{
|
||||
anim.Play("idle");
|
||||
anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) );
|
||||
}
|
||||
|
||||
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
||||
{
|
||||
anim.PlayThen(newAnim, () => { anim.Play("idle"); if (after != null) after(); });
|
||||
}
|
||||
|
||||
bool isSmoking;
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (e.DamageState != DamageState.Half) return;
|
||||
if (isSmoking) return;
|
||||
|
||||
isSmoking = true;
|
||||
var smoke = anims[ "smoke" ].Animation;
|
||||
smoke.PlayThen( "idle",
|
||||
() => smoke.PlayThen( "loop",
|
||||
() => smoke.PlayBackwardsThen( "end",
|
||||
() => isSmoking = false ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user