Improve "monitor" command.

Has -all and +all options, code cleaned up including IDebugMonitors API and implementation.
This commit is contained in:
Pieter-Jan Briers
2022-06-07 00:44:48 +02:00
parent 60ca5beffa
commit ac949a4bee
4 changed files with 131 additions and 100 deletions

View File

@@ -103,3 +103,14 @@ cmd-dump_event_tables-missing-arg-entity = Missing entity argument
cmd-dump_event_tables-error-entity = Invalid entity
cmd-dump_event_tables-arg-entity = <entityUid>
## 'monitor' command
cmd-monitor-desc = Toggles a debug monitor in the F3 menu.
cmd-monitor-help = Usage: monitor <name>
Possible monitors are: { $monitors }
You can also use the special values "-all" and "+all" to hide or show all monitors, respectively.
cmd-monitor-arg-monitor = <monitor>
cmd-monitor-invalid-name = Invalid monitor name
cmd-monitor-arg-count = Missing monitor argument
cmd-monitor-minus-all-hint = Hides all monitors
cmd-monitor-plus-all-hint = Shows all monitors

View File

@@ -19,6 +19,7 @@ using Robust.Shared.Console;
using Robust.Shared.ContentPack;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Network;
@@ -97,54 +98,72 @@ namespace Robust.Client.Console.Commands
{
public string Command => "monitor";
public string Help =>
"Usage: monitor <name>\nPossible monitors are: fps, net, bandwidth, coord, time, frames, mem, clyde, input";
public string Description => Loc.GetString("cmd-monitor-desc");
public string Description => "Toggles a debug monitor in the F3 menu.";
public string Help
{
get
{
var monitors = string.Join(", ", Enum.GetNames<DebugMonitor>());
return Loc.GetString("cmd-monitor-help", ("monitors", monitors));
}
}
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var monitor = IoCManager.Resolve<IUserInterfaceManager>().DebugMonitors;
var monitors = IoCManager.Resolve<IUserInterfaceManager>().DebugMonitors;
if (args.Length != 1)
{
shell.WriteLine(Help);
shell.WriteLine(Loc.GetString("cmd-monitor-arg-count"));
return;
}
switch (args[0])
var monitorArg = args[0];
if (monitorArg.Equals("-all", StringComparison.OrdinalIgnoreCase))
{
case "fps":
monitor.ShowFPS ^= true;
break;
case "net":
monitor.ShowNet ^= true;
break;
case "bandwidth":
monitor.ShowNetBandwidth ^= true;
break;
case "coord":
monitor.ShowCoords ^= true;
break;
case "time":
monitor.ShowTime ^= true;
break;
case "frames":
monitor.ShowFrameGraph ^= true;
break;
case "mem":
monitor.ShowMemory ^= true;
break;
case "clyde":
monitor.ShowClyde ^= true;
break;
case "input":
monitor.ShowInput ^= true;
break;
default:
shell.WriteLine($"Invalid key: {args[0]}");
break;
foreach (var monitor in Enum.GetValues<DebugMonitor>())
{
monitors.SetMonitor(monitor, false);
}
return;
}
if (monitorArg.Equals("+all", StringComparison.OrdinalIgnoreCase))
{
foreach (var monitor in Enum.GetValues<DebugMonitor>())
{
monitors.SetMonitor(monitor, true);
}
return;
}
if (!Enum.TryParse(monitorArg, true, out DebugMonitor parsedMonitor))
{
shell.WriteError(Loc.GetString("cmd-monitor-invalid-name"));
return;
}
monitors.ToggleMonitor(parsedMonitor);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var allOptions = new CompletionOption[]
{
new("-all", Loc.GetString("cmd-monitor-minus-all-hint")),
new("+all", Loc.GetString("cmd-monitor-plus-all-hint"))
};
var options = allOptions.Concat(Enum.GetNames<DebugMonitor>().Select(c => new CompletionOption(c)));
return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-monitor-arg-monitor"));
}
return CompletionResult.Empty;
}
}

View File

