Add Visualization chat commands

This commit is contained in:
rob-v
2017-05-21 09:17:31 +02:00
committed by Oliver Brakmann
parent 8403adba37
commit d4e9e0e069
18 changed files with 145 additions and 71 deletions

View 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;
}
}
}
}