From de63c5230bcab10f5799b73907e0f5c68a9f689d Mon Sep 17 00:00:00 2001 From: Ahion <58528255+Ahion@users.noreply.github.com> Date: Thu, 15 Jun 2023 05:29:52 +0200 Subject: [PATCH] More user friendly crew monitor UI (#17328) --- .../CrewMonitoring/CrewMonitoringWindow.xaml | 10 ++- .../CrewMonitoringWindow.xaml.cs | 80 ++++++++++--------- Content.Client/Pinpointer/UI/NavMapControl.cs | 9 +++ Content.Client/Stylesheets/StyleNano.cs | 5 ++ .../Medical/SuitSensors/SuitSensorSystem.cs | 6 +- .../Medical/SuitSensor/SharedSuitSensor.cs | 7 +- .../components/crew-monitoring-component.ftl | 2 + 7 files changed, 75 insertions(+), 44 deletions(-) diff --git a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml index 99224dbec6..559a12d63b 100644 --- a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml +++ b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml @@ -1,4 +1,4 @@ - + Margin="8, 8, 8, 8"> + diff --git a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs index 96a029603c..95a56f5692 100644 --- a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs +++ b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs @@ -21,6 +21,7 @@ namespace Content.Client.Medical.CrewMonitoring private readonly IEntityManager _entManager; private readonly IEyeManager _eye; private EntityUid? _stationUid; + private CrewMonitoringButton? _trackedButton; public static int IconSize = 16; // XAML has a `VSeparationOverride` of 20 for each row. @@ -52,27 +53,28 @@ namespace Content.Client.Medical.CrewMonitoring // TODO scroll container // TODO filter by name & occupation // TODO make each row a xaml-control. Get rid of some of this c# control creation. + if (stSensors.Count == 0) + { + NoServerLabel.Visible = true; + return; + } + NoServerLabel.Visible = false; // add a row for each sensor foreach (var sensor in stSensors.OrderBy(a => a.Name)) { - // add users name - // format: UserName - var nameLabel = new PanelContainer() + // add button with username + var nameButton = new CrewMonitoringButton() { - PanelOverride = new StyleBoxFlat() - { - BackgroundColor = StyleNano.ButtonColorDisabled, - }, - Children = - { - new Label() - { - Text = sensor.Name, - Margin = new Thickness(5f, 5f), - } - } + SuitSensorUid = sensor.SuitSensorUid, + Coordinates = sensor.Coordinates, + Text = sensor.Name, + Margin = new Thickness(5f, 5f), }; + if (sensor.SuitSensorUid == _trackedButton?.SuitSensorUid) + nameButton.AddStyleClass(StyleNano.StyleClassButtonColorGreen); + SensorsTable.AddChild(nameButton); + _rowsContent.Add(nameButton); // add users job // format: JobName @@ -81,9 +83,6 @@ namespace Content.Client.Medical.CrewMonitoring Text = sensor.Job, HorizontalExpand = true }; - - SensorsTable.AddChild(nameLabel); - _rowsContent.Add(nameLabel); SensorsTable.AddChild(jobLabel); _rowsContent.Add(jobLabel); @@ -112,33 +111,32 @@ namespace Content.Client.Medical.CrewMonitoring if (sensor.Coordinates != null && NavMap.Visible) { - NavMap.TrackedCoordinates.TryAdd(sensor.Coordinates.Value, (true, Color.FromHex("#B02E26"))); - nameLabel.MouseFilter = MouseFilterMode.Stop; + NavMap.TrackedCoordinates.TryAdd(sensor.Coordinates.Value, + (true, sensor.SuitSensorUid == _trackedButton?.SuitSensorUid ? StyleNano.PointGreen : StyleNano.PointRed)); - // Hide all others upon mouseover. - nameLabel.OnMouseEntered += args => + nameButton.OnButtonUp += args => { - foreach (var (coord, value) in NavMap.TrackedCoordinates) - { - if (coord == sensor.Coordinates) - continue; + if (_trackedButton != null && _trackedButton?.Coordinates != null) + //Make previous point red + NavMap.TrackedCoordinates[_trackedButton.Coordinates.Value] = (true, StyleNano.PointRed); - NavMap.TrackedCoordinates[coord] = (false, value.Color); - } - }; + NavMap.TrackedCoordinates[sensor.Coordinates.Value] = (true, StyleNano.PointGreen); + NavMap.CenterToCoordinates(sensor.Coordinates.Value); - nameLabel.OnMouseExited += args => - { - foreach (var (coord, value) in NavMap.TrackedCoordinates) - { - NavMap.TrackedCoordinates[coord] = (true, value.Color); + nameButton.AddStyleClass(StyleNano.StyleClassButtonColorGreen); + if (_trackedButton != null) + { //Make previous button default + var previosButton = SensorsTable.GetChild(_trackedButton.IndexInTable); + previosButton.RemoveStyleClass(StyleNano.StyleClassButtonColorGreen); } + _trackedButton = nameButton; + _trackedButton.IndexInTable = nameButton.GetPositionInParent(); }; } } - // For debugging. - //if (monitorCoords != null) - // NavMap.TrackedCoordinates.Add(monitorCoords.Value, (true, Color.FromHex("#FF00FF"))); + // Show monitor point + if (monitorCoords != null) + NavMap.TrackedCoordinates.Add(monitorCoords.Value, (true, StyleNano.PointMagenta)); } private BoxContainer GetPositionBox(EntityCoordinates? coordinates, Vector2 monitorCoordsInStationSpace, bool snap, float precision) @@ -203,10 +201,16 @@ namespace Content.Client.Medical.CrewMonitoring { SensorsTable.RemoveChild(child); } - _rowsContent.Clear(); _directionIcons.Clear(); NavMap.TrackedCoordinates.Clear(); } } + + public sealed class CrewMonitoringButton : Button + { + public int IndexInTable; + public EntityUid? SuitSensorUid; + public EntityCoordinates? Coordinates; + } } diff --git a/Content.Client/Pinpointer/UI/NavMapControl.cs b/Content.Client/Pinpointer/UI/NavMapControl.cs index 723030b768..2e63ef0ece 100644 --- a/Content.Client/Pinpointer/UI/NavMapControl.cs +++ b/Content.Client/Pinpointer/UI/NavMapControl.cs @@ -95,6 +95,15 @@ public sealed class NavMapControl : MapGridControl }; } + public void CenterToCoordinates(EntityCoordinates coordinates) + { + if (_entManager.TryGetComponent(MapUid, out var physics)) + { + _offset = new Vector2(coordinates.X, coordinates.Y) - physics.LocalCenter; + } + _recenter.Disabled = false; + } + protected override void KeyBindDown(GUIBoundKeyEventArgs args) { base.KeyBindDown(args); diff --git a/Content.Client/Stylesheets/StyleNano.cs b/Content.Client/Stylesheets/StyleNano.cs index e0f0a45224..351b6cf548 100644 --- a/Content.Client/Stylesheets/StyleNano.cs +++ b/Content.Client/Stylesheets/StyleNano.cs @@ -104,6 +104,11 @@ namespace Content.Client.Stylesheets public static readonly Color ButtonColorGoodDefault = Color.FromHex("#3E6C45"); public static readonly Color ButtonColorGoodHovered = Color.FromHex("#31843E"); + //NavMap + public static readonly Color PointRed = Color.FromHex("#B02E26"); + public static readonly Color PointGreen = Color.FromHex("#38b026"); + public static readonly Color PointMagenta = Color.FromHex("#FF00FF"); + // Context menu button colors public static readonly Color ButtonColorContext = Color.FromHex("#1119"); public static readonly Color ButtonColorContextHover = Color.DarkSlateGray; diff --git a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs index 5f8b5954b2..597b647646 100644 --- a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs +++ b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs @@ -321,7 +321,7 @@ namespace Content.Server.Medical.SuitSensors totalDamage = damageable.TotalDamage.Int(); // finally, form suit sensor status - var status = new SuitSensorStatus(userName, userJob); + var status = new SuitSensorStatus(uid, userName, userJob); switch (sensor.Mode) { case SuitSensorMode.SensorBinary: @@ -371,6 +371,7 @@ namespace Content.Server.Medical.SuitSensors [SuitSensorConstants.NET_NAME] = status.Name, [SuitSensorConstants.NET_JOB] = status.Job, [SuitSensorConstants.NET_IS_ALIVE] = status.IsAlive, + [SuitSensorConstants.NET_SUIT_SENSOR_UID] = status.SuitSensorUid, }; if (status.TotalDamage != null) @@ -397,12 +398,13 @@ namespace Content.Server.Medical.SuitSensors if (!payload.TryGetValue(SuitSensorConstants.NET_NAME, out string? name)) return null; if (!payload.TryGetValue(SuitSensorConstants.NET_JOB, out string? job)) return null; if (!payload.TryGetValue(SuitSensorConstants.NET_IS_ALIVE, out bool? isAlive)) return null; + if (!payload.TryGetValue(SuitSensorConstants.NET_SUIT_SENSOR_UID, out EntityUid suitSensorUid)) return null; // try get total damage and cords (optionals) payload.TryGetValue(SuitSensorConstants.NET_TOTAL_DAMAGE, out int? totalDamage); payload.TryGetValue(SuitSensorConstants.NET_COORDINATES, out EntityCoordinates? cords); - var status = new SuitSensorStatus(name, job) + var status = new SuitSensorStatus(suitSensorUid, name, job) { IsAlive = isAlive.Value, TotalDamage = totalDamage, diff --git a/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs b/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs index 5f59836182..8d2d7e230a 100644 --- a/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs +++ b/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs @@ -1,4 +1,4 @@ -using Robust.Shared.Map; +using Robust.Shared.Map; using Robust.Shared.Serialization; namespace Content.Shared.Medical.SuitSensor @@ -6,13 +6,15 @@ namespace Content.Shared.Medical.SuitSensor [Serializable, NetSerializable] public sealed class SuitSensorStatus { - public SuitSensorStatus(string name, string job) + public SuitSensorStatus(EntityUid suitSensorUid, string name, string job) { + SuitSensorUid = suitSensorUid; Name = name; Job = job; } public TimeSpan Timestamp; + public EntityUid SuitSensorUid; public string Name; public string Job; public bool IsAlive; @@ -51,6 +53,7 @@ namespace Content.Shared.Medical.SuitSensor public const string NET_IS_ALIVE = "alive"; public const string NET_TOTAL_DAMAGE = "vitals"; public const string NET_COORDINATES = "coords"; + public const string NET_SUIT_SENSOR_UID = "uid"; ///Used by the CrewMonitoringServerSystem to send the status of all connected suit sensors to each crew monitor public const string NET_STATUS_COLLECTION = "suit-status-collection"; diff --git a/Resources/Locale/en-US/medical/components/crew-monitoring-component.ftl b/Resources/Locale/en-US/medical/components/crew-monitoring-component.ftl index 0914415619..e089b09234 100644 --- a/Resources/Locale/en-US/medical/components/crew-monitoring-component.ftl +++ b/Resources/Locale/en-US/medical/components/crew-monitoring-component.ftl @@ -10,3 +10,5 @@ crew-monitoring-user-interface-location = Location crew-monitoring-user-interface-alive = Alive crew-monitoring-user-interface-dead = Dead crew-monitoring-user-interface-no-info = N/A + +crew-monitoring-user-interface-no-server = Server not found