Skip to content

Commit

Permalink
Add IEffectAnnotation interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote authored and abcdefg30 committed Oct 20, 2019
1 parent 0ff0789 commit 8c1b0f1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions OpenRA.Game/Effects/IEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public interface IEffect
public interface ISpatiallyPartitionable { }

public interface IEffectAboveShroud { IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr); }
public interface IEffectAnnotation { IEnumerable<IRenderable> RenderAnnotation(WorldRenderer wr); }
}
5 changes: 5 additions & 0 deletions OpenRA.Game/Graphics/WorldRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,17 @@ IEnumerable<IFinalizedRenderable> 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));
}
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Cnc/Effects/GpsDotEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace OpenRA.Mods.Cnc.Effects
{
class GpsDotEffect : IEffect, IEffectAboveShroud
class GpsDotEffect : IEffect, IEffectAnnotation
{
readonly Actor actor;
readonly GpsDotInfo info;
Expand Down Expand Up @@ -97,7 +97,7 @@ IEnumerable<IRenderable> IEffect.Render(WorldRenderer wr)
return SpriteRenderable.None;
}

IEnumerable<IRenderable> IEffectAboveShroud.RenderAboveShroud(WorldRenderer wr)
IEnumerable<IRenderable> IEffectAnnotation.RenderAnnotation(WorldRenderer wr)
{
if (actor.World.RenderPlayer == null || !dotStates[actor.World.RenderPlayer].Visible)
return SpriteRenderable.None;
Expand Down
8 changes: 4 additions & 4 deletions OpenRA.Mods.Common/Effects/FloatingText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -37,17 +37,17 @@ 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));

pos += Velocity;
}

public IEnumerable<IRenderable> Render(WorldRenderer wr) { return SpriteRenderable.None; }
IEnumerable<IRenderable> IEffect.Render(WorldRenderer wr) { return SpriteRenderable.None; }

public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr)
IEnumerable<IRenderable> IEffectAnnotation.RenderAnnotation(WorldRenderer wr)
{
if (wr.World.FogObscures(pos) || wr.World.ShroudObscures(pos))
yield break;
Expand Down
35 changes: 21 additions & 14 deletions OpenRA.Mods.Common/Effects/RallyPointIndicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,26 +93,32 @@ IEnumerable<IRenderable> IEffectAboveShroud.RenderAboveShroud(WorldRenderer wr)
if (!building.World.Selection.Contains(building))
return SpriteRenderable.None;

return RenderInner(wr);
}

IEnumerable<IRenderable> 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<IRenderable> 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) };
}
}
}

0 comments on commit 8c1b0f1

Please sign in to comment.