Make all range circles fully configurable.

This commit is contained in:
Matthias Mailänder
2020-10-17 18:33:16 +02:00
committed by Paul Chote
parent 214aa64ce3
commit 14fc0254c6
12 changed files with 205 additions and 44 deletions

View File

@@ -56,6 +56,18 @@ namespace OpenRA.Mods.Cnc.Traits
[VoiceReference]
public readonly string Voice = "Action";
[Desc("Range circle color.")]
public readonly Color CircleColor = Color.FromArgb(128, Color.LawnGreen);
[Desc("Range circle line width.")]
public readonly float CircleWidth = 1;
[Desc("Range circle border color.")]
public readonly Color CircleBorderColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle border width.")]
public readonly float CircleBorderWidth = 3;
public override object Create(ActorInitializer init) { return new PortableChrono(init.Self, this); }
}
@@ -232,8 +244,10 @@ namespace OpenRA.Mods.Cnc.Traits
self.CenterPosition,
WDist.FromCells(self.Trait<PortableChrono>().Info.MaxDistance),
0,
Color.FromArgb(128, Color.LawnGreen),
Color.FromArgb(96, Color.Black));
info.CircleColor,
info.CircleWidth,
info.CircleBorderColor,
info.CircleBorderWidth);
}
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)

View File

@@ -22,6 +22,18 @@ namespace OpenRA.Mods.Cnc.Traits
{
class AttackOrderPowerInfo : SupportPowerInfo, Requires<AttackBaseInfo>
{
[Desc("Range circle color.")]
public readonly Color CircleColor = Color.Red;
[Desc("Range circle line width.")]
public readonly float CircleWidth = 1;
[Desc("Range circle border color.")]
public readonly Color CircleBorderColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle border width.")]
public readonly float CircleBorderWidth = 3;
public override object Create(ActorInitializer init) { return new AttackOrderPower(init.Self, this); }
}
@@ -118,21 +130,26 @@ namespace OpenRA.Mods.Cnc.Traits
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world)
{
var info = instance.Info as AttackOrderPowerInfo;
foreach (var a in instance.Instances.Where(i => !i.IsTraitPaused))
{
yield return new RangeCircleAnnotationRenderable(
a.Self.CenterPosition,
attack.GetMinimumRange(),
0,
Color.Red,
Color.FromArgb(96, Color.Black));
info.CircleColor,
info.CircleWidth,
info.CircleBorderColor,
info.CircleBorderWidth);
yield return new RangeCircleAnnotationRenderable(
a.Self.CenterPosition,
attack.GetMaximumRange(),
0,
Color.Red,
Color.FromArgb(96, Color.Black));
info.CircleColor,
info.CircleWidth,
info.CircleBorderColor,
info.CircleBorderWidth);
}
}

View File

@@ -23,10 +23,12 @@ namespace OpenRA.Mods.Common.Graphics
readonly WAngle trailSeparation;
readonly WAngle trailAngle;
readonly Color color;
readonly Color contrastColor;
readonly float width;
readonly Color borderColor;
readonly float borderWidth;
public DetectionCircleAnnotationRenderable(WPos centerPosition, WDist radius, int zOffset,
int lineTrails, WAngle trailSeparation, WAngle trailAngle, Color color, Color contrastColor)
int lineTrails, WAngle trailSeparation, WAngle trailAngle, Color color, float width, Color borderColor, float borderWidth)
{
this.centerPosition = centerPosition;
this.radius = radius;
@@ -35,7 +37,9 @@ namespace OpenRA.Mods.Common.Graphics
this.trailSeparation = trailSeparation;
this.trailAngle = trailAngle;
this.color = color;
this.contrastColor = contrastColor;
this.width = width;
this.borderColor = borderColor;
this.borderWidth = borderWidth;
}
public WPos Pos { get { return centerPosition; } }
@@ -46,19 +50,19 @@ namespace OpenRA.Mods.Common.Graphics
public IRenderable WithPalette(PaletteReference newPalette)
{
return new DetectionCircleAnnotationRenderable(centerPosition, radius, zOffset,
trailCount, trailSeparation, trailAngle, color, contrastColor);
trailCount, trailSeparation, trailAngle, color, width, borderColor, borderWidth);
}
public IRenderable WithZOffset(int newOffset)
{
return new DetectionCircleAnnotationRenderable(centerPosition, radius, newOffset,
trailCount, trailSeparation, trailAngle, color, contrastColor);
trailCount, trailSeparation, trailAngle, color, width, borderColor, borderWidth);
}
public IRenderable OffsetBy(WVec vec)
{
return new DetectionCircleAnnotationRenderable(centerPosition + vec, radius, zOffset,
trailCount, trailSeparation, trailAngle, color, contrastColor);
trailCount, trailSeparation, trailAngle, color, width, borderColor, borderWidth);
}
public IRenderable AsDecoration() { return this; }
@@ -75,11 +79,11 @@ namespace OpenRA.Mods.Common.Graphics
var length = radius.Length * new WVec(angle.Cos(), angle.Sin(), 0) / 1024;
var end = wr.Viewport.WorldToViewPx(wr.Screen3DPosition(centerPosition + length));
var alpha = color.A - i * color.A / trailCount;
cr.DrawLine(center, end, 3, Color.FromArgb(alpha, contrastColor));
cr.DrawLine(center, end, 1, Color.FromArgb(alpha, color));
cr.DrawLine(center, end, borderWidth, Color.FromArgb(alpha, borderColor));
cr.DrawLine(center, end, width, Color.FromArgb(alpha, color));
}
RangeCircleAnnotationRenderable.DrawRangeCircle(wr, centerPosition, radius, 1, color, 3, contrastColor);
RangeCircleAnnotationRenderable.DrawRangeCircle(wr, centerPosition, radius, width, color, borderWidth, borderColor);
}
public void RenderDebugGeometry(WorldRenderer wr) { }

