Add custom palette support to WithSpriteBody.
This commit is contained in:
@@ -35,6 +35,13 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
[Desc("Forces sprite body to be rendered on ground regardless of actor altitude (for example for custom shadow sprites).")]
|
[Desc("Forces sprite body to be rendered on ground regardless of actor altitude (for example for custom shadow sprites).")]
|
||||||
public readonly bool ForceToGround = false;
|
public readonly bool ForceToGround = false;
|
||||||
|
|
||||||
|
[PaletteReference(nameof(IsPlayerPalette))]
|
||||||
|
[Desc("Custom palette name.")]
|
||||||
|
public readonly string Palette = null;
|
||||||
|
|
||||||
|
[Desc("Palette is a player palette BaseName.")]
|
||||||
|
public readonly bool IsPlayerPalette = 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, string image, int facings, PaletteReference p)
|
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, string image, int facings, PaletteReference p)
|
||||||
@@ -42,6 +49,11 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
if (!EnabledByDefault)
|
if (!EnabledByDefault)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
|
if (IsPlayerPalette)
|
||||||
|
p = init.WorldRenderer.Palette(Palette + init.Get<OwnerInit>().InternalName);
|
||||||
|
else if (Palette != null)
|
||||||
|
p = init.WorldRenderer.Palette(Palette);
|
||||||
|
|
||||||
var anim = new Animation(init.World, image);
|
var anim = new Animation(init.World, image);
|
||||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||||
|
|
||||||
@@ -71,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
subtractDAT = () => new WVec(0, 0, -init.Self.World.Map.DistanceAboveTerrain(init.Self.CenterPosition).Length);
|
subtractDAT = () => new WVec(0, 0, -init.Self.World.Map.DistanceAboveTerrain(init.Self.CenterPosition).Length);
|
||||||
|
|
||||||
DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
|
DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
|
||||||
rs.Add(new AnimationWithOffset(DefaultAnimation, subtractDAT, () => IsTraitDisabled));
|
rs.Add(new AnimationWithOffset(DefaultAnimation, subtractDAT, () => IsTraitDisabled), info.Palette, info.IsPlayerPalette);
|
||||||
|
|
||||||
// Cache the bounds from the default sequence to avoid flickering when the animation changes
|
// Cache the bounds from the default sequence to avoid flickering when the animation changes
|
||||||
boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
|
boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);
|
||||||
|
|||||||
Reference in New Issue
Block a user