From 0ff078968d9ab5030c3a262e4d43cf24e050761d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 1 Sep 2019 18:59:08 +0100 Subject: [PATCH] Change IPlaceBuildingDecorationInfo to use annotations. --- OpenRA.Mods.Cnc/Traits/Render/RenderJammerCircle.cs | 2 +- OpenRA.Mods.Cnc/Traits/Render/RenderShroudCircle.cs | 2 +- .../Orders/PlaceBuildingOrderGenerator.cs | 7 ++++++- .../Buildings/ActorPreviewPlaceBuildingPreview.cs | 3 --- OpenRA.Mods.Common/Traits/Buildings/Building.cs | 2 +- .../Buildings/FootprintPlaceBuildingPreview.cs | 12 +++++++----- .../Traits/Buildings/SequencePlaceBuildingPreview.cs | 2 +- .../Traits/Render/RenderRangeCircle.cs | 2 +- OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs | 2 +- OpenRA.Mods.Common/TraitsInterfaces.cs | 2 +- 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/Render/RenderJammerCircle.cs b/OpenRA.Mods.Cnc/Traits/Render/RenderJammerCircle.cs index 20cd072aa9..23ccf6de07 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/RenderJammerCircle.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/RenderJammerCircle.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Cnc.Traits // TODO: remove all the Render*Circle duplication class RenderJammerCircleInfo : TraitInfo, IPlaceBuildingDecorationInfo { - public IEnumerable Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) + public IEnumerable RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) { var jamsMissiles = ai.TraitInfoOrDefault(); if (jamsMissiles != null) diff --git a/OpenRA.Mods.Cnc/Traits/Render/RenderShroudCircle.cs b/OpenRA.Mods.Cnc/Traits/Render/RenderShroudCircle.cs index 8894155b41..517ec261fa 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/RenderShroudCircle.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/RenderShroudCircle.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Cnc.Traits [Desc("Contrast color of the circle.")] public readonly Color ContrastColor = Color.FromArgb(96, Color.Black); - public IEnumerable Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) + public IEnumerable RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) { var localRange = ai.TraitInfos() .Where(csi => csi.EnabledByDefault) diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index cbfe7bc39d..4f5c0c6a41 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -34,6 +34,7 @@ namespace OpenRA.Mods.Common.Orders int2 TopLeftScreenOffset { get; } void Tick(); IEnumerable Render(WorldRenderer wr, CPos topLeft, Dictionary footprint); + IEnumerable RenderAnnotations(WorldRenderer wr, CPos topLeft); } public class PlaceBuildingOrderGenerator : IOrderGenerator @@ -281,7 +282,11 @@ namespace OpenRA.Mods.Common.Orders return preview != null ? preview.Render(wr, topLeft, footprint) : Enumerable.Empty(); } - IEnumerable IOrderGenerator.RenderAnnotations(WorldRenderer wr, World world) { yield break; } + IEnumerable IOrderGenerator.RenderAnnotations(WorldRenderer wr, World world) + { + var preview = variants[variant].Preview; + return preview != null ? preview.RenderAnnotations(wr, TopLeft) : Enumerable.Empty(); + } string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return "default"; } diff --git a/OpenRA.Mods.Common/Traits/Buildings/ActorPreviewPlaceBuildingPreview.cs b/OpenRA.Mods.Common/Traits/Buildings/ActorPreviewPlaceBuildingPreview.cs index 4039414584..57b1d5bbeb 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/ActorPreviewPlaceBuildingPreview.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/ActorPreviewPlaceBuildingPreview.cs @@ -91,9 +91,6 @@ namespace OpenRA.Mods.Common.Traits if (palette != null) previewRenderables = previewRenderables.Select(a => a.IsDecoration ? a : a.WithPalette(palette)); - foreach (var r in RenderDecorations(wr, topLeft)) - yield return r; - if (info.FootprintUnderPreview != PlaceBuildingCellType.None) foreach (var r in RenderFootprint(wr, topLeft, footprint, info.FootprintUnderPreview)) yield return r; diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index a65dbad8bb..7042f96967 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -233,7 +233,7 @@ namespace OpenRA.Mods.Common.Traits bool IOccupySpaceInfo.SharesCell { get { return false; } } - public IEnumerable Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) + public IEnumerable RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) { if (!RequiresBaseProvider) return SpriteRenderable.None; diff --git a/OpenRA.Mods.Common/Traits/Buildings/FootprintPlaceBuildingPreview.cs b/OpenRA.Mods.Common/Traits/Buildings/FootprintPlaceBuildingPreview.cs index b5b17f1d59..033eb4f4d6 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FootprintPlaceBuildingPreview.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FootprintPlaceBuildingPreview.cs @@ -97,19 +97,16 @@ namespace OpenRA.Mods.Common.Traits } } - protected IEnumerable RenderDecorations(WorldRenderer wr, CPos topLeft) + protected virtual IEnumerable RenderAnnotations(WorldRenderer wr, CPos topLeft) { var centerPosition = wr.World.Map.CenterOfCell(topLeft) + centerOffset; foreach (var d in decorations) - foreach (var r in d.Render(wr, wr.World, actorInfo, centerPosition)) + foreach (var r in d.RenderAnnotations(wr, wr.World, actorInfo, centerPosition)) yield return r; } protected virtual IEnumerable RenderInner(WorldRenderer wr, CPos topLeft, Dictionary footprint) { - foreach (var r in RenderDecorations(wr, topLeft)) - yield return r; - foreach (var r in RenderFootprint(wr, topLeft, footprint)) yield return r; } @@ -119,6 +116,11 @@ namespace OpenRA.Mods.Common.Traits return RenderInner(wr, topLeft, footprint); } + IEnumerable IPlaceBuildingPreview.RenderAnnotations(WorldRenderer wr, CPos topLeft) + { + return RenderAnnotations(wr, topLeft); + } + void IPlaceBuildingPreview.Tick() { TickInner(); } int2 IPlaceBuildingPreview.TopLeftScreenOffset { get { return topLeftScreenOffset; } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/SequencePlaceBuildingPreview.cs b/OpenRA.Mods.Common/Traits/Buildings/SequencePlaceBuildingPreview.cs index 98ef86d52c..6f3104f841 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/SequencePlaceBuildingPreview.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/SequencePlaceBuildingPreview.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits protected override IEnumerable RenderInner(WorldRenderer wr, CPos topLeft, Dictionary footprint) { - foreach (var r in RenderDecorations(wr, topLeft)) + foreach (var r in RenderAnnotations(wr, topLeft)) yield return r; if (info.FootprintUnderPreview != PlaceBuildingCellType.None) diff --git a/OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs b/OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs index 41a988698c..a5dd3b5f66 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits.Render // Computed range Lazy range; - public IEnumerable Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) + public IEnumerable RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) { if (range == null || range.Value == WDist.Zero) return SpriteRenderable.None; diff --git a/OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs b/OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs index a69827befe..dd9bce9aa3 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Range of the circle")] public readonly WDist Range = WDist.Zero; - public IEnumerable Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) + public IEnumerable RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) { if (EnabledByDefault) { diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 65bc255700..2b8271c74c 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits public interface IPlaceBuildingDecorationInfo : ITraitInfo { - IEnumerable Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition); + IEnumerable RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition); } [RequireExplicitImplementation]