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;
@@ -43,37 +43,42 @@ namespace OpenRA.Mods.Common.Traits.Render
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{ {
yield return new RangeCircleRenderable( if (EnabledByDefault)
centerPosition, {
Range, yield return new RangeCircleRenderable(
0, centerPosition,
Color, Range,
Color.FromArgb(96, Color.Black)); 0,
Color,
Color.FromArgb(96, Color.Black));
foreach (var a in w.ActorsWithTrait<WithRangeCircle>()) foreach (var a in w.ActorsWithTrait<WithRangeCircle>())
if (a.Trait.Info.Type == Type) if (a.Trait.Info.Type == Type)
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); } public override object Create(ActorInitializer init) { return new WithRangeCircle(init.Self, this); }
} }
class WithRangeCircle : IRenderAboveShroudWhenSelected, IRenderAboveWorld 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);
} }