]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Day 0 bug fix for atmos alerts computer (#31858)
authorchromiumboy <50505512+chromiumboy@users.noreply.github.com>
Thu, 5 Sep 2024 05:05:03 +0000 (00:05 -0500)
committerGitHub <noreply@github.com>
Thu, 5 Sep 2024 05:05:03 +0000 (01:05 -0400)
Initial commit

Content.Client/Atmos/Consoles/AtmosAlarmEntryContainer.xaml.cs
Content.Client/Atmos/Consoles/AtmosAlertsComputerWindow.xaml.cs

index 4900eabc87df4b8dbeafe46dbfd945a4e2ece0e0..79bb66560e3c33ea9e7f8d0233ca87716c068bbd 100644 (file)
@@ -20,7 +20,8 @@ public sealed partial class AtmosAlarmEntryContainer : BoxContainer
     public NetEntity NetEntity;
     public EntityCoordinates? Coordinates;
 
-    private IResourceCache _cache;
+    private readonly IEntityManager _entManager;
+    private readonly IResourceCache _cache;
 
     private Dictionary<AtmosAlarmType, string> _alarmStrings = new Dictionary<AtmosAlarmType, string>()
     {
@@ -47,6 +48,7 @@ public sealed partial class AtmosAlarmEntryContainer : BoxContainer
     {
         RobustXamlLoader.Load(this);
 
+        _entManager = IoCManager.Resolve<IEntityManager>();
         _cache = IoCManager.Resolve<IResourceCache>();
 
         NetEntity = uid;
@@ -75,6 +77,9 @@ public sealed partial class AtmosAlarmEntryContainer : BoxContainer
 
     public void UpdateEntry(AtmosAlertsComputerEntry entry, bool isFocus, AtmosAlertsFocusDeviceData? focusData = null)
     {
+        NetEntity = entry.NetEntity;
+        Coordinates = _entManager.GetCoordinates(entry.Coordinates);
+
         // Load fonts
         var normalFont = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSansDisplay/NotoSansDisplay-Regular.ttf"), 11);
 
@@ -104,18 +109,18 @@ public sealed partial class AtmosAlarmEntryContainer : BoxContainer
             if (focusData != null)
             {
                 // Update temperature
-                var tempK = (FixedPoint2) focusData.Value.TemperatureData.Item1;
-                var tempC = (FixedPoint2) TemperatureHelpers.KelvinToCelsius(tempK.Float());
+                var tempK = (FixedPoint2)focusData.Value.TemperatureData.Item1;
+                var tempC = (FixedPoint2)TemperatureHelpers.KelvinToCelsius(tempK.Float());
 
                 TemperatureLabel.Text = Loc.GetString("atmos-alerts-window-temperature-value", ("valueInC", tempC), ("valueInK", tempK));
                 TemperatureLabel.FontColorOverride = GetAlarmStateColor(focusData.Value.TemperatureData.Item2);
 
                 // Update pressure
-                PressureLabel.Text = Loc.GetString("atmos-alerts-window-pressure-value", ("value", (FixedPoint2) focusData.Value.PressureData.Item1));
+                PressureLabel.Text = Loc.GetString("atmos-alerts-window-pressure-value", ("value", (FixedPoint2)focusData.Value.PressureData.Item1));
                 PressureLabel.FontColorOverride = GetAlarmStateColor(focusData.Value.PressureData.Item2);
 
                 // Update oxygenation
-                var oxygenPercent = (FixedPoint2) 0f;
+                var oxygenPercent = (FixedPoint2)0f;
                 var oxygenAlert = AtmosAlarmType.Invalid;
 
                 if (focusData.Value.GasData.TryGetValue(Gas.Oxygen, out var oxygenData))
@@ -155,7 +160,7 @@ public sealed partial class AtmosAlarmEntryContainer : BoxContainer
                     // Add an entry for each gas
                     foreach ((var gas, (var mol, var percent, var alert)) in gasData)
                     {
-                        var gasPercent = (FixedPoint2) 0f;
+                        var gasPercent = (FixedPoint2)0f;
                         gasPercent = percent * 100f;
 
                         if (!_gasShorthands.TryGetValue(gas, out var gasShorthand))
index 3fee5b5c4b7543c460c9ca8dd47acebccb9fbfad..f0b7ffbe1199097c837ab5f2f78d47fbe5b41815 100644 (file)
@@ -4,6 +4,7 @@ using Content.Client.Stylesheets;
 using Content.Client.UserInterface.Controls;
 using Content.Shared.Atmos.Components;
 using Content.Shared.Atmos.Monitor;
+using Content.Shared.Pinpointer;
 using Robust.Client.AutoGenerated;
 using Robust.Client.GameObjects;
 using Robust.Client.UserInterface;
@@ -28,6 +29,8 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
 
     private AtmosAlertsComputerEntry[]? _airAlarms = null;
     private AtmosAlertsComputerEntry[]? _fireAlarms = null;
+    private IEnumerable<AtmosAlertsComputerEntry>? _allAlarms = null;
+
     private IEnumerable<AtmosAlertsComputerEntry>? _activeAlarms = null;
     private Dictionary<NetEntity, float> _deviceSilencingProgress = new();
 
@@ -65,7 +68,7 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
                 stationName = stationMetaData.EntityName;
 
             var msg = new FormattedMessage();
-            msg.AddMarkup(Loc.GetString("atmos-alerts-window-station-name", ("stationName", stationName)));
+            msg.TryAddMarkup(Loc.GetString("atmos-alerts-window-station-name", ("stationName", stationName)), out _);
 
             StationName.SetMessage(msg);
         }
@@ -110,7 +113,7 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
 
         foreach (var device in console.AtmosDevices)
         {
-            var alarmState = GetAlarmState(device.NetEntity, device.Group);
+            var alarmState = GetAlarmState(device.NetEntity);
 
             if (toggledAlarmState != alarmState)
                 continue;
@@ -162,11 +165,11 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
         // Retain alarm data for use inbetween updates
         _airAlarms = airAlarms;
         _fireAlarms = fireAlarms;
+        _allAlarms = airAlarms.Concat(fireAlarms);
 
-        var allAlarms = airAlarms.Concat(fireAlarms);
         var silenced = console.SilencedDevices;
 
-        _activeAlarms = allAlarms.Where(x => x.AlarmState > AtmosAlarmType.Normal &&
+        _activeAlarms = _allAlarms.Where(x => x.AlarmState > AtmosAlarmType.Normal &&
             (!silenced.Contains(x.NetEntity) || _deviceSilencingProgress.ContainsKey(x.NetEntity)));
 
         // Reset nav map data
@@ -179,7 +182,7 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
             if (!NavMap.Visible)
                 continue;
 
-            var alarmState = GetAlarmState(device.NetEntity, device.Group);
+            var alarmState = GetAlarmState(device.NetEntity);
 
             if (_trackedEntity != device.NetEntity)
             {
@@ -305,9 +308,7 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
             // On click
             newEntryContainer.FocusButton.OnButtonUp += args =>
             {
-                var prevTrackedEntity = _trackedEntity;
-
-                if (_trackedEntity == entry.NetEntity)
+                if (_trackedEntity == newEntryContainer.NetEntity)
                 {
                     _trackedEntity = null;
                 }
@@ -315,20 +316,22 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
                 else
                 {
                     _trackedEntity = newEntryContainer.NetEntity;
-                    NavMap.CenterToCoordinates(_entManager.GetCoordinates(entry.Coordinates));
+
+                    if (newEntryContainer.Coordinates != null)
+                        NavMap.CenterToCoordinates(newEntryContainer.Coordinates.Value);
                 }
 
                 // Send message to console that the focus has changed
                 SendFocusChangeMessageAction?.Invoke(_trackedEntity);
 
                 // Update affected UI elements across all tables
-                UpdateConsoleTable(console, AlertsTable, _trackedEntity, prevTrackedEntity);
-                UpdateConsoleTable(console, AirAlarmsTable, _trackedEntity, prevTrackedEntity);
-                UpdateConsoleTable(console, FireAlarmsTable, _trackedEntity, prevTrackedEntity);
+                UpdateConsoleTable(console, AlertsTable, _trackedEntity);
+                UpdateConsoleTable(console, AirAlarmsTable, _trackedEntity);
+                UpdateConsoleTable(console, FireAlarmsTable, _trackedEntity);
             };
 
             // On toggling the silence check box
-            newEntryContainer.SilenceCheckBox.OnToggled += _ => OnSilenceAlertsToggled(entry.NetEntity, newEntryContainer.SilenceCheckBox.Pressed);
+            newEntryContainer.SilenceCheckBox.OnToggled += _ => OnSilenceAlertsToggled(newEntryContainer.NetEntity, newEntryContainer.SilenceCheckBox.Pressed);
 
             // Add the entry to the current table
             table.AddChild(newEntryContainer);
@@ -345,48 +348,33 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
             return;
         }
 
-        var entryContainer = tableChild as AtmosAlarmEntryContainer;
-        var silenced = console.SilencedDevices;
-
-        if (entryContainer == null)
-            return;
+        var entryContainer = (AtmosAlarmEntryContainer)tableChild;
 
         entryContainer.UpdateEntry(entry, entry.NetEntity == _trackedEntity, focusData);
-        entryContainer.SilenceCheckBox.Pressed = (silenced.Contains(entry.NetEntity) || _deviceSilencingProgress.ContainsKey(entry.NetEntity));
+
+        if (_trackedEntity != entry.NetEntity)
+        {
+            var silenced = console.SilencedDevices;
+            entryContainer.SilenceCheckBox.Pressed = (silenced.Contains(entry.NetEntity) || _deviceSilencingProgress.ContainsKey(entry.NetEntity));
+        }
+
         entryContainer.SilenceAlarmProgressBar.Visible = (table == AlertsTable && _deviceSilencingProgress.ContainsKey(entry.NetEntity));
     }
 
-    private void UpdateConsoleTable(AtmosAlertsComputerComponent console, Control table, NetEntity? currTrackedEntity, NetEntity? prevTrackedEntity)
+    private void UpdateConsoleTable(AtmosAlertsComputerComponent console, Control table, NetEntity? currTrackedEntity)
     {
-        foreach (var child in table.Children)
+        foreach (var tableChild in table.Children)
         {
-            if (child is not AtmosAlarmEntryContainer)
+            if (tableChild is not AtmosAlarmEntryContainer)
                 continue;
 
-            var castAlert = (AtmosAlarmEntryContainer) child;
-
-            if (castAlert.NetEntity == prevTrackedEntity)
-                castAlert.RemoveAsFocus();
+            var entryContainer = (AtmosAlarmEntryContainer)tableChild;
 
-            else if (castAlert.NetEntity == currTrackedEntity)
-                castAlert.SetAsFocus();
+            if (entryContainer.NetEntity != currTrackedEntity)
+                entryContainer.RemoveAsFocus();
 
-            if (castAlert?.Coordinates == null)
-                continue;
-
-            var device = console.AtmosDevices.FirstOrNull(x => x.NetEntity == castAlert.NetEntity);
-
-            if (device == null)
-                continue;
-
-            var alarmState = GetAlarmState(device.Value.NetEntity, device.Value.Group);
-
-            if (currTrackedEntity != device.Value.NetEntity &&
-                !ShowInactiveAlarms.Pressed &&
-                alarmState <= AtmosAlarmType.Normal)
-                continue;
-
-            AddTrackedEntityToNavMap(device.Value, alarmState);
+            else if (entryContainer.NetEntity == currTrackedEntity)
+                entryContainer.SetAsFocus();
         }
     }
 
@@ -434,8 +422,13 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
             var t = remainingTime - args.DeltaSeconds;
 
             if (t <= 0)
+            {
                 _deviceSilencingProgress.Remove(device);
 
+                if (device == _trackedEntity)
+                    _trackedEntity = null;
+            }
+
             else
                 _deviceSilencingProgress[device] = t;
         }
@@ -512,7 +505,7 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
             if (control == null || control is not AtmosAlarmEntryContainer)
                 continue;
 
-            if (((AtmosAlarmEntryContainer) control).NetEntity == _trackedEntity)
+            if (((AtmosAlarmEntryContainer)control).NetEntity == _trackedEntity)
                 return true;
 
             nextScrollPosition += control.Height;
@@ -524,10 +517,9 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow
         return false;
     }
 
-    private AtmosAlarmType GetAlarmState(NetEntity netEntity, AtmosAlertsComputerGroup group)
+    private AtmosAlarmType GetAlarmState(NetEntity netEntity)
     {
-        var alarms = (group == AtmosAlertsComputerGroup.AirAlarm) ? _airAlarms : _fireAlarms;
-        var alarmState = alarms?.FirstOrNull(x => x.NetEntity == netEntity)?.AlarmState;
+        var alarmState = _allAlarms?.FirstOrNull(x => x.NetEntity == netEntity)?.AlarmState;
 
         if (alarmState == null)
             return AtmosAlarmType.Invalid;