View File

@@ -24,15 +24,19 @@ namespace OpenRA.Mods.Common.Graphics
readonly WDist radius;
readonly int zOffset;
readonly Color color;
readonly Color contrastColor;
readonly float width;
readonly Color borderColor;
readonly float borderWidth;
public RangeCircleAnnotationRenderable(WPos centerPosition, WDist radius, int zOffset, Color color, Color contrastColor)
public RangeCircleAnnotationRenderable(WPos centerPosition, WDist radius, int zOffset, Color color, float width, Color borderColor, float borderWidth)
{
this.centerPosition = centerPosition;
this.radius = radius;
this.zOffset = zOffset;
this.color = color;
this.contrastColor = contrastColor;
this.width = width;
this.borderColor = borderColor;
this.borderWidth = borderWidth;
}
public WPos Pos { get { return centerPosition; } }
@@ -40,19 +44,19 @@ namespace OpenRA.Mods.Common.Graphics
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new RangeCircleAnnotationRenderable(centerPosition, radius, zOffset, color, contrastColor); }
public IRenderable WithZOffset(int newOffset) { return new RangeCircleAnnotationRenderable(centerPosition, radius, newOffset, color, contrastColor); }
public IRenderable OffsetBy(WVec vec) { return new RangeCircleAnnotationRenderable(centerPosition + vec, radius, zOffset, color, contrastColor); }
public IRenderable WithPalette(PaletteReference newPalette) { return new RangeCircleAnnotationRenderable(centerPosition, radius, zOffset, color, width, borderColor, borderWidth); }
public IRenderable WithZOffset(int newOffset) { return new RangeCircleAnnotationRenderable(centerPosition, radius, newOffset, color, width, borderColor, borderWidth); }
public IRenderable OffsetBy(WVec vec) { return new RangeCircleAnnotationRenderable(centerPosition + vec, radius, zOffset, color, width, borderColor, borderWidth); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
public void Render(WorldRenderer wr)
{
DrawRangeCircle(wr, centerPosition, radius, 1, color, 3, contrastColor);
DrawRangeCircle(wr, centerPosition, radius, width, color, borderWidth, borderColor);
}
public static void DrawRangeCircle(WorldRenderer wr, WPos centerPosition, WDist radius,
float width, Color color, float contrastWidth, Color contrastColor)
float width, Color color, float borderWidth, Color borderColor)
{
var cr = Game.Renderer.RgbaColorRenderer;
var offset = new WVec(radius.Length, 0, 0);
@@ -61,8 +65,8 @@ namespace OpenRA.Mods.Common.Graphics
var a = wr.Viewport.WorldToViewPx(wr.ScreenPosition(centerPosition + offset.Rotate(ref RangeCircleStartRotations[i])));
var b = wr.Viewport.WorldToViewPx(wr.ScreenPosition(centerPosition + offset.Rotate(ref RangeCircleEndRotations[i])));
if (contrastWidth > 0)
cr.DrawLine(a, b, contrastWidth, contrastColor);
if (borderWidth > 0)
cr.DrawLine(a, b, borderWidth, borderColor);
if (width > 0)
cr.DrawLine(a, b, width, color);

View File

@@ -24,6 +24,21 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Cooldown = 0;
public readonly int InitialDelay = 0;
[Desc("Range circle color when operational.")]
public readonly Color CircleReadyColor = Color.FromArgb(128, Color.White);
[Desc("Range circle color when inactive.")]
public readonly Color CircleBlockedColor = Color.FromArgb(128, Color.Red);
[Desc("Range circle line width.")]
public readonly float CircleWidth = 1;
[Desc("Range circle border color.")]
public readonly Color CircleBorderColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle border width.")]
public readonly float CircleBorderWidth = 3;
public override object Create(ActorInitializer init) { return new BaseProvider(init.Self, this); }
}
@@ -85,8 +100,10 @@ namespace OpenRA.Mods.Common.Traits
self.CenterPosition,
Info.Range,
0,
Color.FromArgb(128, Ready() ? Color.White : Color.Red),
Color.FromArgb(96, Color.Black));
Ready() ? Info.CircleReadyColor : Info.CircleBlockedColor,
Info.CircleWidth,
Info.CircleBorderColor,
Info.CircleBorderWidth);
}
IEnumerable<IRenderable> IRenderAnnotationsWhenSelected.RenderAnnotations(Actor self, WorldRenderer wr)

