Skip to content

Commit

Permalink
Draw border around capture area in ProximityCapturable
Browse files Browse the repository at this point in the history
  • Loading branch information
obrakmann authored and pchote committed Dec 3, 2023
1 parent c4acd8b commit 3904576
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
9 changes: 9 additions & 0 deletions OpenRA.Mods.Common/Traits/ProximityCapturable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/
#endregion

using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Primitives;

namespace OpenRA.Mods.Common.Traits
{
[Desc("Actor can be captured by units within a certain range.")]
Expand Down Expand Up @@ -44,5 +48,10 @@ protected override void TickInner(Actor self)
{
self.World.ActorMap.UpdateProximityTrigger(trigger, self.CenterPosition, Info.Range, WDist.Zero);
}

protected override IRenderable GetRenderable(Actor self, WorldRenderer wr)
{
return new RangeCircleAnnotationRenderable(self.CenterPosition, Info.Range, 0, self.Owner.Color, 1, Color.Black, 3);
}
}
}
17 changes: 16 additions & 1 deletion OpenRA.Mods.Common/Traits/ProximityCapturableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Effects;
using OpenRA.Primitives;
using OpenRA.Traits;
Expand All @@ -33,6 +34,9 @@ public abstract class ProximityCapturableBaseInfo : TraitInfo, IRulesetLoaded
"This option implies the `" + nameof(Sticky) + "` behaviour as well.")]
public readonly bool Permanent = false;

[Desc("If set, will draw a border in the owner's color around the capturable area.")]
public readonly bool DrawDecoration = true;

public void RulesetLoaded(Ruleset rules, ActorInfo info)
{
var pci = rules.Actors[SystemActors.Player].TraitInfoOrDefault<ProximityCaptorInfo>();
Expand All @@ -43,7 +47,7 @@ public void RulesetLoaded(Ruleset rules, ActorInfo info)
public abstract override object Create(ActorInitializer init);
}

public abstract class ProximityCapturableBase : ITick, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOwnerChanged
public abstract class ProximityCapturableBase : ITick, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOwnerChanged, IRenderAnnotations
{
public readonly Player OriginalOwner;
public bool Captured => Self.Owner != OriginalOwner;
Expand All @@ -66,6 +70,7 @@ protected ProximityCapturableBase(ActorInitializer init, ProximityCapturableBase
protected abstract int CreateTrigger(Actor self);
protected abstract void RemoveTrigger(Actor self, int trigger);
protected abstract void TickInner(Actor self);
protected abstract IRenderable GetRenderable(Actor self, WorldRenderer wr);

void INotifyAddedToWorld.AddedToWorld(Actor self)
{
Expand Down Expand Up @@ -192,5 +197,15 @@ void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newO
{
Game.RunAfterTick(() => skipTriggerUpdate = false);
}

IEnumerable<IRenderable> IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr)
{
if (!self.IsInWorld || !Info.DrawDecoration)
return Enumerable.Empty<IRenderable>();

return new[] { GetRenderable(self, wr) };
}

bool IRenderAnnotations.SpatiallyPartitionable { get { return false; } }
}
}
8 changes: 8 additions & 0 deletions OpenRA.Mods.Common/Traits/RegionProximityCapturable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Primitives;

namespace OpenRA.Mods.Common.Traits
{
Expand Down Expand Up @@ -53,6 +56,11 @@ protected override void RemoveTrigger(Actor self, int trigger)
}

protected override void TickInner(Actor self) { }

protected override IRenderable GetRenderable(Actor self, WorldRenderer wr)
{
return new BorderedRegionRenderable(region, self.Owner.Color, 1, Color.Black, 3);
}
}

public class RegionInit : ValueActorInit<CVec[]>
Expand Down

0 comments on commit 3904576

Please sign in to comment.