Moving renders
Remove Traits.Render
This commit is contained in:
@@ -108,6 +108,7 @@
|
||||
<Compile Include="Scripting\Properties\ResourceProperties.cs" />
|
||||
<Compile Include="Scripting\Properties\UpgradeProperties.cs" />
|
||||
<Compile Include="Traits\BlocksBullets.cs" />
|
||||
<Compile Include="Traits\Buildings\DeadBuildingState.cs" />
|
||||
<Compile Include="Traits\Burns.cs" />
|
||||
<Compile Include="Traits\CustomBuildTimeValue.cs" />
|
||||
<Compile Include="Traits\CustomSellValue.cs" />
|
||||
@@ -130,7 +131,14 @@
|
||||
<Compile Include="Traits\Power\ScalePowerWithHealth.cs" />
|
||||
<Compile Include="Traits\ProvidesRadar.cs" />
|
||||
<Compile Include="Traits\RallyPoint.cs" />
|
||||
<Compile Include="Traits\Render\RenderEditorOnly.cs" />
|
||||
<Compile Include="Traits\Render\RenderFlare.cs" />
|
||||
<Compile Include="Traits\Render\RenderSimple.cs" />
|
||||
<Compile Include="Traits\Render\RenderSprites.cs" />
|
||||
<Compile Include="Traits\Render\RenderUnit.cs" />
|
||||
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithDeathAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithResources.cs" />
|
||||
<Compile Include="Traits\ShakeOnDeath.cs" />
|
||||
<Compile Include="Traits\Sound\ActorLostNotification.cs" />
|
||||
<Compile Include="Traits\Sound\AnnounceOnBuild.cs" />
|
||||
|
||||
50
OpenRA.Mods.Common/Traits/Buildings/DeadBuildingState.cs
Normal file
50
OpenRA.Mods.Common/Traits/Buildings/DeadBuildingState.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class DeadBuildingStateInfo : ITraitInfo, Requires<HealthInfo>, Requires<RenderSimpleInfo>
|
||||
{
|
||||
public readonly int LingerTime = 20;
|
||||
|
||||
public object Create(ActorInitializer init) { return new DeadBuildingState(init.self, this); }
|
||||
}
|
||||
|
||||
class DeadBuildingState : INotifyKilled
|
||||
{
|
||||
DeadBuildingStateInfo info;
|
||||
RenderSimple rs;
|
||||
|
||||
public DeadBuildingState(Actor self, DeadBuildingStateInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
rs = self.Trait<RenderSimple>();
|
||||
self.Trait<Health>().RemoveOnDeath = !rs.DefaultAnimation.HasSequence("dead");
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
if (!rs.DefaultAnimation.HasSequence("dead")) return;
|
||||
|
||||
if (rs.DefaultAnimation.GetSequence("dead").Length > 1)
|
||||
rs.DefaultAnimation.Play("dead");
|
||||
else
|
||||
rs.DefaultAnimation.PlayRepeating("dead");
|
||||
|
||||
self.World.AddFrameEndTask(
|
||||
w => w.Add(
|
||||
new DelayedAction(info.LingerTime,
|
||||
() => self.Destroy())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits.Render;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
|
||||
28
OpenRA.Mods.Common/Traits/Render/RenderEditorOnly.cs
Normal file
28
OpenRA.Mods.Common/Traits/Render/RenderEditorOnly.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Invisible during games.")]
|
||||
class RenderEditorOnlyInfo : RenderSimpleInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderEditorOnly(init.self); }
|
||||
}
|
||||
|
||||
class RenderEditorOnly : RenderSimple
|
||||
{
|
||||
public RenderEditorOnly(Actor self) : base(self, () => 0) { }
|
||||
|
||||
public override IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr) { return SpriteRenderable.None; }
|
||||
}
|
||||
}
|
||||
26
OpenRA.Mods.Common/Traits/Render/RenderFlare.cs
Normal file
26
OpenRA.Mods.Common/Traits/Render/RenderFlare.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class RenderFlareInfo : RenderSimpleInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderFlare(init.self); }
|
||||
}
|
||||
|
||||
class RenderFlare : RenderSimple
|
||||
{
|
||||
public RenderFlare(Actor self)
|
||||
: base(self, () => 0)
|
||||
{
|
||||
DefaultAnimation.PlayThen("open", () => DefaultAnimation.PlayRepeating("idle"));
|
||||
}
|
||||
}
|
||||
}
|
||||
73
OpenRA.Mods.Common/Traits/Render/RenderSimple.cs
Normal file
73
OpenRA.Mods.Common/Traits/Render/RenderSimple.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class RenderSimpleInfo : RenderSpritesInfo, IRenderActorPreviewSpritesInfo, IQuantizeBodyOrientationInfo, ILegacyEditorRenderInfo, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderSimple(init.self); }
|
||||
|
||||
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating("idle");
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
|
||||
public virtual int QuantizedBodyFacings(SequenceProvider sequenceProvider, ActorInfo ai)
|
||||
{
|
||||
return sequenceProvider.GetSequence(RenderSprites.GetImage(ai), "idle").Facings;
|
||||
}
|
||||
|
||||
public string EditorPalette { get { return Palette; } }
|
||||
public string EditorImage(ActorInfo actor) { return RenderSimple.GetImage(actor); }
|
||||
}
|
||||
|
||||
public class RenderSimple : RenderSprites, IAutoSelectionSize
|
||||
{
|
||||
public readonly Animation DefaultAnimation;
|
||||
|
||||
public RenderSimple(Actor self, Func<int> baseFacing)
|
||||
: base(self)
|
||||
{
|
||||
DefaultAnimation = new Animation(self.World, GetImage(self), baseFacing);
|
||||
Add("", DefaultAnimation);
|
||||
}
|
||||
|
||||
public RenderSimple(Actor self)
|
||||
: this(self, MakeFacingFunc(self))
|
||||
{
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle"));
|
||||
}
|
||||
|
||||
public int2 SelectionSize(Actor self) { return AutoSelectionSize(self); }
|
||||
|
||||
public string NormalizeSequence(Actor self, string sequence)
|
||||
{
|
||||
return NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence);
|
||||
}
|
||||
|
||||
public void PlayCustomAnim(Actor self, string name)
|
||||
{
|
||||
if (DefaultAnimation.HasSequence(name))
|
||||
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
|
||||
() => DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits.Render
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public interface IRenderActorPreviewSpritesInfo { IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p); }
|
||||
|
||||
|
||||
43
OpenRA.Mods.Common/Traits/Render/RenderUnit.cs
Normal file
43
OpenRA.Mods.Common/Traits/Render/RenderUnit.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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.Mods.Common.Traits
|
||||
{
|
||||
public class RenderUnitInfo : RenderSimpleInfo, Requires<IFacingInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderUnit(init.self); }
|
||||
}
|
||||
|
||||
public class RenderUnit : RenderSimple
|
||||
{
|
||||
public RenderUnit(Actor self)
|
||||
: base(self) { }
|
||||
|
||||
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
||||
{
|
||||
DefaultAnimation.PlayThen(newAnim, () => { DefaultAnimation.Play("idle"); if (after != null) after(); });
|
||||
}
|
||||
|
||||
public void PlayCustomAnimRepeating(Actor self, string name)
|
||||
{
|
||||
DefaultAnimation.PlayThen(name,
|
||||
() => PlayCustomAnimRepeating(self, name));
|
||||
}
|
||||
|
||||
public void PlayCustomAnimBackwards(Actor self, string name, Action after)
|
||||
{
|
||||
DefaultAnimation.PlayBackwardsThen(name,
|
||||
() => { DefaultAnimation.PlayRepeating("idle"); if (after != null) after(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Changes the animation when the actor constructed a building.")]
|
||||
public class WithBuildingPlacedAnimationInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
public readonly string Sequence = "build";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithBuildingPlacedAnimation(init.self, this); }
|
||||
}
|
||||
|
||||
public class WithBuildingPlacedAnimation : INotifyBuildingPlaced
|
||||
{
|
||||
WithBuildingPlacedAnimationInfo info;
|
||||
RenderSimple renderSimple;
|
||||
|
||||
public WithBuildingPlacedAnimation(Actor self, WithBuildingPlacedAnimationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
renderSimple = self.Trait<RenderSimple>();
|
||||
}
|
||||
|
||||
public void BuildingPlaced(Actor self)
|
||||
{
|
||||
renderSimple.PlayCustomAnim(self, info.Sequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs
Normal file
73
OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("This actor has a death animation.")]
|
||||
public class WithDeathAnimationInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
{
|
||||
[Desc("Sequence to play when this actor is killed by a warhead.")]
|
||||
public readonly string DeathSequence = "die";
|
||||
public readonly string DeathSequencePalette = "player";
|
||||
[Desc("Custom death animation palette is a player palette BaseName")]
|
||||
public readonly bool DeathPaletteIsPlayerPalette = true;
|
||||
[Desc("Should DeathType-specific sequences be used (sequence name = DeathSequence + DeathType).")]
|
||||
public readonly bool UseDeathTypeSuffix = true;
|
||||
[Desc("Sequence to play when this actor is crushed.")]
|
||||
public readonly string CrushedSequence = "die-crushed";
|
||||
public readonly string CrushedSequencePalette = "effect";
|
||||
[Desc("Custom crushed animation palette is a player palette BaseName")]
|
||||
public readonly bool CrushedPaletteIsPlayerPalette = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithDeathAnimation(init.self, this); }
|
||||
}
|
||||
|
||||
public class WithDeathAnimation : INotifyKilled
|
||||
{
|
||||
public readonly WithDeathAnimationInfo Info;
|
||||
readonly RenderSimple renderSimple;
|
||||
|
||||
public WithDeathAnimation(Actor self, WithDeathAnimationInfo info)
|
||||
{
|
||||
Info = info;
|
||||
renderSimple = self.Trait<RenderSimple>();
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
// Killed by some non-standard means. This includes being crushed
|
||||
// by a vehicle (Actors with Crushable trait will spawn CrushedSequence instead).
|
||||
if (e.Warhead == null)
|
||||
return;
|
||||
|
||||
var sequence = Info.DeathSequence;
|
||||
if (Info.UseDeathTypeSuffix)
|
||||
sequence += e.Warhead.DeathType;
|
||||
|
||||
var palette = Info.DeathSequencePalette;
|
||||
if (Info.DeathPaletteIsPlayerPalette)
|
||||
palette += self.Owner.InternalName;
|
||||
|
||||
SpawnDeathAnimation(self, sequence, palette);
|
||||
}
|
||||
|
||||
public void SpawnDeathAnimation(Actor self, string sequence, string palette)
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (!self.Destroyed)
|
||||
w.Add(new Corpse(w, self.CenterPosition, renderSimple.GetImage(self), sequence, palette));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
68
OpenRA.Mods.Common/Traits/Render/WithResources.cs
Normal file
68
OpenRA.Mods.Common/Traits/Render/WithResources.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Displays the fill status of PlayerResources with an extra sprite overlay on the actor.")]
|
||||
class WithResourcesInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
public readonly string Sequence = "resources";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithResources(init.self, this); }
|
||||
}
|
||||
|
||||
class WithResources : INotifyBuildComplete, INotifySold, INotifyOwnerChanged, INotifyDamageStateChanged
|
||||
{
|
||||
WithResourcesInfo info;
|
||||
Animation anim;
|
||||
RenderSimple rs;
|
||||
PlayerResources playerResources;
|
||||
bool buildComplete;
|
||||
|
||||
public WithResources(Actor self, WithResourcesInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
rs = self.Trait<RenderSimple>();
|
||||
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
|
||||
anim = new Animation(self.World, rs.GetImage(self));
|
||||
anim.PlayFetchIndex(info.Sequence,
|
||||
() => playerResources.ResourceCapacity != 0
|
||||
? ((10 * anim.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity)
|
||||
: 0);
|
||||
|
||||
rs.Add("resources_{0}".F(info.Sequence), new AnimationWithOffset(
|
||||
anim, null, () => !buildComplete, 1024));
|
||||
}
|
||||
|
||||
public void BuildingComplete( Actor self )
|
||||
{
|
||||
buildComplete = true;
|
||||
}
|
||||
|
||||
public void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (anim.CurrentSequence != null)
|
||||
anim.ReplaceAnim(rs.NormalizeSequence(self, info.Sequence));
|
||||
}
|
||||
|
||||
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||
}
|
||||
|
||||
public void Selling(Actor self) { rs.Remove("resources_{0}".F(info.Sequence)); }
|
||||
public void Sold(Actor self) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user