View File

@@ -29,8 +29,14 @@ namespace OpenRA.Mods.Common.Traits.Render
[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);
[Desc("Range circle line width.")]
public readonly float Width = 1;
[Desc("Border color of the circle and scanner update line.")]
public readonly Color BorderColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle border width.")]
public readonly float BorderWidth = 3;
public override object Create(ActorInitializer init) { return new RenderDetectionCircle(init.Self, this); }
}
@@ -65,7 +71,9 @@ namespace OpenRA.Mods.Common.Traits.Render
info.UpdateLineTick,
lineAngle,
info.Color,
info.ContrastColor);
info.Width,
info.BorderColor,
info.BorderWidth);
}
bool IRenderAnnotationsWhenSelected.SpatiallyPartitionable { get { return false; } }

View File

@@ -18,8 +18,20 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
// TODO: remove all the Render*Circle duplication
class RenderJammerCircleInfo : TraitInfo<RenderJammerCircle>, IPlaceBuildingDecorationInfo
class RenderJammerCircleInfo : TraitInfo, IPlaceBuildingDecorationInfo
{
[Desc("Range circle color.")]
public readonly Color Color = Color.FromArgb(128, Color.Red);
[Desc("Range circle line width.")]
public readonly float Width = 1;
[Desc("Range circle border color.")]
public readonly Color BorderColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle border width.")]
public readonly float BorderWidth = 3;
public IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
var jamsMissiles = ai.TraitInfoOrDefault<JamsMissilesInfo>();
@@ -29,8 +41,10 @@ namespace OpenRA.Mods.Common.Traits
centerPosition,
jamsMissiles.Range,
0,
Color.FromArgb(128, Color.Red),
Color.FromArgb(96, Color.Black));
Color,
Width,
BorderColor,
BorderWidth);
}
foreach (var a in w.ActorsWithTrait<RenderJammerCircle>())
@@ -38,10 +52,19 @@ namespace OpenRA.Mods.Common.Traits
foreach (var r in a.Trait.RenderAnnotations(a.Actor, wr))
yield return r;
}
public override object Create(ActorInitializer init) { return new RenderJammerCircle(this); }
}
class RenderJammerCircle : IRenderAnnotationsWhenSelected
{
readonly RenderJammerCircleInfo info;
public RenderJammerCircle(RenderJammerCircleInfo info)
{
this.info = info;
}
public IEnumerable<IRenderable> RenderAnnotations(Actor self, WorldRenderer wr)
{
if (!self.Owner.IsAlliedWith(self.World.RenderPlayer))
@@ -54,8 +77,10 @@ namespace OpenRA.Mods.Common.Traits
self.CenterPosition,
jamsMissiles.Range,
0,
Color.FromArgb(128, Color.Red),
Color.FromArgb(96, Color.Black));
info.Color,
info.Width,
info.BorderColor,
info.BorderWidth);
}
}

View File

