From 8c1b0f1afe9805a06fe1e43f9b646759e4cbe3ef Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 15 Sep 2019 16:39:58 +0100 Subject: [PATCH] Add IEffectAnnotation interface. --- OpenRA.Game/Effects/IEffect.cs | 1 + OpenRA.Game/Graphics/WorldRenderer.cs | 5 +++ OpenRA.Mods.Cnc/Effects/GpsDotEffect.cs | 4 +-- OpenRA.Mods.Common/Effects/FloatingText.cs | 8 ++--- .../Effects/RallyPointIndicator.cs | 35 +++++++++++-------- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/OpenRA.Game/Effects/IEffect.cs b/OpenRA.Game/Effects/IEffect.cs index 6014fb4308b9..c77a1dc376c0 100644 --- a/OpenRA.Game/Effects/IEffect.cs +++ b/OpenRA.Game/Effects/IEffect.cs @@ -24,4 +24,5 @@ public interface IEffect public interface ISpatiallyPartitionable { } public interface IEffectAboveShroud { IEnumerable RenderAboveShroud(WorldRenderer wr); } + public interface IEffectAnnotation { IEnumerable RenderAnnotation(WorldRenderer wr); } } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 065d1b0236e5..100776a528ea 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -166,12 +166,17 @@ IEnumerable GenerateAnnotationRenderables() .Where(t => !t.SpatiallyPartitionable || onScreenActors.Contains(a)) .SelectMany(t => t.RenderAnnotations(a, this))); + var effects = World.Effects.Select(e => e as IEffectAnnotation) + .Where(e => e != null) + .SelectMany(e => e.RenderAnnotation(this)); + var orderGenerator = SpriteRenderable.None; if (World.OrderGenerator != null) orderGenerator = World.OrderGenerator.RenderAnnotations(this, World); return actors .Concat(selected) + .Concat(effects) .Concat(orderGenerator) .Select(r => r.PrepareRender(this)); } diff --git a/OpenRA.Mods.Cnc/Effects/GpsDotEffect.cs b/OpenRA.Mods.Cnc/Effects/GpsDotEffect.cs index c7f37ce91ea1..88a0e3d377cc 100644 --- a/OpenRA.Mods.Cnc/Effects/GpsDotEffect.cs +++ b/OpenRA.Mods.Cnc/Effects/GpsDotEffect.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Cnc.Effects { - class GpsDotEffect : IEffect, IEffectAboveShroud + class GpsDotEffect : IEffect, IEffectAnnotation { readonly Actor actor; readonly GpsDotInfo info; @@ -97,7 +97,7 @@ IEnumerable IEffect.Render(WorldRenderer wr) return SpriteRenderable.None; } - IEnumerable IEffectAboveShroud.RenderAboveShroud(WorldRenderer wr) + IEnumerable IEffectAnnotation.RenderAnnotation(WorldRenderer wr) { if (actor.World.RenderPlayer == null || !dotStates[actor.World.RenderPlayer].Visible) return SpriteRenderable.None; diff --git a/OpenRA.Mods.Common/Effects/FloatingText.cs b/OpenRA.Mods.Common/Effects/FloatingText.cs index f035319a3c7a..d153db18a081 100644 --- a/OpenRA.Mods.Common/Effects/FloatingText.cs +++ b/OpenRA.Mods.Common/Effects/FloatingText.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Effects { - public class FloatingText : IEffect, IEffectAboveShroud + public class FloatingText : IEffect, IEffectAnnotation { static readonly WVec Velocity = new WVec(0, 0, 86); @@ -37,7 +37,7 @@ public FloatingText(WPos pos, Color color, string text, int duration) remaining = duration; } - public void Tick(World world) + void IEffect.Tick(World world) { if (--remaining <= 0) world.AddFrameEndTask(w => w.Remove(this)); @@ -45,9 +45,9 @@ public void Tick(World world) pos += Velocity; } - public IEnumerable Render(WorldRenderer wr) { return SpriteRenderable.None; } + IEnumerable IEffect.Render(WorldRenderer wr) { return SpriteRenderable.None; } - public IEnumerable RenderAboveShroud(WorldRenderer wr) + IEnumerable IEffectAnnotation.RenderAnnotation(WorldRenderer wr) { if (wr.World.FogObscures(pos) || wr.World.ShroudObscures(pos)) yield break; diff --git a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs index 61b644772e80..cb359fd3ed7b 100644 --- a/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs +++ b/OpenRA.Mods.Common/Effects/RallyPointIndicator.cs @@ -10,13 +10,14 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Effects; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; namespace OpenRA.Mods.Common.Effects { - class RallyPointIndicator : IEffect, IEffectAboveShroud + class RallyPointIndicator : IEffect, IEffectAboveShroud, IEffectAnnotation { readonly Actor building; readonly RallyPoint rp; @@ -92,26 +93,32 @@ IEnumerable IEffectAboveShroud.RenderAboveShroud(WorldRenderer wr) if (!building.World.Selection.Contains(building)) return SpriteRenderable.None; - return RenderInner(wr); - } - - IEnumerable RenderInner(WorldRenderer wr) - { - if (Game.Settings.Game.TargetLines != TargetLinesType.Disabled) - yield return new TargetLineRenderable(targetLine, building.Owner.Color, rp.Info.LineWidth); - + var renderables = SpriteRenderable.None; if (circles != null || flag != null) { var palette = wr.Palette(rp.PaletteName); - if (circles != null) - foreach (var r in circles.Render(targetLine[1], palette)) - yield return r; + renderables = renderables.Concat(circles.Render(targetLine[1], palette)); if (flag != null) - foreach (var r in flag.Render(targetLine[1], palette)) - yield return r; + renderables = renderables.Concat(flag.Render(targetLine[1], palette)); } + + return renderables; + } + + IEnumerable IEffectAnnotation.RenderAnnotation(WorldRenderer wr) + { + if (Game.Settings.Game.TargetLines == TargetLinesType.Disabled) + return SpriteRenderable.None; + + if (!building.IsInWorld || !building.Owner.IsAlliedWith(building.World.LocalPlayer)) + return SpriteRenderable.None; + + if (!building.World.Selection.Contains(building)) + return SpriteRenderable.None; + + return new IRenderable[] { new TargetLineRenderable(targetLine, building.Owner.Color, rp.Info.LineWidth) }; } } }