Remove palettes from base IRenderable.

This commit is contained in:
Paul Chote
2020-08-21 18:56:26 +01:00
committed by abcdefg30
parent 71b13c7b5d
commit b88495c689
28 changed files with 28 additions and 59 deletions

View File

@@ -51,8 +51,8 @@ namespace OpenRA.Mods.Common.Effects
{
var palette = wr.Palette(player == null ? "highlight" : "highlight" + player.InternalName);
return target.Render(wr)
.Where(r => !r.IsDecoration)
.Select(r => r.WithPalette(palette));
.Where(r => !r.IsDecoration && r is IPalettedRenderable)
.Select(r => ((IPalettedRenderable)r).WithPalette(palette));
}
return SpriteRenderable.None;

View File

@@ -35,11 +35,9 @@ namespace OpenRA.Mods.Common.Graphics
}
public WPos Pos { get { return pos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new BeamRenderable(pos, zOffset, length, shape, width, color); }
public IRenderable WithZOffset(int newOffset) { return new BeamRenderable(pos, zOffset, length, shape, width, color); }
public IRenderable OffsetBy(WVec vec) { return new BeamRenderable(pos + vec, zOffset, length, shape, width, color); }
public IRenderable AsDecoration() { return this; }

View File

@@ -35,11 +35,9 @@ namespace OpenRA.Mods.Common.Graphics
}
public WPos Pos { get { return centerPosition; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new CircleAnnotationRenderable(centerPosition, radius, width, color, filled); }
public IRenderable WithZOffset(int newOffset) { return new CircleAnnotationRenderable(centerPosition, radius, width, color, filled); }
public IRenderable OffsetBy(WVec vec) { return new CircleAnnotationRenderable(centerPosition + vec, radius, width, color, filled); }
public IRenderable AsDecoration() { return this; }

View File

@@ -46,11 +46,9 @@ namespace OpenRA.Mods.Common.Graphics
}
public WPos Pos { get { return trail[Index(next - 1)]; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new ContrailRenderable(world, (WPos[])trail.Clone(), width, next, length, skip, color, zOffset); }
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, (WPos[])trail.Clone(), width, next, length, skip, color, newOffset); }
public IRenderable OffsetBy(WVec vec) { return new ContrailRenderable(world, trail.Select(pos => pos + vec).ToArray(), width, next, length, skip, color, zOffset); }
public IRenderable AsDecoration() { return this; }

View File

