Draw targeting lines for player-issued orders. Can force-display targets with [alt].
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -228,6 +228,7 @@
|
||||
<Compile Include="Widgets\TimerWidget.cs" />
|
||||
<Compile Include="Widgets\ShpImageWidget.cs" />
|
||||
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
||||
<Compile Include="Traits\DrawLineToTarget.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
69
OpenRA.Game/Traits/DrawLineToTarget.cs
Normal file
69
OpenRA.Game/Traits/DrawLineToTarget.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class DrawLineToTargetInfo : ITraitInfo
|
||||
{
|
||||
public readonly int Ticks = 60;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new DrawLineToTarget(this); }
|
||||
}
|
||||
|
||||
public class DrawLineToTarget :IRenderSelection
|
||||
{
|
||||
DrawLineToTargetInfo Info;
|
||||
public DrawLineToTarget(DrawLineToTargetInfo info)
|
||||
{
|
||||
this.Info = info;
|
||||
}
|
||||
|
||||
Actor target;
|
||||
float2 pos;
|
||||
int lifetime;
|
||||
Color c;
|
||||
public void SetTarget(Actor self, int2 cell, Color c)
|
||||
{
|
||||
pos = Game.CellSize * (cell + new float2(0.5f, 0.5f));
|
||||
lifetime = Info.Ticks;
|
||||
target = null;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public void SetTarget(Actor self, Actor target, Color c)
|
||||
{
|
||||
this.target = target;
|
||||
lifetime = Info.Ticks;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public void Render (Actor self)
|
||||
{
|
||||
var force = Game.controller.GetModifiers().HasModifier(Modifiers.Alt);
|
||||
if ((lifetime <= 0 || --lifetime <= 0) && !force)
|
||||
return;
|
||||
|
||||
var p = (target != null) ? target.CenterLocation : pos;
|
||||
|
||||
Game.Renderer.LineRenderer.DrawLine(self.CenterLocation, p, c, c);
|
||||
for (bool b = false; !b; p = self.CenterLocation, b = true)
|
||||
{
|
||||
Game.Renderer.LineRenderer.DrawLine(p + new float2(-1, -1), p + new float2(-1, 1), c, c);
|
||||
Game.Renderer.LineRenderer.DrawLine(p + new float2(-1, 1), p + new float2(1, 1), c, c);
|
||||
Game.Renderer.LineRenderer.DrawLine(p + new float2(1, 1), p + new float2(1, -1), c, c);
|
||||
Game.Renderer.LineRenderer.DrawLine(p + new float2(1, -1), p + new float2(-1, -1), c, c);
|
||||
}
|
||||
Game.Renderer.LineRenderer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.FileFormats;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
@@ -111,7 +112,13 @@ namespace OpenRA.Traits
|
||||
if (self.traits.GetOrDefault<IMove>().CanEnterCell(order.TargetLocation))
|
||||
{
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new MoveFlash(self.World, order.TargetLocation)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new MoveFlash(self.World, order.TargetLocation));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetLocation, Color.Green);
|
||||
});
|
||||
|
||||
if( !order.Queued ) self.CancelActivity();
|
||||
self.QueueActivity(new Activities.Move(order.TargetLocation, 8));
|
||||
|
||||
@@ -15,6 +15,7 @@ using OpenRA.Effects;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -246,8 +247,17 @@ namespace OpenRA.Mods.RA
|
||||
self.CancelActivity();
|
||||
QueueAttack(self, order);
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer && order.TargetActor != null)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (order.TargetActor != null)
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
if (order.TargetActor != null) line.SetTarget(self, order.TargetActor, Color.Red);
|
||||
else line.SetTarget(self, order.TargetLocation, Color.Red);
|
||||
});
|
||||
}
|
||||
else
|
||||
target = Target.None;
|
||||
|
||||
@@ -12,6 +12,7 @@ using OpenRA.Effects;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -37,7 +38,13 @@ namespace OpenRA.Mods.RA
|
||||
if (order.OrderString == "C4")
|
||||
{
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetActor, Color.Red);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor));
|
||||
|
||||
@@ -12,6 +12,7 @@ using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -43,7 +44,13 @@ namespace OpenRA.Mods.RA
|
||||
if (order.OrderString == "CaptureBuilding")
|
||||
{
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetActor, Color.Red);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor));
|
||||
|
||||
@@ -12,6 +12,7 @@ using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.Effects;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -53,7 +54,13 @@ namespace OpenRA.Mods.RA
|
||||
if (order.OrderString == "EngineerRepair" && order.TargetActor.Health < order.TargetActor.GetMaxHP())
|
||||
{
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetActor, Color.Yellow);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor));
|
||||
|
||||
@@ -14,6 +14,7 @@ using OpenRA.Effects;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -122,7 +123,13 @@ namespace OpenRA.Mods.RA
|
||||
if (order.OrderString == "Harvest")
|
||||
{
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new MoveFlash(self.World, order.TargetLocation)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new MoveFlash(self.World, order.TargetLocation));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetLocation, Color.Red);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetLocation, 0));
|
||||
@@ -142,7 +149,13 @@ namespace OpenRA.Mods.RA
|
||||
return;
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetActor, Color.Green);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new DeliverResources());
|
||||
|
||||
@@ -15,6 +15,7 @@ using OpenRA.Effects;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -74,7 +75,13 @@ namespace OpenRA.Mods.RA
|
||||
if (order.OrderString == "Move")
|
||||
{
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new MoveFlash(self.World, order.TargetLocation)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new MoveFlash(self.World, order.TargetLocation));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetLocation, Color.Green);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new HeliFly(Util.CenterOfCell(order.TargetLocation)));
|
||||
@@ -98,7 +105,13 @@ namespace OpenRA.Mods.RA
|
||||
var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero;
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetActor, Color.Green);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new HeliFly(order.TargetActor.CenterLocation + offsetVec));
|
||||
|
||||
@@ -12,6 +12,7 @@ using OpenRA.Effects;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -67,7 +68,13 @@ namespace OpenRA.Mods.RA
|
||||
if (!CanEnter(self, order.TargetActor)) return;
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetActor, Color.Green);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetActor.Location, 1));
|
||||
|
||||
@@ -13,6 +13,7 @@ using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -90,7 +91,13 @@ namespace OpenRA.Mods.RA
|
||||
UnReserve();
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new MoveFlash(self.World, order.TargetLocation)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new MoveFlash(self.World, order.TargetLocation));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetLocation, Color.Green);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation)));
|
||||
@@ -109,7 +116,13 @@ namespace OpenRA.Mods.RA
|
||||
var info = self.Info.Traits.Get<PlaneInfo>();
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetActor, Color.Green);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
|
||||
|
||||
@@ -13,6 +13,7 @@ using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -59,7 +60,13 @@ namespace OpenRA.Mods.RA
|
||||
var rp = order.TargetActor.traits.GetOrDefault<RallyPoint>();
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Add(new FlashTarget(order.TargetActor));
|
||||
var line = self.traits.GetOrDefault<DrawLineToTarget>();
|
||||
if (line != null)
|
||||
line.SetTarget(self, order.TargetActor, Color.Green);
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor));
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
RevealsShroud:
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Tank:
|
||||
Category: Vehicle
|
||||
@@ -34,6 +35,7 @@
|
||||
RevealsShroud:
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Helicopter:
|
||||
Category: Plane
|
||||
@@ -49,6 +51,7 @@
|
||||
TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River
|
||||
TerrainSpeeds: 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100%
|
||||
AvoidsAA:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Infantry:
|
||||
Category: Infantry
|
||||
@@ -69,6 +72,7 @@
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
# SharesCell:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Plane:
|
||||
Category: Plane
|
||||
@@ -80,6 +84,7 @@
|
||||
RevealsShroud:
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Building:
|
||||
Category: Building
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
RevealsShroud:
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Tank:
|
||||
Category: Vehicle
|
||||
@@ -35,6 +36,7 @@
|
||||
RevealsShroud:
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Infantry:
|
||||
Category: Infantry
|
||||
@@ -55,6 +57,7 @@
|
||||
TeslaInstantKills:
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Ship:
|
||||
Category: Ship
|
||||
@@ -68,6 +71,7 @@
|
||||
RevealsShroud:
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Plane:
|
||||
Category: Plane
|
||||
@@ -79,6 +83,7 @@
|
||||
RevealsShroud:
|
||||
GainsExperience:
|
||||
GivesExperience:
|
||||
DrawLineToTarget:
|
||||
|
||||
^Building:
|
||||
Category: Building
|
||||
|
||||
Reference in New Issue
Block a user