@@ -35,9 +35,15 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Color of the circle.")]
public readonly Color Color = Color.FromArgb(128, Color.Yellow);
[Desc("Color of the border of the circle.")]
[Desc("Range circle line width.")]
public readonly float Width = 1;
[Desc("Color of the border.")]
public readonly Color BorderColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle border width.")]
public readonly float BorderWidth = 3;
// Computed range
Lazy<WDist> range;
@@ -51,7 +57,9 @@ namespace OpenRA.Mods.Common.Traits.Render
range.Value,
0,
Color,
BorderColor);
Width,
BorderColor,
BorderWidth);
var otherRanges = w.ActorsWithTrait<RenderRangeCircle>()
.Where(a => a.Trait.Info.RangeCircleType == RangeCircleType)
@@ -105,7 +113,9 @@ namespace OpenRA.Mods.Common.Traits.Render
range,
0,
Info.Color,
Info.BorderColor);
Info.Width,
Info.BorderColor,
Info.BorderWidth);
}
IEnumerable<IRenderable> IRenderAnnotationsWhenSelected.RenderAnnotations(Actor self, WorldRenderer wr)

View File

@@ -23,8 +23,14 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Color of the circle.")]
public readonly Color Color = Color.FromArgb(128, Color.Cyan);
[Desc("Contrast color of the circle.")]
public readonly Color ContrastColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle line width.")]
public readonly float Width = 1;
[Desc("Border color of the circle.")]
public readonly Color BorderColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle border width.")]
public readonly float BorderWidth = 3;
public IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
@@ -39,7 +45,9 @@ namespace OpenRA.Mods.Common.Traits
localRange,
0,
Color,
ContrastColor);
Width,
BorderColor,
BorderWidth);
var otherRangeRenderables = w.ActorsWithTrait<RenderShroudCircle>()
.SelectMany(a => a.Trait.RangeCircleRenderables(a.Actor, wr));
@@ -78,7 +86,9 @@ namespace OpenRA.Mods.Common.Traits
range,
0,
info.Color,
info.ContrastColor);
info.Width,
info.BorderColor,
info.BorderWidth);
}
IEnumerable<IRenderable> IRenderAnnotationsWhenSelected.RenderAnnotations(Actor self, WorldRenderer wr)

View File

@@ -28,6 +28,15 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Color of the circle")]
public readonly Color Color = Color.FromArgb(128, Color.White);
[Desc("Border width.")]
public readonly float Width = 1;
[Desc("Color of the border.")]
public readonly Color BorderColor = Color.FromArgb(96, Color.Black);
[Desc("Range circle border width.")]
public readonly float BorderWidth = 3;
[Desc("If set, the color of the owning player will be used instead of `Color`.")]
public readonly bool UsePlayerColor = false;
@@ -50,7 +59,9 @@ namespace OpenRA.Mods.Common.Traits.Render
Range,
0,
Color,
Color.FromArgb(96, Color.Black));
Width,
BorderColor,
BorderWidth);
foreach (var a in w.ActorsWithTrait<WithRangeCircle>())
if (a.Trait.Info.Type == Type)
@@ -92,7 +103,9 @@ namespace OpenRA.Mods.Common.Traits.Render
Info.Range,
0,
Info.UsePlayerColor ? self.Owner.Color : Info.Color,
Color.FromArgb(96, Color.Black));
Info.Width,
Info.BorderColor,
Info.BorderWidth);
}
IEnumerable<IRenderable> IRenderAnnotationsWhenSelected.RenderAnnotations(Actor self, WorldRenderer wr)

View File

@@ -0,0 +1,38 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class RenameCircleContrast : UpdateRule
{
public override string Name { get { return "Rename 'ContrastColor' to 'BorderColor'."; } }
public override string Description
{
get
{
return "RenderDetectionCircle and RenderShroudCircle ContrastColor have been renamed to BorderColor for consistency.";
}
}
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
foreach (var rdc in actorNode.ChildrenMatching("RenderDetectionCircle"))
rdc.RenameChildrenMatching("ContrastColor", "BorderColor");
foreach (var rsc in actorNode.ChildrenMatching("RenderShroudCircle"))
rsc.RenameChildrenMatching("ContrastColor", "BorderColor");
yield break;
}
}
}

View File

@@ -75,6 +75,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new RemoveMuzzleSplitFacings(),
new RemoveTurnToDock(),
new RenameSmudgeSmokeFields(),
new RenameCircleContrast(),
})
};