Remove custom palettes from building placement previews.
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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; } }
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
{
|
||||
public class RemovePlaceBuildingPalette : UpdateRule
|
||||
{
|
||||
public override string Name { get { return "*PlaceBuildingPreview palette overrides have been removed."; } }
|
||||
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "The palette overrides on the ActorPreviewPlaceBuildingPreview, FootprintPlaceBuildingPreview\n" +
|
||||
"SequencePlaceBuildingPreview, and D2kActorPreviewPlaceBuildingPreview traits have been removed.\n" +
|
||||
"New Alpha and LineBuildSegmentAlpha properties have been added in their place.";
|
||||
}
|
||||
}
|
||||
|
||||
readonly List<string> locations = new List<string>();
|
||||
|
||||
public override IEnumerable<string> AfterUpdate(ModData modData)
|
||||
{
|
||||
if (locations.Any())
|
||||
yield return "The *Palette fields have been removed from the *PlaceBuildingPreview traits.\n" +
|
||||
"You may wish to inspect the following definitions and define new Alpha or\n" +
|
||||
"LineBuildSegmentAlpha properties as appropriate to recreate transparency effects:\n" +
|
||||
UpdateUtils.FormatMessageList(locations);
|
||||
|
||||
locations.Clear();
|
||||
}
|
||||
|
||||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
|
||||
{
|
||||
var removed = 0;
|
||||
foreach (var node in actorNode.ChildrenMatching("ActorPreviewPlaceBuildingPreview"))
|
||||
{
|
||||
removed += node.RemoveNodes("OverridePalette");
|
||||
removed += node.RemoveNodes("OverridePaletteIsPlayerPalette");
|
||||
removed += node.RemoveNodes("LineBuildSegmentPalette");
|
||||
}
|
||||
|
||||
foreach (var node in actorNode.ChildrenMatching("D2kActorPreviewPlaceBuildingPreview"))
|
||||
{
|
||||
removed += node.RemoveNodes("OverridePalette");
|
||||
removed += node.RemoveNodes("OverridePaletteIsPlayerPalette");
|
||||
removed += node.RemoveNodes("LineBuildSegmentPalette");
|
||||
}
|
||||
|
||||
foreach (var node in actorNode.ChildrenMatching("FootprintPlaceBuildingPreview"))
|
||||
removed += node.RemoveNodes("LineBuildSegmentPalette");
|
||||
|
||||
foreach (var node in actorNode.ChildrenMatching("SequencePlaceBuildingPreview"))
|
||||
{
|
||||
removed += node.RemoveNodes("SequencePalette");
|
||||
removed += node.RemoveNodes("SequencePaletteIsPlayerPalette");
|
||||
removed += node.RemoveNodes("LineBuildSegmentPalette");
|
||||
}
|
||||
|
||||
if (removed > 0)
|
||||
locations.Add("{0} ({1})".F(actorNode.Key, actorNode.Location.Filename));
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
||||
new RemovePlayerHighlightPalette(),
|
||||
new ReplaceWithColoredOverlayPalette(),
|
||||
new RemoveRenderSpritesScale(),
|
||||
new RemovePlaceBuildingPalette(),
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user