Draw radar update line for mobile sensors array

This commit is contained in:
teees
2015-11-10 12:53:00 +01:00
parent 7d2c86d75b
commit 2777262cb0
2 changed files with 54 additions and 5 deletions

View File

@@ -19,14 +19,35 @@ namespace OpenRA.Mods.Common.Traits
{ {
class RenderDetectionCircleInfo : ITraitInfo, Requires<DetectCloakedInfo> class RenderDetectionCircleInfo : ITraitInfo, Requires<DetectCloakedInfo>
{ {
public object Create(ActorInitializer init) { return new RenderDetectionCircle(init.Self); } [Desc("Draw a rotating radar scanner update line, disabled by default.")]
public readonly bool DrawUpdateLine = false;
[Desc("WAngle the Radar update line advances per tick.")]
public readonly WAngle UpdateLineTick = new WAngle(-1);
[Desc("Number of trailing Radar update lines, will only draw one line if zero.")]
public readonly int LineTrailLength = 3;
[Desc("Color of the circle and scanner update line.")]
public readonly Color Color = Color.FromArgb(128, Color.LimeGreen);
[Desc("Contrast color of the circle and scanner update line.")]
public readonly Color ContrastColor = Color.FromArgb(96, Color.Black);
public object Create(ActorInitializer init) { return new RenderDetectionCircle(init.Self, this); }
} }
class RenderDetectionCircle : IPostRenderSelection class RenderDetectionCircle : ITick, IPostRenderSelection
{ {
readonly RenderDetectionCircleInfo info;
readonly Actor self; readonly Actor self;
WAngle lineAngle;
public RenderDetectionCircle(Actor self) { this.self = self; } public RenderDetectionCircle(Actor self, RenderDetectionCircleInfo info)
{
this.info = info;
this.self = self;
}
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr) public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr)
{ {
@@ -45,8 +66,35 @@ namespace OpenRA.Mods.Common.Traits
self.CenterPosition, self.CenterPosition,
range, range,
0, 0,
Color.FromArgb(128, Color.LimeGreen), info.Color,
Color.FromArgb(96, Color.Black)); info.ContrastColor);
if (info.DrawUpdateLine)
{
for (var i = info.LineTrailLength; i >= 0; i--)
{
var angle = lineAngle - new WAngle(i * (info.UpdateLineTick.Angle <= 512 ? 1 : -1));
var length = range.Length * new WVec(angle.Cos(), angle.Sin(), 0) / 1024;
var alpha = info.Color.A - (info.LineTrailLength > 0 ? i * info.Color.A / info.LineTrailLength : 0);
yield return new BeamRenderable(
self.CenterPosition,
0,
length,
3,
Color.FromArgb(alpha, info.ContrastColor));
yield return new BeamRenderable(
self.CenterPosition,
0,
length,
1,
Color.FromArgb(alpha, info.Color));
}
}
}
public void Tick(Actor self)
{
lineAngle += info.UpdateLineTick;
} }
} }
} }

View File

@@ -148,4 +148,5 @@ LPST:
UpgradeMinEnabledLevel: 1 UpgradeMinEnabledLevel: 1
Range: 18c0 Range: 18c0
RenderDetectionCircle: RenderDetectionCircle:
DrawUpdateLine: true