@@ -1,4 +1,5 @@
using Robust.Client.GameStates;
using System;
using Robust.Client.GameStates;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
@@ -15,66 +16,43 @@ namespace Robust.Client.UserInterface.CustomControls
{
internal sealed class DebugMonitors : BoxContainer, IDebugMonitors
{
public bool ShowFPS { get => _fpsCounter.Visible; set => _fpsCounter.Visible = value; }
public bool ShowCoords { get => _debugCoordsPanel.Visible; set => _debugCoordsPanel.Visible = value; }
public bool ShowNet { get => _debugNetPanel.Visible; set => _debugNetPanel.Visible = value; }
public bool ShowNetBandwidth { get => _debugNetBandwidthPanel.Visible; set => _debugNetBandwidthPanel.Visible = value; }
public bool ShowTime { get => _timeDebug.Visible; set => _timeDebug.Visible = value; }
public bool ShowFrameGraph { get => _frameGraph.Visible; set => _frameGraph.Visible = value; }
public bool ShowMemory { get => _debugMemoryPanel.Visible; set => _debugMemoryPanel.Visible = value; }
public bool ShowClyde { get => _debugClydePanel.Visible; set => _debugClydePanel.Visible = value; }
public bool ShowInput { get => _debugInputPanel.Visible; set => _debugInputPanel.Visible = value; }
private readonly FpsCounter _fpsCounter;
private readonly DebugCoordsPanel _debugCoordsPanel;
private readonly DebugNetPanel _debugNetPanel;
private readonly DebugTimePanel _timeDebug;
private readonly FrameGraph _frameGraph;
private readonly DebugMemoryPanel _debugMemoryPanel;
private readonly DebugClydePanel _debugClydePanel;
private readonly DebugInputPanel _debugInputPanel;
private readonly DebugNetBandwidthPanel _debugNetBandwidthPanel;
private readonly Control[] _monitors = new Control[Enum.GetNames<DebugMonitor>().Length];
//TODO: Think about a factory for this
public DebugMonitors(IGameTiming gameTiming, IPlayerManager playerManager, IEyeManager eyeManager, IInputManager inputManager, IStateManager stateManager, IClyde displayManager, IClientNetManager netManager, IMapManager mapManager)
public DebugMonitors(IGameTiming gameTiming, IPlayerManager playerManager, IEyeManager eyeManager,
IInputManager inputManager, IStateManager stateManager, IClyde displayManager, IClientNetManager netManager,
IMapManager mapManager)
{
var gameTiming1 = gameTiming;
Visible = false;
Orientation = LayoutOrientation.Vertical;
_fpsCounter = new FpsCounter(gameTiming1);
AddChild(_fpsCounter);
Add(DebugMonitor.Fps, new FpsCounter(gameTiming));
Add(DebugMonitor.Coords, new DebugCoordsPanel());
Add(DebugMonitor.Net, new DebugNetPanel(netManager, gameTiming));
Add(DebugMonitor.Bandwidth, new DebugNetBandwidthPanel(netManager, gameTiming));
Add(DebugMonitor.Time, new DebugTimePanel(gameTiming, IoCManager.Resolve<IClientGameStateManager>()));
Add(DebugMonitor.Frames, new FrameGraph(gameTiming, IoCManager.Resolve<IConfigurationManager>()));
Add(DebugMonitor.Memory, new DebugMemoryPanel());
Add(DebugMonitor.Clyde, new DebugClydePanel { HorizontalAlignment = HAlignment.Left });
Add(DebugMonitor.Input, new DebugInputPanel { HorizontalAlignment = HAlignment.Left });
Add(DebugMonitor.Prof, new LiveProfileViewControl());
_debugCoordsPanel = new DebugCoordsPanel();
AddChild(_debugCoordsPanel);
_debugNetPanel = new DebugNetPanel(netManager, gameTiming1);
AddChild(_debugNetPanel);
_debugNetBandwidthPanel = new DebugNetBandwidthPanel(netManager, gameTiming1);
AddChild(_debugNetBandwidthPanel);
_timeDebug = new DebugTimePanel(gameTiming1, IoCManager.Resolve<IClientGameStateManager>());
AddChild(_timeDebug);
_frameGraph = new FrameGraph(gameTiming1, IoCManager.Resolve<IConfigurationManager>());
AddChild(_frameGraph);
AddChild(_debugMemoryPanel = new DebugMemoryPanel());
AddChild(_debugClydePanel = new DebugClydePanel
void Add(DebugMonitor monitor, Control instance)
{
HorizontalAlignment = HAlignment.Left
});
_monitors[(int)monitor] = instance;
AddChild(instance);
}
}
AddChild(_debugInputPanel = new DebugInputPanel
{
HorizontalAlignment = HAlignment.Left
});
public void ToggleMonitor(DebugMonitor monitor)
{
_monitors[(int)monitor].Visible ^= true;
}
AddChild(new LiveProfileViewControl());
public void SetMonitor(DebugMonitor monitor, bool visible)
{
_monitors[(int)monitor].Visible = visible;
}
}
}

View File

@@ -1,16 +1,39 @@
namespace Robust.Client.UserInterface
namespace Robust.Client.UserInterface;
/// <summary>
/// Manages the debug monitors overlay, AKA "F3 screen".
/// </summary>
public interface IDebugMonitors
{
public interface IDebugMonitors
{
bool Visible { get; set; }
bool ShowFPS { get; set; }
bool ShowCoords { get; set; }
bool ShowNet { get; set; }
bool ShowTime { get; set; }
bool ShowFrameGraph { get; set; }
bool ShowMemory { get; set; }
bool ShowClyde { get; set; }
bool ShowInput { get; set; }
bool ShowNetBandwidth { get; set; }
}
/// <summary>
/// Whether debug monitors are currently visible.
/// </summary>
bool Visible { get; set; }
/// <summary>
/// Toggle visibility of a specific debug monitor.
/// </summary>
void ToggleMonitor(DebugMonitor monitor);
/// <summary>
/// Set visibility of a specific debug monitor.
/// </summary>
void SetMonitor(DebugMonitor monitor, bool visible);
}
/// <summary>
/// Debug monitors available in the debug monitors overlay.
/// </summary>
public enum DebugMonitor
{
Fps,
Coords,
Net,
Time,
Frames,
Memory,
Clyde,
Input,
Bandwidth,
Prof
}