]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add copy threshold button to air alarms (#34346)
authorSouthbridge <7013162+southbridge-fur@users.noreply.github.com>
Fri, 10 Jan 2025 06:55:05 +0000 (01:55 -0500)
committerGitHub <noreply@github.com>
Fri, 10 Jan 2025 06:55:05 +0000 (22:55 -0800)
Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs
Content.Client/Atmos/Monitor/UI/Widgets/PumpControl.xaml.cs
Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml.cs
Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml
Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml.cs
Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs
Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs
Resources/Locale/en-US/atmos/air-alarm-ui.ftl

index 651649838653760cf2c78248e4eb6a9bfee60751..f0201dc81ba5206ea26b056437f62aee85f31780 100644 (file)
@@ -130,8 +130,8 @@ public sealed partial class AirAlarmWindow : FancyWindow
                 if (!_pumps.TryGetValue(addr, out var pumpControl))
                 {
                     var control= new PumpControl(pump, addr);
-                    control.PumpDataChanged += AtmosDeviceDataChanged!.Invoke;
-                                       control.PumpDataCopied += AtmosDeviceDataCopied!.Invoke;
+                    control.PumpDataChanged += AtmosDeviceDataChanged;
+                    control.PumpDataCopied += AtmosDeviceDataCopied;
                     _pumps.Add(addr, control);
                     CVentContainer.AddChild(control);
                 }
@@ -145,8 +145,8 @@ public sealed partial class AirAlarmWindow : FancyWindow
                 if (!_scrubbers.TryGetValue(addr, out var scrubberControl))
                 {
                     var control = new ScrubberControl(scrubber, addr);
-                    control.ScrubberDataChanged += AtmosDeviceDataChanged!.Invoke;
-                                       control.ScrubberDataCopied += AtmosDeviceDataCopied!.Invoke;
+                    control.ScrubberDataChanged += AtmosDeviceDataChanged;
+                                       control.ScrubberDataCopied += AtmosDeviceDataCopied;
                     _scrubbers.Add(addr, control);
                     CScrubberContainer.AddChild(control);
                 }
@@ -161,6 +161,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
                 {
                     var control = new SensorInfo(sensor, addr);
                     control.OnThresholdUpdate += AtmosAlarmThresholdChanged;
+                    control.SensorDataCopied += AtmosDeviceDataCopied;
                     _sensors.Add(addr, control);
                     CSensorContainer.AddChild(control);
                 }
index 2cd51d6fc7f5e8c0c4dc3f5506644da6e8a440bc..8502cd2712b39bba9135f745660d0052ad8dec32 100644 (file)
@@ -83,10 +83,10 @@ public sealed partial class PumpControl : BoxContainer
             PumpDataChanged?.Invoke(_address, _data);
         };
 
-               _copySettings.OnPressed += _ =>
-               {
-                       PumpDataCopied?.Invoke(_data);
-               };
+        _copySettings.OnPressed += _ =>
+        {
+            PumpDataCopied?.Invoke(_data);
+        };
     }
 
     public void ChangeData(GasVentPumpData data)
index c16ff688c93eb6406363a3e2a1af4045674043b9..d03ac77ab310fb0484406d205f73fd914088f634 100644 (file)
@@ -72,10 +72,10 @@ public sealed partial class ScrubberControl : BoxContainer
             ScrubberDataChanged?.Invoke(_address, _data);
         };
 
-               _copySettings.OnPressed += _ =>
-               {
-                       ScrubberDataCopied?.Invoke(_data);
-               };
+        _copySettings.OnPressed += _ =>
+        {
+            ScrubberDataCopied?.Invoke(_data);
+        };
 
         foreach (var value in Enum.GetValues<Gas>())
         {
index 005e6807b37df057f41c98f75c77072127c414eb..c50dadc9c7d182a761d277d5a4ecf5148bfcd175 100644 (file)
@@ -3,6 +3,9 @@
         <CollapsibleHeading Name="SensorAddress" />
         <CollapsibleBody Margin="20 2 2 2">
             <BoxContainer Orientation="Vertical" HorizontalExpand="True">
+                <BoxContainer Orientation="Horizontal" Margin ="0 0 0 2">
+                    <Button Name="CCopySettings" Text="{Loc 'air-alarm-ui-thresholds-copy'}" ToolTip="{Loc 'air-alarm-ui-thresholds-copy-tooltip'}" />
+                </BoxContainer>
                 <BoxContainer Orientation="Vertical" Margin="0 0 2 0" HorizontalExpand="True">
                     <RichTextLabel Name="AlarmStateLabel" />
                     <RichTextLabel Name="PressureLabel" />
index 9e60b6cea62434422978268f8672954ee210a060..f906bd3930060c2910653e773e5b971ddfc0c470 100644 (file)
@@ -12,12 +12,14 @@ namespace Content.Client.Atmos.Monitor.UI.Widgets;
 public sealed partial class SensorInfo : BoxContainer
 {
     public Action<string, AtmosMonitorThresholdType, AtmosAlarmThreshold, Gas?>? OnThresholdUpdate;
+    public event Action<AtmosSensorData>? SensorDataCopied;
     private string _address;
 
     private ThresholdControl _pressureThreshold;
     private ThresholdControl _temperatureThreshold;
     private Dictionary<Gas, ThresholdControl> _gasThresholds = new();
     private Dictionary<Gas, RichTextLabel> _gasLabels = new();
+    private Button _copySettings => CCopySettings;
 
     public SensorInfo(AtmosSensorData data, string address)
     {
@@ -56,7 +58,7 @@ public sealed partial class SensorInfo : BoxContainer
             gasThresholdControl.Margin = new Thickness(20, 2, 2, 2);
             gasThresholdControl.ThresholdDataChanged += (type, alarmThreshold, arg3) =>
             {
-                OnThresholdUpdate!(_address, type, alarmThreshold, arg3);
+                OnThresholdUpdate?.Invoke(_address, type, alarmThreshold, arg3);
             };
 
             _gasThresholds.Add(gas, gasThresholdControl);
@@ -72,12 +74,17 @@ public sealed partial class SensorInfo : BoxContainer
 
         _pressureThreshold.ThresholdDataChanged += (type, threshold, arg3) =>
         {
-            OnThresholdUpdate!(_address, type, threshold, arg3);
+            OnThresholdUpdate?.Invoke(_address, type, threshold, arg3);
         };
 
         _temperatureThreshold.ThresholdDataChanged += (type, threshold, arg3) =>
         {
-            OnThresholdUpdate!(_address, type, threshold, arg3);
+            OnThresholdUpdate?.Invoke(_address, type, threshold, arg3);
+        };
+
+        _copySettings.OnPressed += _ =>
+        {
+            SensorDataCopied?.Invoke(data);
         };
     }
 
index ca01ef13072fa59afc36d7b36a8a3465e2495535..63dbb19a57141a18d879ff5e2456a0a4029d425b 100644 (file)
@@ -131,6 +131,19 @@ public sealed class AirAlarmSystem : EntitySystem
         SyncDevice(uid, address);
     }
 
+    private void SetAllThresholds(EntityUid uid, string address, AtmosSensorData data)
+    {
+        var payload = new NetworkPayload
+        {
+            [DeviceNetworkConstants.Command] = AtmosMonitorSystem.AtmosMonitorSetAllThresholdsCmd,
+            [AtmosMonitorSystem.AtmosMonitorAllThresholdData] = data
+        };
+
+        _deviceNet.QueuePacket(uid, address, payload);
+
+        SyncDevice(uid, address);
+    }
+
     /// <summary>
     ///     Sync this air alarm's mode with the rest of the network.
     /// </summary>
@@ -341,6 +354,13 @@ public sealed class AirAlarmSystem : EntitySystem
                     SetData(uid, addr, args.Data);
                 }
                 break;
