Add custom palette support to WithInfantryBody.

This commit is contained in:
Paul Chote
2020-05-13 23:35:24 +01:00
committed by reaperrr
parent d3ab3d7d78
commit 23561cd76b

View File

@@ -38,6 +38,13 @@ namespace OpenRA.Mods.Common.Traits.Render
[SequenceReference]
public readonly string[] StandSequences = { "stand" };
[PaletteReference("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 WithInfantryBody(init, this); }
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
@@ -47,6 +54,12 @@ namespace OpenRA.Mods.Common.Traits.Render
var anim = new Animation(init.World, image, init.GetFacing());
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), StandSequences.First()));
if (IsPlayerPalette)
p = init.WorldRenderer.Palette(Palette + init.Get<OwnerInit>().PlayerName);
else if (Palette != null)
p = init.WorldRenderer.Palette(Palette);
yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale);
}
}
@@ -78,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits.Render
var rs = self.Trait<RenderSprites>();
DefaultAnimation = new Animation(init.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self));
rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled));
rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled), info.Palette, info.IsPlayerPalette);
PlayStandAnimation(self);
move = init.Self.Trait<IMove>();