Extend WithSpriteBody funtionality
Move building placement range circle to PlaceBuilding, add PauseAnimationWhenDisabled.
This commit is contained in:
@@ -8,15 +8,17 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Effects;
|
using OpenRA.Effects;
|
||||||
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Allows the player to execute build orders.", " Attach this to the player actor.")]
|
[Desc("Allows the player to execute build orders.", " Attach this to the player actor.")]
|
||||||
public class PlaceBuildingInfo : ITraitInfo
|
public class PlaceBuildingInfo : ITraitInfo, IPlaceBuildingDecoration
|
||||||
{
|
{
|
||||||
[Desc("Palette to use for rendering the placement sprite.")]
|
[Desc("Palette to use for rendering the placement sprite.")]
|
||||||
[PaletteReference] public readonly string Palette = "terrain";
|
[PaletteReference] public readonly string Palette = "terrain";
|
||||||
@@ -28,6 +30,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly string NewOptionsNotification = "NewOptions";
|
public readonly string NewOptionsNotification = "NewOptions";
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new PlaceBuilding(this); }
|
public object Create(ActorInitializer init) { return new PlaceBuilding(this); }
|
||||||
|
|
||||||
|
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
||||||
|
{
|
||||||
|
if (!ai.Traits.Get<BuildingInfo>().RequiresBaseProvider)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
foreach (var a in w.ActorsWithTrait<BaseProvider>())
|
||||||
|
foreach (var r in a.Trait.RenderAfterWorld(wr))
|
||||||
|
yield return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlaceBuilding : IResolveOrder
|
public class PlaceBuilding : IResolveOrder
|
||||||
|
|||||||
@@ -17,21 +17,11 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Render trait for stationary objects that can be placed from the build palette.")]
|
[Desc("Render trait for stationary objects that can be placed from the build palette.")]
|
||||||
public class RenderBuildingInfo : RenderSimpleInfo, Requires<BuildingInfo>, IPlaceBuildingDecoration
|
public class RenderBuildingInfo : RenderSimpleInfo, Requires<BuildingInfo>
|
||||||
{
|
{
|
||||||
public readonly bool PauseOnLowPower = false;
|
public readonly bool PauseOnLowPower = false;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new RenderBuilding(init, this); }
|
public override object Create(ActorInitializer init) { return new RenderBuilding(init, this); }
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
|
||||||
{
|
|
||||||
if (!ai.Traits.Get<BuildingInfo>().RequiresBaseProvider)
|
|
||||||
yield break;
|
|
||||||
|
|
||||||
foreach (var a in w.ActorsWithTrait<BaseProvider>())
|
|
||||||
foreach (var r in a.Trait.RenderAfterWorld(wr))
|
|
||||||
yield return r;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete
|
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Animation to play when the actor is idle.")]
|
[Desc("Animation to play when the actor is idle.")]
|
||||||
[SequenceReference] public readonly string Sequence = "idle";
|
[SequenceReference] public readonly string Sequence = "idle";
|
||||||
|
|
||||||
|
[Desc("Pause animation when actor is disabled.")]
|
||||||
|
public readonly bool PauseAnimationWhenDisabled = false;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new WithSpriteBody(init, this); }
|
public override object Create(ActorInitializer init) { return new WithSpriteBody(init, this); }
|
||||||
|
|
||||||
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
@@ -36,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WithSpriteBody : UpgradableTrait<WithSpriteBodyInfo>, ISpriteBody, INotifyDamageStateChanged
|
public class WithSpriteBody : UpgradableTrait<WithSpriteBodyInfo>, ISpriteBody, INotifyDamageStateChanged, INotifyBuildComplete
|
||||||
{
|
{
|
||||||
public readonly Animation DefaultAnimation;
|
public readonly Animation DefaultAnimation;
|
||||||
|
|
||||||
@@ -63,6 +66,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence);
|
return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Get rid of INotifyBuildComplete in favor of using the upgrade system
|
||||||
|
public virtual void BuildingComplete(Actor self)
|
||||||
|
{
|
||||||
|
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
|
||||||
|
|
||||||
|
if (Info.PauseAnimationWhenDisabled)
|
||||||
|
DefaultAnimation.Paused = () =>
|
||||||
|
self.IsDisabled() && DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, Info.Sequence);
|
||||||
|
}
|
||||||
|
|
||||||
public void PlayCustomAnimation(Actor self, string name, Action after = null)
|
public void PlayCustomAnimation(Actor self, string name, Action after = null)
|
||||||
{
|
{
|
||||||
DefaultAnimation.PlayThen(NormalizeSequence(self, name), () =>
|
DefaultAnimation.PlayThen(NormalizeSequence(self, name), () =>
|
||||||
|
|||||||
Reference in New Issue
Block a user