From 6854b23bcc56b6aae2b776ef1729fbac294e2cb7 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 5 Feb 2021 20:57:57 +0000 Subject: [PATCH] Add custom palette support to WithSpriteBody. --- OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs index bc1ca9847c..55d9fa840d 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs @@ -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).")] 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 virtual IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, string image, int facings, PaletteReference p) @@ -42,6 +49,11 @@ namespace OpenRA.Mods.Common.Traits.Render if (!EnabledByDefault) yield break; + if (IsPlayerPalette) + p = init.WorldRenderer.Palette(Palette + init.Get().InternalName); + else if (Palette != null) + p = init.WorldRenderer.Palette(Palette); + var anim = new Animation(init.World, image); 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); 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 boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused);