Have crew monitor display entity coordinates instead (#13120)

closes https://github.com/space-wizards/space-station-14/issues/13042
This commit is contained in:
keronshb
2023-01-09 08:25:46 -05:00
committed by GitHub
parent 05975606cf
commit 72bddb6bdb
5 changed files with 20 additions and 16 deletions

View File

@@ -18,6 +18,7 @@ namespace Content.Client.Medical.CrewMonitoring
private List<Control> _rowsContent = new();
private List<(DirectionIcon Icon, Vector2 Position)> _directionIcons = new();
private readonly IEyeManager _eye;
private readonly IEntityManager _entityManager;
public static int IconSize = 16; // XAML has a `VSeparationOverride` of 20 for each row.
@@ -25,6 +26,7 @@ namespace Content.Client.Medical.CrewMonitoring
{
RobustXamlLoader.Load(this);
_eye = IoCManager.Resolve<IEyeManager>();
_entityManager = IoCManager.Resolve<IEntityManager>();
}
public void ShowSensors(List<SuitSensorStatus> stSensors, Vector2 worldPosition, bool snap, float precision)
@@ -72,7 +74,7 @@ namespace Content.Client.Medical.CrewMonitoring
}
}
private BoxContainer GetPositionBox(MapCoordinates? coordinates, Vector2 sensorPosition, bool snap, float precision)
private BoxContainer GetPositionBox(EntityCoordinates? coordinates, Vector2 sensorPosition, bool snap, float precision)
{
var box = new BoxContainer() { Orientation = LayoutOrientation.Horizontal };
@@ -90,6 +92,7 @@ namespace Content.Client.Medical.CrewMonitoring
{
// todo: add locations names (kitchen, bridge, etc)
var pos = (Vector2i) coordinates.Value.Position;
var mapCoords = coordinates.Value.ToMap(_entityManager).Position;
var dirIcon = new DirectionIcon(snap, precision)
{
SetSize = (IconSize, IconSize),
@@ -97,7 +100,7 @@ namespace Content.Client.Medical.CrewMonitoring
};
box.AddChild(dirIcon);
box.AddChild(new Label() { Text = pos.ToString() });
_directionIcons.Add((dirIcon, coordinates.Value.Position - sensorPosition));
_directionIcons.Add((dirIcon, mapCoords - sensorPosition));
}
return box;

View File

@@ -3,6 +3,7 @@ using Content.Server.DeviceNetwork.Systems;
using Content.Server.Medical.SuitSensors;
using Content.Server.UserInterface;
using Content.Shared.Medical.CrewMonitoring;
using Robust.Shared.Map;
using Robust.Shared.Timing;
namespace Content.Server.Medical.CrewMonitoring
@@ -66,9 +67,9 @@ namespace Content.Server.Medical.CrewMonitoring
return;
// update all sensors info
var worldPos = _xform.GetWorldPosition(uid);
var xform = Transform(uid);
var allSensors = component.ConnectedSensors.Values.ToList();
var uiState = new CrewMonitoringState(allSensors, worldPos, component.Snap, component.Precision);
var uiState = new CrewMonitoringState(allSensors, xform.WorldPosition, component.Snap, component.Precision);
ui.SetState(uiState);
}

View File

@@ -12,7 +12,6 @@ using Content.Shared.MobState.Components;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Timing;
@@ -26,6 +25,7 @@ namespace Content.Server.Medical.SuitSensors
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly SharedTransformSystem _xform = default!;
private const float UpdateRate = 1f;
private float _updateDif;
@@ -228,7 +228,7 @@ namespace Content.Server.Medical.SuitSensors
return null;
// check if sensor is enabled and worn by user
if (sensor.Mode == SuitSensorMode.SensorOff || sensor.User == null)
if (sensor.Mode == SuitSensorMode.SensorOff || sensor.User == null || transform.GridUid == null)
return null;
// try to get mobs id from ID slot
@@ -245,18 +245,17 @@ namespace Content.Server.Medical.SuitSensors
// get health mob state
var isAlive = false;
if (EntityManager.TryGetComponent(sensor.User.Value, out MobStateComponent? mobState))
{
isAlive = _mobStateSystem.IsAlive(sensor.User.Value, mobState);
}
// get mob total damage
var totalDamage = 0;
if (EntityManager.TryGetComponent(sensor.User.Value, out DamageableComponent? damageable))
{
if (TryComp<DamageableComponent>(sensor.User.Value, out var damageable))
totalDamage = damageable.TotalDamage.Int();
}
// finally, form suit sensor status
var xForm = Transform(sensor.User.Value);
var xFormQuery = GetEntityQuery<TransformComponent>();
var coords = _xform.GetMoverCoordinates(xForm, xFormQuery);
var status = new SuitSensorStatus(userName, userJob);
switch (sensor.Mode)
{
@@ -270,7 +269,7 @@ namespace Content.Server.Medical.SuitSensors
case SuitSensorMode.SensorCords:
status.IsAlive = isAlive;
status.TotalDamage = totalDamage;
status.Coordinates = transform.MapPosition;
status.Coordinates = coords;
break;
}
@@ -295,6 +294,7 @@ namespace Content.Server.Medical.SuitSensors
if (status.Coordinates != null)
payload.Add(SuitSensorConstants.NET_CORDINATES, status.Coordinates);
return payload;
}
@@ -316,13 +316,13 @@ namespace Content.Server.Medical.SuitSensors
// try get total damage and cords (optionals)
payload.TryGetValue(SuitSensorConstants.NET_TOTAL_DAMAGE, out int? totalDamage);
payload.TryGetValue(SuitSensorConstants.NET_CORDINATES, out MapCoordinates? cords);
payload.TryGetValue(SuitSensorConstants.NET_CORDINATES, out EntityCoordinates? cords);
var status = new SuitSensorStatus(name, job)
{
IsAlive = isAlive.Value,
TotalDamage = totalDamage,
Coordinates = cords
Coordinates = cords,
};
return status;
}

View File

@@ -17,7 +17,7 @@ namespace Content.Shared.Medical.SuitSensor
public string Job;
public bool IsAlive;
public int? TotalDamage;
public MapCoordinates? Coordinates;
public EntityCoordinates? Coordinates;
}
[Serializable, NetSerializable]

View File

@@ -71,7 +71,7 @@
randomMode: false
controlsLocked: true
mode: SensorCords
activationContainer: "ImplantContainer"
activationContainer: "implant"
- type: DeviceNetwork
deviceNetId: Wireless
transmitFrequencyId: SuitSensor