Replace projectile, WithShadow, WithParachute shadows with tint effects.

This commit is contained in:
Paul Chote
2021-02-12 23:20:28 +00:00
committed by reaperrr
parent 1c1af89bb9
commit 554486fb0b
7 changed files with 126 additions and 24 deletions

View File

@@ -53,9 +53,8 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Paradropped unit's shadow sequence.")]
public readonly string ShadowSequence = null;
[PaletteReference(false)]
[Desc("Palette used to render the paradropped unit's shadow.")]
public readonly string ShadowPalette = "shadow";
[Desc("Color to render the paradropped unit's shadow.")]
public readonly Color ShadowColor = Color.FromArgb(140, 0, 0, 0);
[Desc("Shadow position relative to the paradropped unit's intended landing position.")]
public readonly WVec ShadowOffset = new WVec(0, 128, 0);
@@ -108,6 +107,8 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly Animation shadow;
readonly AnimationWithOffset anim;
readonly WithParachuteInfo info;
readonly float3 shadowColor;
readonly float shadowAlpha;
bool renderProlonged = false;
@@ -135,6 +136,9 @@ namespace OpenRA.Mods.Common.Traits.Render
var rs = self.Trait<RenderSprites>();
rs.Add(anim, info.Palette, info.IsPlayerPalette);
shadowColor = new float3(info.ShadowColor.R, info.ShadowColor.G, info.ShadowColor.B) / 255f;
shadowAlpha = info.ShadowColor.A / 255f;
}
protected override void TraitEnabled(Actor self)
@@ -175,9 +179,9 @@ namespace OpenRA.Mods.Common.Traits.Render
var dat = self.World.Map.DistanceAboveTerrain(self.CenterPosition);
var pos = self.CenterPosition - new WVec(0, 0, dat.Length);
var palette = wr.Palette(info.ShadowPalette);
var tintModifiers = shadow.CurrentSequence.IgnoreWorldTint ? TintModifiers.IgnoreWorldTint : TintModifiers.None;
return new IRenderable[] { new SpriteRenderable(shadow.Image, pos, info.ShadowOffset, info.ShadowZOffset, palette, shadow.CurrentSequence.Scale, true, tintModifiers) };
var palette = wr.Palette(info.Palette);
var tintModifiers = shadow.CurrentSequence.IgnoreWorldTint ? TintModifiers.ReplaceColor | TintModifiers.IgnoreWorldTint : TintModifiers.ReplaceColor;
return new IRenderable[] { new SpriteRenderable(shadow.Image, pos, info.ShadowOffset, info.ShadowZOffset, palette, 1, shadowAlpha, shadowColor, tintModifiers, true) };
}
IEnumerable<Rectangle> IRender.ScreenBounds(Actor self, WorldRenderer wr)

View File

@@ -20,8 +20,8 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Clones the actor sprite with another palette below it.")]
public class WithShadowInfo : ConditionalTraitInfo
{
[PaletteReference]
public readonly string Palette = "shadow";
[Desc("Color to draw shadow.")]
public readonly Color ShadowColor = Color.FromArgb(140, 0, 0, 0);
[Desc("Shadow position offset relative to actor position (ground level).")]
public readonly WVec Offset = WVec.Zero;
@@ -35,11 +35,15 @@ namespace OpenRA.Mods.Common.Traits.Render
public class WithShadow : ConditionalTrait<WithShadowInfo>, IRenderModifier
{
readonly WithShadowInfo info;
readonly float3 shadowColor;
readonly float shadowAlpha;
public WithShadow(WithShadowInfo info)
: base(info)
{
this.info = info;
shadowColor = new float3(info.ShadowColor.R, info.ShadowColor.G, info.ShadowColor.B) / 255f;
shadowAlpha = info.ShadowColor.A / 255f;
}
IEnumerable<IRenderable> IRenderModifier.ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
@@ -47,12 +51,12 @@ namespace OpenRA.Mods.Common.Traits.Render
if (IsTraitDisabled)
return r;
// Contrails shouldn't cast shadows
var height = self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length;
var shadowSprites = r.Where(s => !s.IsDecoration && s is IPalettedRenderable)
.Select(a => ((IPalettedRenderable)a).WithPalette(wr.Palette(info.Palette))
var shadowSprites = r.Where(s => !s.IsDecoration && s is IModifyableRenderable)
.Select(ma => ((IModifyableRenderable)ma).WithTint(shadowColor, ((IModifyableRenderable)ma).TintModifiers | TintModifiers.ReplaceColor)
.WithAlpha(shadowAlpha)
.OffsetBy(info.Offset - new WVec(0, 0, height))
.WithZOffset(a.ZOffset + (height + info.ZOffset))
.WithZOffset(ma.ZOffset + (height + info.ZOffset))
.AsDecoration());
return shadowSprites.Concat(r);