Make WithRangeCircle conditional

This commit is contained in:
Mustafa Alperen Seki
2019-02-20 23:53:40 +03:00
committed by reaperrr
parent 2ee6243e67
commit b8a85091d4

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public enum RangeCircleVisibility { Always, WhenSelected } public enum RangeCircleVisibility { Always, WhenSelected }
[Desc("Renders an arbitrary circle when selected or placing a structure")] [Desc("Renders an arbitrary circle when selected or placing a structure")]
class WithRangeCircleInfo : ITraitInfo, IPlaceBuildingDecorationInfo class WithRangeCircleInfo : ConditionalTraitInfo, IPlaceBuildingDecorationInfo
{ {
[Desc("Type of range circle. used to decide which circles to draw on other structures during building placement.")] [Desc("Type of range circle. used to decide which circles to draw on other structures during building placement.")]
public readonly string Type = null; public readonly string Type = null;
@@ -42,6 +42,8 @@ namespace OpenRA.Mods.Common.Traits.Render
public readonly WDist Range = WDist.Zero; public readonly WDist Range = WDist.Zero;
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
if (EnabledByDefault)
{ {
yield return new RangeCircleRenderable( yield return new RangeCircleRenderable(
centerPosition, centerPosition,
@@ -55,25 +57,28 @@ namespace OpenRA.Mods.Common.Traits.Render
foreach (var r in a.Trait.RenderRangeCircle(a.Actor, wr)) foreach (var r in a.Trait.RenderRangeCircle(a.Actor, wr))
yield return r; yield return r;
} }
public object Create(ActorInitializer init) { return new WithRangeCircle(init.Self, this); }
} }
class WithRangeCircle : IRenderAboveShroudWhenSelected, IRenderAboveWorld public override object Create(ActorInitializer init) { return new WithRangeCircle(init.Self, this); }
}
class WithRangeCircle : ConditionalTrait<WithRangeCircleInfo>, IRenderAboveShroudWhenSelected, IRenderAboveWorld
{ {
public readonly WithRangeCircleInfo Info;
readonly Actor self; readonly Actor self;
public WithRangeCircle(Actor self, WithRangeCircleInfo info) public WithRangeCircle(Actor self, WithRangeCircleInfo info)
: base(info)
{ {
this.self = self; this.self = self;
Info = info;
} }
bool Visible bool Visible
{ {
get get
{ {
if (IsTraitDisabled)
return false;
var p = self.World.RenderPlayer; var p = self.World.RenderPlayer;
return p == null || Info.ValidStances.HasStance(self.Owner.Stances[p]) || (p.Spectating && !p.NonCombatant); return p == null || Info.ValidStances.HasStance(self.Owner.Stances[p]) || (p.Spectating && !p.NonCombatant);
} }