Add directional icons to crew monitors (#7404)

This commit is contained in:
Leon Friedrich
2022-04-09 13:50:59 +12:00
committed by GitHub
parent 1c9062e881
commit 91a70bdaac
12 changed files with 226 additions and 40 deletions

View File

@@ -1,10 +1,10 @@
using System.Linq;
using System.Linq;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Medical.SuitSensors;
using Content.Server.UserInterface;
using Content.Shared.Medical.CrewMonitoring;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Content.Shared.Movement.Components;
using Robust.Shared.Map;
using Robust.Shared.Timing;
namespace Content.Server.Medical.CrewMonitoring
@@ -13,6 +13,7 @@ namespace Content.Server.Medical.CrewMonitoring
{
[Dependency] private readonly SuitSensorSystem _sensors = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
private const float UpdateRate = 3f;
private float _updateDif;
@@ -66,9 +67,22 @@ namespace Content.Server.Medical.CrewMonitoring
if (ui == null)
return;
// For directional arrows, we need to fetch the monitor's transform data
var xform = Transform(uid);
var (worldPos, worldRot) = xform.GetWorldPositionRotation();
// In general, the directions displayed depend on either the orientation of the grid, or the orientation of
// the monitor. But in the special case where the monitor IS a player (i.e., admin ghost), we base it off
// the players eye rotation. We don't know what that is for sure, but we know their last grid angle, which
// should work well enough?
if (TryComp(uid, out IMoverComponent? mover))
worldRot = mover.LastGridAngle;
else if (_mapManager.TryGetGrid(xform.GridID, out var grid))
worldRot = grid.WorldRotation;
// update all sensors info
var allSensors = component.ConnectedSensors.Values.ToList();
var uiState = new CrewMonitoringState(allSensors);
var uiState = new CrewMonitoringState(allSensors, worldPos, worldRot, component.Snap, component.Precision);
ui.SetState(uiState);
}