Reimplement RenderDetectionCircle trails.
This commit is contained in:
88
OpenRA.Mods.Common/Graphics/DetectionCircleRenderable.cs
Normal file
88
OpenRA.Mods.Common/Graphics/DetectionCircleRenderable.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.Common.Graphics
|
||||
{
|
||||
public struct DetectionCircleRenderable : IRenderable, IFinalizedRenderable
|
||||
{
|
||||
readonly WPos centerPosition;
|
||||
readonly WDist radius;
|
||||
readonly int zOffset;
|
||||
readonly int trailCount;
|
||||
readonly WAngle trailSeparation;
|
||||
readonly WAngle trailAngle;
|
||||
readonly Color color;
|
||||
readonly Color contrastColor;
|
||||
|
||||
public DetectionCircleRenderable(WPos centerPosition, WDist radius, int zOffset,
|
||||
int lineTrails, WAngle trailSeparation, WAngle trailAngle, Color color, Color contrastColor)
|
||||
{
|
||||
this.centerPosition = centerPosition;
|
||||
this.radius = radius;
|
||||
this.zOffset = zOffset;
|
||||
this.trailCount = lineTrails;
|
||||
this.trailSeparation = trailSeparation;
|
||||
this.trailAngle = trailAngle;
|
||||
this.color = color;
|
||||
this.contrastColor = contrastColor;
|
||||
}
|
||||
|
||||
public WPos Pos { get { return centerPosition; } }
|
||||
public PaletteReference Palette { get { return null; } }
|
||||
public int ZOffset { get { return zOffset; } }
|
||||
public bool IsDecoration { get { return true; } }
|
||||
|
||||
public IRenderable WithPalette(PaletteReference newPalette)
|
||||
{
|
||||
return new DetectionCircleRenderable(centerPosition, radius, zOffset,
|
||||
trailCount, trailAngle, trailSeparation, color, contrastColor);
|
||||
}
|
||||
|
||||
public IRenderable WithZOffset(int newOffset)
|
||||
{
|
||||
return new DetectionCircleRenderable(centerPosition, radius, newOffset,
|
||||
trailCount, trailAngle, trailSeparation, color, contrastColor);
|
||||
}
|
||||
|
||||
public IRenderable OffsetBy(WVec vec)
|
||||
{
|
||||
return new DetectionCircleRenderable(centerPosition + vec, radius, zOffset,
|
||||
trailCount, trailAngle, trailSeparation, color, contrastColor);
|
||||
}
|
||||
|
||||
public IRenderable AsDecoration() { return this; }
|
||||
|
||||
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
var wcr = Game.Renderer.WorldRgbaColorRenderer;
|
||||
var center = wr.ScreenPosition(centerPosition);
|
||||
|
||||
for (var i = 0; i < trailCount; i++)
|
||||
{
|
||||
var angle = trailAngle - new WAngle(i * (trailSeparation.Angle <= 512 ? 1 : -1));
|
||||
var length = radius.Length * new WVec(angle.Cos(), angle.Sin(), 0) / 1024;
|
||||
var end = wr.ScreenPosition(centerPosition + length);
|
||||
var alpha = color.A - i * color.A / trailCount;
|
||||
|
||||
wcr.DrawLine(center, end, 3, Color.FromArgb(alpha, contrastColor));
|
||||
wcr.DrawLine(center, end, 1, Color.FromArgb(alpha, color));
|
||||
}
|
||||
|
||||
RangeCircleRenderable.DrawRangeCircle(wr, centerPosition, radius, 1, color, 3, contrastColor);
|
||||
}
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr) { }
|
||||
public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; }
|
||||
}
|
||||
}
|
||||
@@ -713,6 +713,7 @@
|
||||
<Compile Include="Widgets\Logic\MultiplayerLogic.cs" />
|
||||
<Compile Include="EditorBrushes\EditorCopyPasteBrush.cs" />
|
||||
<Compile Include="Traits\World\EditorSelectionLayer.cs" />
|
||||
<Compile Include="Graphics\DetectionCircleRenderable.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -19,14 +19,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class RenderDetectionCircleInfo : ITraitInfo, Requires<DetectCloakedInfo>
|
||||
{
|
||||
[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("Number of trailing Radar update lines.")]
|
||||
public readonly int TrailCount = 0;
|
||||
|
||||
[Desc("Color of the circle and scanner update line.")]
|
||||
public readonly Color Color = Color.FromArgb(128, Color.LimeGreen);
|
||||
@@ -62,34 +59,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (range == WDist.Zero)
|
||||
yield break;
|
||||
|
||||
yield return new RangeCircleRenderable(
|
||||
yield return new DetectionCircleRenderable(
|
||||
self.CenterPosition,
|
||||
range,
|
||||
0,
|
||||
info.TrailCount,
|
||||
info.UpdateLineTick,
|
||||
lineAngle,
|
||||
info.Color,
|
||||
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)
|
||||
|
||||
@@ -146,5 +146,5 @@ LPST:
|
||||
UpgradeMinEnabledLevel: 1
|
||||
Range: 18c0
|
||||
RenderDetectionCircle:
|
||||
DrawUpdateLine: true
|
||||
TrailCount: 3
|
||||
|
||||
|
||||
Reference in New Issue
Block a user