@@ -43,16 +43,9 @@ namespace OpenRA.Mods.Common.Graphics
}
public WPos Pos { get { return centerPosition; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette)
{
return new DetectionCircleAnnotationRenderable(centerPosition, radius, zOffset,
trailCount, trailSeparation, trailAngle, color, width, borderColor, borderWidth);
}
public IRenderable WithZOffset(int newOffset)
{
return new DetectionCircleAnnotationRenderable(centerPosition, radius, newOffset,

View File

@@ -51,11 +51,9 @@ namespace OpenRA.Mods.Common.Graphics
public bool DisplayHealth { get { return displayHealth; } }
public bool DisplayExtra { get { return displayExtra; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return this; }
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(WVec vec) { return new IsometricSelectionBarsAnnotationRenderable(pos + vec, actor, bounds); }
public IRenderable AsDecoration() { return this; }

View File

@@ -50,11 +50,9 @@ namespace OpenRA.Mods.Common.Graphics
public WPos Pos { get { return pos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return this; }
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(WVec vec) { return new IsometricSelectionBoxAnnotationRenderable(pos + vec, bounds, color); }
public IRenderable AsDecoration() { return this; }

View File

@@ -40,11 +40,9 @@ namespace OpenRA.Mods.Common.Graphics
}
public WPos Pos { get { return start; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new LineAnnotationRenderable(start, end, width, startColor, endColor); }
public IRenderable WithZOffset(int newOffset) { return new LineAnnotationRenderable(start, end, width, startColor, endColor); }
public IRenderable OffsetBy(WVec vec) { return new LineAnnotationRenderable(start + vec, end + vec, width, startColor, endColor); }
public IRenderable AsDecoration() { return this; }

View File

@@ -17,7 +17,7 @@ using OpenRA.Primitives;
namespace OpenRA.Mods.Common.Graphics
{
public struct ModelRenderable : IRenderable, ITintableRenderable
public struct ModelRenderable : IPalettedRenderable, ITintableRenderable
{
readonly IEnumerable<ModelAnimation> models;
readonly WPos pos;
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Graphics
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return false; } }
public IRenderable WithPalette(PaletteReference newPalette)
public IPalettedRenderable WithPalette(PaletteReference newPalette)
{
return new ModelRenderable(
models, pos, zOffset, camera, scale,

View File

@@ -31,11 +31,9 @@ namespace OpenRA.Mods.Common.Graphics
}
public WPos Pos { get { return effectivePos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new PolygonAnnotationRenderable(vertices, effectivePos, width, color); }
public IRenderable WithZOffset(int newOffset) { return new PolygonAnnotationRenderable(vertices, effectivePos, width, color); }
public IRenderable OffsetBy(WVec vec) { return new PolygonAnnotationRenderable(vertices.Select(v => v + vec).ToArray(), effectivePos + vec, width, color); }
public IRenderable AsDecoration() { return this; }

View File

@@ -41,11 +41,9 @@ namespace OpenRA.Mods.Common.Graphics
}
public WPos Pos { get { return pos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new RailgunHelixRenderable(pos, zOffset, railgun, info, ticks); }
public IRenderable WithZOffset(int newOffset) { return new RailgunHelixRenderable(pos, newOffset, railgun, info, ticks); }
public IRenderable OffsetBy(WVec vec) { return new RailgunHelixRenderable(pos + vec, zOffset, railgun, info, ticks); }
public IRenderable AsDecoration() { return this; }

View File

@@ -40,11 +40,9 @@ namespace OpenRA.Mods.Common.Graphics
}
public WPos Pos { get { return centerPosition; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new RangeCircleAnnotationRenderable(centerPosition, radius, zOffset, color, width, borderColor, borderWidth); }
public IRenderable WithZOffset(int newOffset) { return new RangeCircleAnnotationRenderable(centerPosition, radius, newOffset, color, width, borderColor, borderWidth); }
public IRenderable OffsetBy(WVec vec) { return new RangeCircleAnnotationRenderable(centerPosition + vec, radius, zOffset, color, width, borderColor, borderWidth); }
public IRenderable AsDecoration() { return this; }

View File

@@ -42,11 +42,9 @@ namespace OpenRA.Mods.Common.Graphics
public bool DisplayHealth { get { return displayHealth; } }
public bool DisplayExtra { get { return displayExtra; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return this; }
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(WVec vec) { return new SelectionBarsAnnotationRenderable(pos + vec, actor, decorationBounds); }
public IRenderable AsDecoration() { return this; }

View File

@@ -32,11 +32,9 @@ namespace OpenRA.Mods.Common.Graphics
public WPos Pos { get { return pos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return this; }
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(WVec vec) { return new SelectionBoxAnnotationRenderable(pos + vec, decorationBounds, color); }
public IRenderable AsDecoration() { return this; }

View File

@@ -43,11 +43,9 @@ namespace OpenRA.Mods.Common.Graphics
text) { }
public WPos Pos { get { return pos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new TextAnnotationRenderable(font, pos, zOffset, color, text); }
public IRenderable WithZOffset(int newOffset) { return new TextAnnotationRenderable(font, pos, zOffset, color, text); }
public IRenderable OffsetBy(WVec vec) { return new TextAnnotationRenderable(font, pos + vec, zOffset, color, text); }
public IRenderable AsDecoration() { return this; }

View File

@@ -17,7 +17,7 @@ using OpenRA.Primitives;
namespace OpenRA.Mods.Common.Graphics
{
public struct UIModelRenderable : IRenderable
public struct UIModelRenderable : IRenderable, IPalettedRenderable
{
readonly IEnumerable<ModelAnimation> models;
readonly WPos effectiveWorldPos;
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Graphics
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return false; } }
public IRenderable WithPalette(PaletteReference newPalette)
public IPalettedRenderable WithPalette(PaletteReference newPalette)
{
return new UIModelRenderable(
models, effectiveWorldPos, screenPos, zOffset, camera, scale,

View File

@@ -45,11 +45,9 @@ namespace OpenRA.Mods.Common.Graphics
text) { }
public WPos Pos { get { return effectiveWorldPos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new UITextRenderable(font, effectiveWorldPos, screenPos, zOffset, color, text); }
public IRenderable WithZOffset(int newOffset) { return new UITextRenderable(font, effectiveWorldPos, screenPos, zOffset, color, text); }
public IRenderable OffsetBy(WVec vec) { return new UITextRenderable(font, effectiveWorldPos + vec, screenPos, zOffset, color, text); }
public IRenderable AsDecoration() { return this; }

View File

@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
.SelectMany(p => p.Render(wr, centerPosition));
if (palette != null)
previewRenderables = previewRenderables.Select(a => a.IsDecoration ? a : a.WithPalette(palette));
previewRenderables = previewRenderables.Select(a => !a.IsDecoration && a is IPalettedRenderable ? ((IPalettedRenderable)a).WithPalette(palette) : a);
if (info.FootprintUnderPreview != PlaceBuildingCellType.None)
foreach (var r in RenderFootprint(wr, topLeft, footprint, info.FootprintUnderPreview))

View File

@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Traits
if (palette == null)
return r;
else
return r.Select(a => a.IsDecoration ? a : a.WithPalette(palette));
return r.Select(a => !a.IsDecoration && a is IPalettedRenderable ? ((IPalettedRenderable)a).WithPalette(palette) : a);
}
else
return SpriteRenderable.None;

View File

@@ -45,8 +45,8 @@ namespace OpenRA.Mods.Common.Traits
{
yield return a;
if (!a.IsDecoration)
yield return a.WithPalette(wr.Palette(Info.Palette))
if (!a.IsDecoration && a is IPalettedRenderable)
yield return ((IPalettedRenderable)a).WithPalette(wr.Palette(Info.Palette))
.WithZOffset(a.ZOffset + 1)
.AsDecoration();
}

View File

@@ -49,8 +49,8 @@ namespace OpenRA.Mods.Common.Traits.Render
// Contrails shouldn't cast shadows
var height = self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length;
var shadowSprites = r.Where(s => !s.IsDecoration)
.Select(a => a.WithPalette(wr.Palette(info.Palette))
var shadowSprites = r.Where(s => !s.IsDecoration && s is IPalettedRenderable)
.Select(a => ((IPalettedRenderable)a).WithPalette(wr.Palette(info.Palette))
.OffsetBy(info.Offset - new WVec(0, 0, height))
.WithZOffset(a.ZOffset + (height + info.ZOffset))
.AsDecoration());

View File

@@ -118,8 +118,8 @@ namespace OpenRA.Mods.Common.Traits
if (Selected)
{
var highlight = worldRenderer.Palette("highlight");
var overlay = items.Where(r => !r.IsDecoration)
.Select(r => r.WithPalette(highlight));
var overlay = items.Where(r => !r.IsDecoration && r is IPalettedRenderable)
.Select(r => ((IPalettedRenderable)r).WithPalette(highlight));
return items.Concat(overlay);
}