+
+            case AtmosSensorData sensorData:
+                foreach (string addr in component.SensorData.Keys)
+                {
+                    SetAllThresholds(uid, addr, sensorData);
+                }
+                break;
         }
     }
 
index 875d8ad1cda4531dc90c5bb759361c256eb38f7c..3805c012b7f4d099aebd7e53044168d0b630dfb6 100644 (file)
@@ -33,10 +33,11 @@ public sealed class AtmosMonitorSystem : EntitySystem
 
     // Commands
     public const string AtmosMonitorSetThresholdCmd = "atmos_monitor_set_threshold";
+    public const string AtmosMonitorSetAllThresholdsCmd = "atmos_monitor_set_all_thresholds";
 
     // Packet data
     public const string AtmosMonitorThresholdData = "atmos_monitor_threshold_data";
-
+    public const string AtmosMonitorAllThresholdData = "atmos_monitor_all_threshold_data";
     public const string AtmosMonitorThresholdDataType = "atmos_monitor_threshold_type";
 
     public const string AtmosMonitorThresholdGasType = "atmos_monitor_threshold_gas";
@@ -138,7 +139,12 @@ public sealed class AtmosMonitorSystem : EntitySystem
                     args.Data.TryGetValue(AtmosMonitorThresholdGasType, out Gas? gas);
                     SetThreshold(uid, thresholdType.Value, thresholdData, gas);
                 }
-
+                break;
+            case AtmosMonitorSetAllThresholdsCmd:
+                if (args.Data.TryGetValue(AtmosMonitorAllThresholdData, out AtmosSensorData? allThresholdData))
+                {
+                    SetAllThresholds(uid, allThresholdData);
+                }
                 break;
             case AtmosDeviceNetworkSystem.SyncData:
                 var payload = new NetworkPayload();
@@ -403,4 +409,20 @@ public sealed class AtmosMonitorSystem : EntitySystem
         }
 
     }
+
+    /// <summary>
+    ///     Sets all of a monitor's thresholds at once according to the incoming
+    ///     AtmosSensorData object's thresholds.
+    /// </summary>
+    /// <param name="uid">The entity's uid</param>
+    /// <param name="allThresholdData">An AtmosSensorData object from which the thresholds will be loaded.</param>
+    public void SetAllThresholds(EntityUid uid, AtmosSensorData allThresholdData)
+    {
+        SetThreshold(uid, AtmosMonitorThresholdType.Temperature, allThresholdData.TemperatureThreshold);
+        SetThreshold(uid, AtmosMonitorThresholdType.Pressure, allThresholdData.PressureThreshold);
+        foreach (var gas in Enum.GetValues<Gas>())
+        {
+            SetThreshold(uid, AtmosMonitorThresholdType.Gas, allThresholdData.GasThresholds[gas], gas);
+        }
+    }
 }
index 626f30bacb924fde17805226f46e510c03364085..15043e49847b4219e5dfb35fc99cc4cd94ab366a 100644 (file)
@@ -69,3 +69,5 @@ air-alarm-ui-thresholds-upper-bound = Danger above
 air-alarm-ui-thresholds-lower-bound = Danger below
 air-alarm-ui-thresholds-upper-warning-bound = Warning above
 air-alarm-ui-thresholds-lower-warning-bound = Warning below
+air-alarm-ui-thresholds-copy = Copy thresholds to all devices
+air-alarm-ui-thresholds-copy-tooltip = Copies the sensor thresholds of this device to all devices in this air alarm tab.