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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user