Add Visualization chat commands
This commit is contained in:
70
OpenRA.Mods.Common/Commands/DebugVisualizationCommands.cs
Normal file
70
OpenRA.Mods.Common/Commands/DebugVisualizationCommands.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 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;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Commands
|
||||
{
|
||||
[Desc("Enables visualization commands via the chatbox. Attach this to the world actor.")]
|
||||
public class DebugVisualizationCommandsInfo : TraitInfo<DebugVisualizationCommands> { }
|
||||
|
||||
public class DebugVisualizationCommands : IChatCommand, IWorldLoaded
|
||||
{
|
||||
DebugVisualizations debugVis;
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
{
|
||||
var world = w;
|
||||
debugVis = world.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
|
||||
if (debugVis == null)
|
||||
return;
|
||||
|
||||
var console = world.WorldActor.Trait<ChatCommands>();
|
||||
var help = world.WorldActor.Trait<HelpCommand>();
|
||||
|
||||
Action<string, string> register = (name, helpText) =>
|
||||
{
|
||||
console.RegisterCommand(name, this);
|
||||
help.RegisterHelp(name, helpText);
|
||||
};
|
||||
|
||||
register("showcombatgeometry", "toggles combat geometry overlay.");
|
||||
register("showrendergeometry", "toggles render geometry overlay.");
|
||||
register("showdepthbuffer", "toggles depth buffer overlay.");
|
||||
register("showactortags", "toggles actor tags overlay.");
|
||||
}
|
||||
|
||||
public void InvokeCommand(string name, string arg)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "showcombatgeometry":
|
||||
debugVis.CombatGeometry ^= true;
|
||||
break;
|
||||
|
||||
case "showrendergeometry":
|
||||
debugVis.RenderGeometry ^= true;
|
||||
break;
|
||||
|
||||
case "showdepthbuffer":
|
||||
debugVis.DepthBuffer ^= true;
|
||||
break;
|
||||
|
||||
case "showactortags":
|
||||
debugVis.ActorTags ^= true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,6 +157,7 @@
|
||||
<Compile Include="Commands\DevCommands.cs" />
|
||||
<Compile Include="Commands\HelpCommand.cs" />
|
||||
<Compile Include="Commands\PlayerCommands.cs" />
|
||||
<Compile Include="Commands\DebugVisualizationCommands.cs" />
|
||||
<Compile Include="Graphics\ActorPreview.cs" />
|
||||
<Compile Include="Graphics\BeamRenderable.cs" />
|
||||
<Compile Include="Graphics\ContrailRenderable.cs" />
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
@@ -30,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
static readonly WVec TargetPosHLine = new WVec(0, 128, 0);
|
||||
static readonly WVec TargetPosVLine = new WVec(128, 0, 0);
|
||||
|
||||
readonly DeveloperMode devMode;
|
||||
readonly DebugVisualizations debugVis;
|
||||
readonly HealthInfo healthInfo;
|
||||
readonly Lazy<BodyOrientation> coords;
|
||||
|
||||
@@ -42,8 +41,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
healthInfo = self.Info.TraitInfoOrDefault<HealthInfo>();
|
||||
coords = Exts.Lazy(self.Trait<BodyOrientation>);
|
||||
|
||||
var localPlayer = self.World.LocalPlayer;
|
||||
devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;
|
||||
debugVis = self.World.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
@@ -54,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void IRenderAboveWorld.RenderAboveWorld(Actor self, WorldRenderer wr)
|
||||
{
|
||||
if (devMode == null || !devMode.ShowCombatGeometry)
|
||||
if (debugVis == null || !debugVis.CombatGeometry)
|
||||
return;
|
||||
|
||||
var wcr = Game.Renderer.WorldRgbaColorRenderer;
|
||||
@@ -132,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void INotifyDamage.Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (devMode == null || !devMode.ShowCombatGeometry || e.Damage.Value == 0)
|
||||
if (debugVis == null || !debugVis.CombatGeometry || e.Damage.Value == 0)
|
||||
return;
|
||||
|
||||
if (healthInfo == null)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
class CustomTerrainDebugOverlay : IWorldLoaded, IChatCommand, IRender
|
||||
{
|
||||
const string CommandName = "debugcustomterrain";
|
||||
const string CommandDesc = "Toggles the custom terrain debug overlay.";
|
||||
const string CommandDesc = "toggles the custom terrain debug overlay.";
|
||||
|
||||
public bool Enabled;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
class RenderDebugState : INotifyAddedToWorld, INotifyOwnerChanged, IRenderAboveShroudWhenSelected
|
||||
{
|
||||
readonly DeveloperMode devMode;
|
||||
readonly DebugVisualizations debugVis;
|
||||
readonly SpriteFont font;
|
||||
readonly Actor self;
|
||||
readonly WVec offset;
|
||||
@@ -48,8 +48,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
color = GetColor();
|
||||
font = Game.Renderer.Fonts[info.Font];
|
||||
|
||||
var localPlayer = self.World.LocalPlayer;
|
||||
devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;
|
||||
debugVis = self.World.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
ai = self.Owner.PlayerActor.TraitsImplementing<HackyAI>().FirstOrDefault(x => x.IsEnabled);
|
||||
}
|
||||
|
||||
@@ -70,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
IEnumerable<IRenderable> IRenderAboveShroudWhenSelected.RenderAboveShroud(Actor self, WorldRenderer wr)
|
||||
{
|
||||
if (devMode == null || !devMode.ShowActorTags)
|
||||
if (debugVis == null || !debugVis.ActorTags)
|
||||
yield break;
|
||||
|
||||
yield return new TextRenderable(font, self.CenterPosition - offset, 0, color, tagString);
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public class TerrainGeometryOverlay : IRenderAboveWorld, IWorldLoaded, IChatCommand
|
||||
{
|
||||
const string CommandName = "terrainoverlay";
|
||||
const string CommandDesc = "Toggles the terrain geometry overlay";
|
||||
const string CommandDesc = "toggles the terrain geometry overlay.";
|
||||
|
||||
public bool Enabled;
|
||||
|
||||
|
||||
@@ -25,12 +25,9 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
{
|
||||
var world = firedBy.World;
|
||||
|
||||
if (world.LocalPlayer != null)
|
||||
{
|
||||
var devMode = world.LocalPlayer.PlayerActor.TraitOrDefault<DeveloperMode>();
|
||||
if (devMode != null && devMode.ShowCombatGeometry)
|
||||
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, Spread, DebugOverlayColor);
|
||||
}
|
||||
var debugVis = world.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
if (debugVis != null && debugVis.CombatGeometry)
|
||||
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, Spread, DebugOverlayColor);
|
||||
|
||||
var range = Spread[0];
|
||||
var hitActors = world.FindActorsInCircle(pos, range);
|
||||
|
||||
@@ -54,12 +54,9 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
{
|
||||
var world = firedBy.World;
|
||||
|
||||
if (world.LocalPlayer != null)
|
||||
{
|
||||
var devMode = world.LocalPlayer.PlayerActor.TraitOrDefault<DeveloperMode>();
|
||||
if (devMode != null && devMode.ShowCombatGeometry)
|
||||
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, Range, DebugOverlayColor);
|
||||
}
|
||||
var debugVis = world.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
if (debugVis != null && debugVis.CombatGeometry)
|
||||
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, Range, DebugOverlayColor);
|
||||
|
||||
// This only finds actors where the center is within the search radius,
|
||||
// so we need to search beyond the maximum spread to account for actors with large health radius
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -33,12 +32,9 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
var world = firedBy.World;
|
||||
var debugOverlayRange = new[] { WDist.Zero, new WDist(128) };
|
||||
|
||||
if (world.LocalPlayer != null)
|
||||
{
|
||||
var devMode = world.LocalPlayer.PlayerActor.TraitOrDefault<DeveloperMode>();
|
||||
if (devMode != null && devMode.ShowCombatGeometry)
|
||||
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, debugOverlayRange, DebugOverlayColor);
|
||||
}
|
||||
var debugVis = world.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
if (debugVis != null && debugVis.CombatGeometry)
|
||||
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, debugOverlayRange, DebugOverlayColor);
|
||||
}
|
||||
|
||||
public override void DoImpact(Actor victim, Actor firedBy, IEnumerable<int> damageModifiers)
|
||||
@@ -53,8 +49,9 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
if (world.LocalPlayer != null)
|
||||
{
|
||||
var debugOverlayRange = new[] { WDist.Zero, new WDist(128) };
|
||||
var devMode = world.LocalPlayer.PlayerActor.TraitOrDefault<DeveloperMode>();
|
||||
if (devMode != null && devMode.ShowCombatGeometry)
|
||||
|
||||
var debugVis = world.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
if (debugVis != null && debugVis.CombatGeometry)
|
||||
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(victim.CenterPosition, debugOverlayRange, DebugOverlayColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public DebugMenuLogic(Widget widget, World world)
|
||||
{
|
||||
var devTrait = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
|
||||
var debugVis = world.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||
|
||||
var visibilityCheckbox = widget.GetOrNull<CheckboxWidget>("DISABLE_VISIBILITY_CHECKS");
|
||||
if (visibilityCheckbox != null)
|
||||
@@ -63,15 +64,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var showCombatCheckbox = widget.GetOrNull<CheckboxWidget>("SHOW_COMBATOVERLAY");
|
||||
if (showCombatCheckbox != null)
|
||||
{
|
||||
showCombatCheckbox.IsChecked = () => devTrait.ShowCombatGeometry;
|
||||
showCombatCheckbox.OnClick = () => devTrait.ShowCombatGeometry ^= true;
|
||||
showCombatCheckbox.Disabled = debugVis == null;
|
||||
showCombatCheckbox.IsChecked = () => debugVis != null && debugVis.CombatGeometry;
|
||||
showCombatCheckbox.OnClick = () => debugVis.CombatGeometry ^= true;
|
||||
}
|
||||
|
||||
var showGeometryCheckbox = widget.GetOrNull<CheckboxWidget>("SHOW_GEOMETRY");
|
||||
if (showGeometryCheckbox != null)
|
||||
{
|
||||
showGeometryCheckbox.IsChecked = () => devTrait.ShowDebugGeometry;
|
||||
showGeometryCheckbox.OnClick = () => devTrait.ShowDebugGeometry ^= true;
|
||||
showGeometryCheckbox.Disabled = debugVis == null;
|
||||
showGeometryCheckbox.IsChecked = () => debugVis != null && debugVis.RenderGeometry;
|
||||
showGeometryCheckbox.OnClick = () => debugVis.RenderGeometry ^= true;
|
||||
}
|
||||
|
||||
var terrainGeometryTrait = world.WorldActor.Trait<TerrainGeometryOverlay>();
|
||||
@@ -85,8 +88,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var showDepthPreviewCheckbox = widget.GetOrNull<CheckboxWidget>("SHOW_DEPTH_PREVIEW");
|
||||
if (showDepthPreviewCheckbox != null)
|
||||
{
|
||||
showDepthPreviewCheckbox.IsChecked = () => devTrait.ShowDepthPreview;
|
||||
showDepthPreviewCheckbox.OnClick = () => devTrait.ShowDepthPreview ^= true;
|
||||
showDepthPreviewCheckbox.Disabled = debugVis == null;
|
||||
showDepthPreviewCheckbox.IsChecked = () => debugVis != null && debugVis.DepthBuffer;
|
||||
showDepthPreviewCheckbox.OnClick = () => debugVis.DepthBuffer ^= true;
|
||||
}
|
||||
|
||||
var allTechCheckbox = widget.GetOrNull<CheckboxWidget>("ENABLE_TECH");
|
||||
@@ -123,8 +127,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var showActorTagsCheckbox = widget.GetOrNull<CheckboxWidget>("SHOW_ACTOR_TAGS");
|
||||
if (showActorTagsCheckbox != null)
|
||||
{
|
||||
showActorTagsCheckbox.IsChecked = () => devTrait.ShowActorTags;
|
||||
showActorTagsCheckbox.OnClick = () => devTrait.ShowActorTags ^= true;
|
||||
showActorTagsCheckbox.Disabled = debugVis == null;
|
||||
showActorTagsCheckbox.IsChecked = () => debugVis != null && debugVis.ActorTags;
|
||||
showActorTagsCheckbox.OnClick = () => debugVis.ActorTags ^= true;
|
||||
}
|
||||
|
||||
var showCustomTerrainCheckbox = widget.GetOrNull<CheckboxWidget>("SHOW_CUSTOMTERRAIN_OVERLAY");
|
||||
|
||||
Reference in New Issue
Block a user