Remove custom palettes from building placement previews.

This commit is contained in:
Paul Chote
2021-01-31 13:45:21 +00:00
committed by reaperrr
parent 5bda6852a4
commit d09476c603
23 changed files with 137 additions and 123 deletions

View File

@@ -25,12 +25,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Enable the building's idle animation.")]
public readonly bool Animated = true;
[PaletteReference(nameof(OverridePaletteIsPlayerPalette))]
[Desc("Custom palette name.")]
public readonly string OverridePalette = null;
[Desc("Custom palette is a player palette BaseName.")]
public readonly bool OverridePaletteIsPlayerPalette = true;
[Desc("Custom opacity to apply to the actor preview.")]
public readonly float PreviewAlpha = 1f;
[Desc("Footprint types to draw underneath the actor preview.")]
public readonly PlaceBuildingCellType FootprintUnderPreview = PlaceBuildingCellType.Valid | PlaceBuildingCellType.LineBuild;
@@ -54,7 +50,6 @@ namespace OpenRA.Mods.Common.Traits
public class ActorPreviewPlaceBuildingPreviewPreview : FootprintPlaceBuildingPreviewPreview
{
readonly ActorPreviewPlaceBuildingPreviewInfo info;
readonly PaletteReference palette;
readonly IActorPreview[] preview;
public ActorPreviewPlaceBuildingPreviewPreview(WorldRenderer wr, ActorInfo ai, ActorPreviewPlaceBuildingPreviewInfo info, TypeDictionary init)
@@ -65,12 +60,6 @@ namespace OpenRA.Mods.Common.Traits
preview = actorInfo.TraitInfos<IRenderActorPreviewInfo>()
.SelectMany(rpi => rpi.RenderPreview(previewInit))
.ToArray();
if (!string.IsNullOrEmpty(info.OverridePalette))
{
var ownerName = init.Get<OwnerInit>().InternalName;
palette = wr.Palette(info.OverridePaletteIsPlayerPalette ? info.OverridePalette + ownerName : info.OverridePalette);
}
}
protected override void TickInner()
@@ -88,15 +77,17 @@ namespace OpenRA.Mods.Common.Traits
var previewRenderables = preview
.SelectMany(p => p.Render(wr, centerPosition));
if (palette != null)
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))
yield return r;
foreach (var r in previewRenderables.OrderBy(WorldRenderer.RenderableZPositionComparisonKey))
yield return r;
{
if (info.PreviewAlpha < 1f && r is IModifyableRenderable mr)
yield return mr.WithAlpha(mr.Alpha * info.PreviewAlpha);
else
yield return r;
}
if (info.FootprintOverPreview != PlaceBuildingCellType.None)
foreach (var r in RenderFootprint(wr, topLeft, footprint, info.FootprintOverPreview))

View File

