Admin Tool: Observe entities in an extra viewport (#36969)
* camera * add console command * change verb name to camera * placeholder text * add button to player panel * orks are indeed the best * visibility flag fix * not a datafield * more follower fixes * more cleanup * add zooming * resizing real * remove commented out code * remove AddForceSend * comment * Use OS window and add some comments * fix comments and variable name * Needs RT update * Minor grammarchange * Fix warning * Cleanup * almost working... * fix bug * oswindow update * Remove need for RequestClosed. --------- Co-authored-by: beck-thompson <beck314159@hotmail.com> Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
This commit is contained in:
58
Content.Server/Administration/Commands/CameraCommand.cs
Normal file
58
Content.Server/Administration/Commands/CameraCommand.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Content.Server.Administration.UI;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Administration.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public sealed class CameraCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly EuiManager _eui = default!;
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
|
||||
public override string Command => "camera";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (shell.Player is not { } user)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NetEntity.TryParse(args[0], out var targetNetId) || !_entManager.TryGetEntity(targetNetId, out var targetUid))
|
||||
{
|
||||
if (!_playerManager.TryGetSessionByUsername(args[0], out var player)
|
||||
|| player.AttachedEntity == null)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("cmd-camera-wrong-argument"));
|
||||
return;
|
||||
}
|
||||
targetUid = player.AttachedEntity.Value;
|
||||
}
|
||||
|
||||
var ui = new AdminCameraEui(targetUid.Value);
|
||||
_eui.OpenEui(ui, user);
|
||||
}
|
||||
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
return CompletionResult.FromHintOptions(
|
||||
CompletionHelper.SessionNames(players: _playerManager),
|
||||
Loc.GetString("cmd-camera-hint"));
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
@@ -388,6 +388,22 @@ namespace Content.Server.Administration.Systems
|
||||
Icon = new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Actions/actions_borg.rsi"), "state-laws"),
|
||||
});
|
||||
}
|
||||
|
||||
// open camera
|
||||
args.Verbs.Add(new Verb()
|
||||
{
|
||||
Priority = 10,
|
||||
Text = Loc.GetString("admin-verbs-camera"),
|
||||
Message = Loc.GetString("admin-verbs-camera-description"),
|
||||
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/vv.svg.192dpi.png")),
|
||||
Category = VerbCategory.Admin,
|
||||
Act = () =>
|
||||
{
|
||||
var ui = new AdminCameraEui(args.Target);
|
||||
_euiManager.OpenEui(ui, player);
|
||||
},
|
||||
Impact = LogImpact.Low
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
97
Content.Server/Administration/UI/AdminCameraEui.cs
Normal file
97
Content.Server/Administration/UI/AdminCameraEui.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.Follower;
|
||||
using Content.Shared.Coordinates;
|
||||
using Robust.Server.GameStates;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.Administration.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Admin Eui for opening a viewport window to observe entities.
|
||||
/// Use the "Open Camera" admin verb or the "camera" command to open.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public sealed partial class AdminCameraEui : BaseEui
|
||||
{
|
||||
[Dependency] private readonly IAdminManager _admin = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private readonly FollowerSystem _follower = default!;
|
||||
private readonly PvsOverrideSystem _pvs = default!;
|
||||
private readonly SharedViewSubscriberSystem _viewSubscriber = default!;
|
||||
|
||||
private static readonly EntProtoId CameraProtoId = "AdminCamera";
|
||||
|
||||
private readonly EntityUid _target;
|
||||
private EntityUid? _camera;
|
||||
|
||||
|
||||
public AdminCameraEui(EntityUid target)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_follower = _entityManager.System<FollowerSystem>();
|
||||
_pvs = _entityManager.System<PvsOverrideSystem>();
|
||||
_viewSubscriber = _entityManager.System<SharedViewSubscriberSystem>();
|
||||
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
base.Opened();
|
||||
|
||||
_camera = CreateCamera(_target, Player);
|
||||
StateDirty();
|
||||
}
|
||||
|
||||
public override void Closed()
|
||||
{
|
||||
base.Closed();
|
||||
|
||||
_entityManager.DeleteEntity(_camera);
|
||||
}
|
||||
|
||||
public override void HandleMessage(EuiMessageBase msg)
|
||||
{
|
||||
base.HandleMessage(msg);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case AdminCameraFollowMessage:
|
||||
if (!_admin.HasAdminFlag(Player, AdminFlags.Admin) || Player.AttachedEntity == null)
|
||||
return;
|
||||
_follower.StartFollowingEntity(Player.AttachedEntity.Value, _target);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
var name = _entityManager.GetComponent<MetaDataComponent>(_target).EntityName;
|
||||
var netEnt = _entityManager.GetNetEntity(_camera);
|
||||
return new AdminCameraEuiState(netEnt, name, _timing.CurTick);
|
||||
}
|
||||
|
||||
private EntityUid CreateCamera(EntityUid target, ICommonSession observer)
|
||||
{
|
||||
// Spawn a camera entity attached to the target.
|
||||
var coords = target.ToCoordinates();
|
||||
var camera = _entityManager.SpawnAttachedTo(CameraProtoId, coords);
|
||||
|
||||
// Allow the user to see the entities near the camera.
|
||||
// This also force sends the camera entity to the user, overriding the visibility flags.
|
||||
// (The camera entity has its visibility flags set to VisibilityFlags.Admin so that cheat clients can't see it)
|
||||
_viewSubscriber.AddViewSubscriber(camera, observer);
|
||||
|
||||
return camera;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user