@@ -25,9 +25,11 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Palette to use for rendering the placement sprite.")]
public readonly string Palette = TileSet.TerrainPaletteInternalName;
[PaletteReference]
[Desc("Palette to use for rendering the placement sprite for line build segments.")]
public readonly string LineBuildSegmentPalette = TileSet.TerrainPaletteInternalName;
[Desc("Custom opacity to apply to the placement sprite.")]
public readonly float FootprintAlpha = 1f;
[Desc("Custom opacity to apply to the line-build placement sprite.")]
public readonly float LineBuildFootprintAlpha = 1f;
protected virtual IPlaceBuildingPreview CreatePreview(WorldRenderer wr, ActorInfo ai, TypeDictionary init)
{
@@ -52,12 +54,6 @@ namespace OpenRA.Mods.Common.Traits
readonly Sprite buildOk;
readonly Sprite buildBlocked;
protected static bool HasFlag(PlaceBuildingCellType value, PlaceBuildingCellType flag)
{
// PERF: Enum.HasFlag is slower and requires allocations.
return (value & flag) == value;
}
public FootprintPlaceBuildingPreviewPreview(WorldRenderer wr, ActorInfo ai, FootprintPlaceBuildingPreviewInfo info, TypeDictionary init)
{
actorInfo = ai;
@@ -81,19 +77,18 @@ namespace OpenRA.Mods.Common.Traits
protected virtual IEnumerable<IRenderable> RenderFootprint(WorldRenderer wr, CPos topLeft, Dictionary<CPos, PlaceBuildingCellType> footprint,
PlaceBuildingCellType filter = PlaceBuildingCellType.Invalid | PlaceBuildingCellType.Valid | PlaceBuildingCellType.LineBuild)
{
var cellPalette = wr.Palette(info.Palette);
var linePalette = wr.Palette(info.LineBuildSegmentPalette);
var palette = wr.Palette(info.Palette);
var topLeftPos = wr.World.Map.CenterOfCell(topLeft);
foreach (var c in footprint)
{
if ((c.Value & filter) == 0)
continue;
var tile = HasFlag(c.Value, PlaceBuildingCellType.Invalid) ? buildBlocked : buildOk;
var pal = HasFlag(c.Value, PlaceBuildingCellType.LineBuild) ? linePalette : cellPalette;
var tile = (c.Value & PlaceBuildingCellType.Invalid) != 0 ? buildBlocked : buildOk;
var pos = wr.World.Map.CenterOfCell(c.Key);
var offset = new WVec(0, 0, topLeftPos.Z - pos.Z);
yield return new SpriteRenderable(tile, pos, offset, -511, pal, 1f, true, TintModifiers.IgnoreWorldTint);
var alpha = (c.Value & PlaceBuildingCellType.LineBuild) != 0 ? info.LineBuildFootprintAlpha : info.FootprintAlpha;
yield return new SpriteRenderable(tile, pos, offset, -511, palette, 1f, alpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
}
}
@@ -107,8 +102,7 @@ namespace OpenRA.Mods.Common.Traits
protected virtual IEnumerable<IRenderable> RenderInner(WorldRenderer wr, CPos topLeft, Dictionary<CPos, PlaceBuildingCellType> footprint)
{
foreach (var r in RenderFootprint(wr, topLeft, footprint))
yield return r;
return RenderFootprint(wr, topLeft, footprint);
}
IEnumerable<IRenderable> IPlaceBuildingPreview.Render(WorldRenderer wr, CPos topLeft, Dictionary<CPos, PlaceBuildingCellType> footprint)

View File

@@ -25,12 +25,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Sequence name to use.")]
public readonly string Sequence = "idle";
[PaletteReference(nameof(SequencePaletteIsPlayerPalette))]
[Desc("Custom palette name.")]
public readonly string SequencePalette = null;
[Desc("Custom palette is a player palette BaseName.")]
public readonly bool SequencePaletteIsPlayerPalette = true;
[Desc("Custom opacity to apply to the sequence sprite.")]
public readonly float SequenceAlpha = 1f;
[Desc("Footprint types to draw underneath the actor preview.")]
public readonly PlaceBuildingCellType FootprintUnderPreview = PlaceBuildingCellType.Valid | PlaceBuildingCellType.LineBuild;
@@ -65,12 +61,7 @@ namespace OpenRA.Mods.Common.Traits
var faction = init.Get<FactionInit>().Value;
var rsi = ai.TraitInfo<RenderSpritesInfo>();
if (!string.IsNullOrEmpty(info.SequencePalette))
palette = wr.Palette(info.SequencePaletteIsPlayerPalette ? info.SequencePalette + ownerName : info.SequencePalette);
else
palette = wr.Palette(rsi.Palette ?? rsi.PlayerPalette + ownerName);
palette = wr.Palette(rsi.Palette ?? rsi.PlayerPalette + ownerName);
preview = new Animation(wr.World, rsi.GetImage(ai, wr.World.Map.Rules.Sequences, faction));
preview.PlayRepeating(info.Sequence);
}
@@ -88,7 +79,12 @@ namespace OpenRA.Mods.Common.Traits
var centerPosition = wr.World.Map.CenterOfCell(topLeft) + centerOffset;
foreach (var r in preview.Render(centerPosition, WVec.Zero, 0, palette))
yield return r;
{
if (info.SequenceAlpha < 1f && r is IModifyableRenderable mr)
yield return mr.WithAlpha(mr.Alpha * info.SequenceAlpha);
else
yield return r;
}
if (info.FootprintOverPreview != PlaceBuildingCellType.None)
foreach (var r in RenderFootprint(wr, topLeft, footprint, info.FootprintOverPreview))

View File

@@ -22,6 +22,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Palette to use for rendering the placement sprite.")]
public readonly string Palette = TileSet.TerrainPaletteInternalName;
[Desc("Custom opacity to apply to the placement sprite.")]
public readonly float FootprintAlpha = 1f;
[Desc("Sequence image where the selection overlay types are defined.")]
public readonly string Image = "editor-overlay";
@@ -89,12 +92,12 @@ namespace OpenRA.Mods.Common.Traits
if (CopyRegion != null)
foreach (var c in CopyRegion)
yield return new SpriteRenderable(copySprite, wr.World.Map.CenterOfCell(c),
WVec.Zero, -511, palette, 1f, true, TintModifiers.IgnoreWorldTint);
WVec.Zero, -511, palette, 1f, info.FootprintAlpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
if (PasteRegion != null)
foreach (var c in PasteRegion)
yield return new SpriteRenderable(pasteSprite, wr.World.Map.CenterOfCell(c),
WVec.Zero, -511, palette, 1f, true, TintModifiers.IgnoreWorldTint);
WVec.Zero, -511, palette, 1f, info.FootprintAlpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
}
bool IRenderAboveShroud.SpatiallyPartitionable { get { return false; } }