]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Cleanup some Client atmos systems (#33634)
authorMilenVolf <63782763+MilenVolf@users.noreply.github.com>
Sat, 30 Nov 2024 01:33:29 +0000 (04:33 +0300)
committerGitHub <noreply@github.com>
Sat, 30 Nov 2024 01:33:29 +0000 (02:33 +0100)
* Cleanup `ScrubberControl.xaml.cs`

* Minor cleanups

* Another pile of minor cleanups

* Apply requested changes

* Rename "which" into "bound". Add whitespace after "if"

15 files changed:
Content.Client/Atmos/Components/PipeColorVisualsComponent.cs
Content.Client/Atmos/Consoles/AtmosAlarmEntryContainer.xaml
Content.Client/Atmos/Consoles/AtmosAlarmEntryContainer.xaml.cs
Content.Client/Atmos/Consoles/AtmosAlertsComputerBoundUserInterface.cs
Content.Client/Atmos/Consoles/AtmosAlertsComputerWindow.xaml
Content.Client/Atmos/EntitySystems/AtmosPipeAppearanceSystem.cs
Content.Client/Atmos/Monitor/AtmosAlarmableVisualsSystem.cs
Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs
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.cs
Content.Client/Atmos/Monitor/UI/Widgets/ThresholdBoundControl.xaml.cs
Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs
Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs

index 355b10cb4a4d83f7d43e112db8db81a14c534a34..9b24b1adc254d811e2bf67a8010ad0e03116f752 100644 (file)
@@ -1,8 +1,4 @@
-using Robust.Shared.GameObjects;
-
 namespace Content.Client.Atmos.Components;
 
 [RegisterComponent]
-public sealed partial class PipeColorVisualsComponent : Component
-{
-}
+public sealed partial class PipeColorVisualsComponent : Component;
index 6bdfb3989f982cc94b10352a52518d5e2ad1bb57..3dbe14e6b6d159476c760711340621b4ebdac539 100644 (file)
@@ -1,6 +1,5 @@
 <BoxContainer xmlns="https://spacestation14.io"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-         xmlns:s="clr-namespace:Content.Client.Stylesheets"
          xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
          xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
          Orientation="Vertical" HorizontalExpand ="True" Margin="0 0 0 3">
@@ -62,7 +61,7 @@
                     </PanelContainer>
                 </BoxContainer>
 
-                <!-- If the alarm is inactive, this is label is diplayed instead -->
+                <!-- If the alarm is inactive, this is label is displayed instead -->
                 <Label Name="NoDataLabel" Text="{Loc 'atmos-alerts-window-no-data-available'}" HorizontalAlignment="Center" Margin="0 15" FontColorOverride="#a9a9a9" ReservesSpace="False" Visible="False"></Label>
 
                 <!-- Silencing progress bar -->
index 79bb66560e3c33ea9e7f8d0233ca87716c068bbd..e533ef2dce0a2aec13aae9bc9741ee93ed692383 100644 (file)
@@ -136,8 +136,9 @@ public sealed partial class AtmosAlarmEntryContainer : BoxContainer
                 GasGridContainer.RemoveAllChildren();
 
                 var gasData = focusData.Value.GasData.Where(g => g.Key != Gas.Oxygen);
+                var keyValuePairs = gasData.ToList();
 
-                if (gasData.Count() == 0)
+                if (keyValuePairs.Count == 0)
                 {
                     // No other gases
                     var gasLabel = new Label()
@@ -158,13 +159,11 @@ public sealed partial class AtmosAlarmEntryContainer : BoxContainer
                 else
                 {
                     // Add an entry for each gas
-                    foreach ((var gas, (var mol, var percent, var alert)) in gasData)
+                    foreach ((var gas, (var mol, var percent, var alert)) in keyValuePairs)
                     {
-                        var gasPercent = (FixedPoint2)0f;
-                        gasPercent = percent * 100f;
+                        FixedPoint2 gasPercent = percent * 100f;
 
-                        if (!_gasShorthands.TryGetValue(gas, out var gasShorthand))
-                            gasShorthand = "X";
+                        var gasShorthand = _gasShorthands.GetValueOrDefault(gas, "X");
 
                         var gasLabel = new Label()
                         {
index 08cae979b9b83a834f789ba20786536f893657b9..6f0e7f80da14952bc9cdcb654cd6b1de4933d987 100644 (file)
@@ -14,8 +14,6 @@ public sealed class AtmosAlertsComputerBoundUserInterface : BoundUserInterface
         _menu = new AtmosAlertsComputerWindow(this, Owner);
         _menu.OpenCentered();
         _menu.OnClose += Close;
-
-        EntMan.TryGetComponent<TransformComponent>(Owner, out var xform);
     }
 
     protected override void UpdateState(BoundUserInterfaceState state)
@@ -24,9 +22,6 @@ public sealed class AtmosAlertsComputerBoundUserInterface : BoundUserInterface
 
         var castState = (AtmosAlertsComputerBoundInterfaceState) state;
 
-        if (castState == null)
-            return;
-
         EntMan.TryGetComponent<TransformComponent>(Owner, out var xform);
         _menu?.UpdateUI(xform?.Coordinates, castState.AirAlarms, castState.FireAlarms, castState.FocusData);
     }
index 8824a776ee6825aab1a7ea07e085e31af33365f4..e5ede1b92e3960de747eaad01a999118633c5b2d 100644 (file)
@@ -1,7 +1,6 @@
 <controls:FancyWindow xmlns="https://spacestation14.io"
                xmlns:ui="clr-namespace:Content.Client.Pinpointer.UI"
                xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
-               xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
                Title="{Loc 'atmos-alerts-window-title'}"
                Resizable="False"
                SetSize="1120 750"
index adcbfac7f353bf9eaa22437fce8ab02af45dd3f3..5c323d7dc1861eafe6fb965bc50569b4c4b8725f 100644 (file)
@@ -4,8 +4,6 @@ using Content.Shared.Atmos.Components;
 using Content.Shared.Atmos.Piping;
 using JetBrains.Annotations;
 using Robust.Client.GameObjects;
-using Robust.Client.ResourceManagement;
-using Robust.Shared.Serialization.TypeSerializers.Implementations;
 
 namespace Content.Client.Atmos.EntitySystems;
 
@@ -19,7 +17,7 @@ public sealed class AtmosPipeAppearanceSystem : EntitySystem
         base.Initialize();
 
         SubscribeLocalEvent<PipeAppearanceComponent, ComponentInit>(OnInit);
-        SubscribeLocalEvent<PipeAppearanceComponent, AppearanceChangeEvent>(OnAppearanceChanged, after: new[] { typeof(SubFloorHideSystem) });
+        SubscribeLocalEvent<PipeAppearanceComponent, AppearanceChangeEvent>(OnAppearanceChanged, after: [typeof(SubFloorHideSystem)]);
     }
 
     private void OnInit(EntityUid uid, PipeAppearanceComponent component, ComponentInit args)
@@ -84,7 +82,8 @@ public sealed class AtmosPipeAppearanceSystem : EntitySystem
 
             layer.Visible &= visible;
 
-            if (!visible) continue;
+            if (!visible)
+                continue;
 
             layer.Color = color;
         }
index 019f25f376b77f00c3c57bfa1eb9340a53924f5d..18ca22347527be25f521b592e459706000e93618 100644 (file)
@@ -1,12 +1,7 @@
-using System.Collections.Generic;
 using Content.Shared.Atmos.Monitor;
 using Content.Shared.Power;
 using Robust.Client.GameObjects;
 using Robust.Client.Graphics;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Maths;
-using Robust.Shared.Serialization.Manager.Attributes;
 
 namespace Content.Client.Atmos.Monitor;
 
@@ -27,7 +22,7 @@ public sealed class AtmosAlarmableVisualsSystem : VisualizerSystem<AtmosAlarmabl
         {
             foreach (var visLayer in component.HideOnDepowered)
             {
-                if (args.Sprite.LayerMapTryGet(visLayer, out int powerVisibilityLayer))
+                if (args.Sprite.LayerMapTryGet(visLayer, out var powerVisibilityLayer))
                     args.Sprite.LayerSetVisible(powerVisibilityLayer, powered);
             }
         }
@@ -36,7 +31,7 @@ public sealed class AtmosAlarmableVisualsSystem : VisualizerSystem<AtmosAlarmabl
         {
             foreach (var (setLayer, powerState) in component.SetOnDepowered)
             {
-                if (args.Sprite.LayerMapTryGet(setLayer, out int setStateLayer))
+                if (args.Sprite.LayerMapTryGet(setLayer, out var setStateLayer))
                     args.Sprite.LayerSetState(setStateLayer, new RSI.StateId(powerState));
             }
         }
index d9e94e373b4a8dc7150491c27f85528197279782..650f96eec97a9085688a057ff9245c2fb7431a3f 100644 (file)
@@ -1,11 +1,7 @@
 using Content.Shared.Atmos;
 using Content.Shared.Atmos.Monitor;
 using Content.Shared.Atmos.Monitor.Components;
-using Robust.Client.GameObjects;
 using Robust.Client.UserInterface;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Log;
 
 namespace Content.Client.Atmos.Monitor.UI;
 
@@ -78,6 +74,7 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
     {
         base.Dispose(disposing);
 
-        if (disposing) _window?.Dispose();
+        if (disposing)
+            _window?.Dispose();
     }
 }
index e1425ac491bee77b253f912b0639841530388b13..651649838653760cf2c78248e4eb6a9bfee60751 100644 (file)
@@ -8,7 +8,6 @@ using Content.Shared.Atmos.Monitor.Components;
 using Content.Shared.Atmos.Piping.Unary.Components;
 using Content.Shared.Temperature;
 using Robust.Client.AutoGenerated;
-using Robust.Client.GameObjects;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
 
@@ -59,7 +58,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
                 AirAlarmMode.Fill => "air-alarm-ui-mode-fill",
                 AirAlarmMode.Panic => "air-alarm-ui-mode-panic",
                 AirAlarmMode.None => "air-alarm-ui-mode-none",
-                _ => "error"
+                _ => "error",
             };
             _modes.AddItem(Loc.GetString(text));
         }
@@ -70,7 +69,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
             AirAlarmModeChanged!.Invoke((AirAlarmMode) args.Id);
         };
 
-        _autoMode.OnToggled += args =>
+        _autoMode.OnToggled += _ =>
         {
             AutoModeChanged!.Invoke(_autoMode.Pressed);
         };
@@ -176,22 +175,18 @@ public sealed partial class AirAlarmWindow : FancyWindow
 
     public static Color ColorForThreshold(float amount, AtmosAlarmThreshold threshold)
     {
-        threshold.CheckThreshold(amount, out AtmosAlarmType curAlarm);
+        threshold.CheckThreshold(amount, out var curAlarm);
         return ColorForAlarm(curAlarm);
     }
 
     public static Color ColorForAlarm(AtmosAlarmType curAlarm)
     {
-        if(curAlarm == AtmosAlarmType.Danger)
+        return curAlarm switch
         {
-            return StyleNano.DangerousRedFore;
-        }
-        else if(curAlarm == AtmosAlarmType.Warning)
-        {
-            return StyleNano.ConcerningOrangeFore;
-        }
-
-        return StyleNano.GoodGreenFore;
+            AtmosAlarmType.Danger => StyleNano.DangerousRedFore,
+            AtmosAlarmType.Warning => StyleNano.ConcerningOrangeFore,
+            _ => StyleNano.GoodGreenFore,
+        };
     }
 
 
index 17b03b84684e57c7f0e1ffb76d6bb16565eeca19..2cd51d6fc7f5e8c0c4dc3f5506644da6e8a440bc 100644 (file)
@@ -1,12 +1,8 @@
-using System;
-using Content.Shared.Atmos.Monitor;
 using Content.Shared.Atmos.Monitor.Components;
 using Content.Shared.Atmos.Piping.Unary.Components;
 using Robust.Client.AutoGenerated;
 using Robust.Client.UserInterface.Controls;
-using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
-using Robust.Shared.Localization;
 
 namespace Content.Client.Atmos.Monitor.UI.Widgets;
 
@@ -25,7 +21,7 @@ public sealed partial class PumpControl : BoxContainer
     private OptionButton _pressureCheck => CPressureCheck;
     private FloatSpinBox _externalBound => CExternalBound;
     private FloatSpinBox _internalBound => CInternalBound;
-       private Button _copySettings => CCopySettings;
+    private Button _copySettings => CCopySettings;
 
     public PumpControl(GasVentPumpData data, string address)
     {
@@ -86,7 +82,7 @@ public sealed partial class PumpControl : BoxContainer
             _data.PressureChecks = (VentPressureBound) args.Id;
             PumpDataChanged?.Invoke(_address, _data);
         };
-               
+
                _copySettings.OnPressed += _ =>
                {
                        PumpDataCopied?.Invoke(_data);
index f2241bcd8da7535a0abf50af0afb87548c70a195..c16ff688c93eb6406363a3e2a1af4045674043b9 100644 (file)
@@ -1,15 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
 using Content.Shared.Atmos;
-using Content.Shared.Atmos.Monitor;
 using Content.Shared.Atmos.Monitor.Components;
 using Content.Shared.Atmos.Piping.Unary.Components;
 using Robust.Client.AutoGenerated;
 using Robust.Client.UserInterface.Controls;
-using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
-using Robust.Shared.Localization;
 
 namespace Content.Client.Atmos.Monitor.UI.Widgets;
 
@@ -27,7 +21,7 @@ public sealed partial class ScrubberControl : BoxContainer
     private OptionButton _pumpDirection => CPumpDirection;
     private FloatSpinBox _volumeRate => CVolumeRate;
     private CheckBox _wideNet => CWideNet;
-       private Button _copySettings => CCopySettings;
+    private Button _copySettings => CCopySettings;
 
     private GridContainer _gases => CGasContainer;
     private Dictionary<Gas, Button> _gasControls = new();
@@ -77,7 +71,7 @@ public sealed partial class ScrubberControl : BoxContainer
             _data.PumpDirection = (ScrubberPumpDirection) args.Id;
             ScrubberDataChanged?.Invoke(_address, _data);
         };
-               
+
                _copySettings.OnPressed += _ =>
                {
                        ScrubberDataCopied?.Invoke(_data);
index da602cd7479f8eabf8752b3a4907108d7ff60f9c..9e60b6cea62434422978268f8672954ee210a060 100644 (file)
@@ -43,7 +43,8 @@ public sealed partial class SensorInfo : BoxContainer
             var label = new RichTextLabel();
 
             var fractionGas = amount / data.TotalMoles;
-            label.SetMarkup(Loc.GetString("air-alarm-ui-gases-indicator", ("gas", $"{gas}"),
+            label.SetMarkup(Loc.GetString("air-alarm-ui-gases-indicator",
+                ("gas", $"{gas}"),
                 ("color", AirAlarmWindow.ColorForThreshold(fractionGas, data.GasThresholds[gas])),
                 ("amount", $"{amount:0.####}"),
                 ("percentage", $"{(100 * fractionGas):0.##}")));
@@ -53,9 +54,9 @@ public sealed partial class SensorInfo : BoxContainer
             var threshold = data.GasThresholds[gas];
             var gasThresholdControl = new ThresholdControl(Loc.GetString($"air-alarm-ui-thresholds-gas-title", ("gas", $"{gas}")), threshold, AtmosMonitorThresholdType.Gas, gas, 100);
             gasThresholdControl.Margin = new Thickness(20, 2, 2, 2);
-            gasThresholdControl.ThresholdDataChanged += (type, threshold, arg3) =>
+            gasThresholdControl.ThresholdDataChanged += (type, alarmThreshold, arg3) =>
             {
-                OnThresholdUpdate!(_address, type, threshold, arg3);
+                OnThresholdUpdate!(_address, type, alarmThreshold, arg3);
             };
 
             _gasThresholds.Add(gas, gasThresholdControl);
@@ -64,7 +65,8 @@ public sealed partial class SensorInfo : BoxContainer
 
         _pressureThreshold = new ThresholdControl(Loc.GetString("air-alarm-ui-thresholds-pressure-title"), data.PressureThreshold, AtmosMonitorThresholdType.Pressure);
         PressureThresholdContainer.AddChild(_pressureThreshold);
-        _temperatureThreshold = new ThresholdControl(Loc.GetString("air-alarm-ui-thresholds-temperature-title"), data.TemperatureThreshold,
+        _temperatureThreshold = new ThresholdControl(Loc.GetString("air-alarm-ui-thresholds-temperature-title"),
+            data.TemperatureThreshold,
             AtmosMonitorThresholdType.Temperature);
         TemperatureThresholdContainer.AddChild(_temperatureThreshold);
 
@@ -103,7 +105,8 @@ public sealed partial class SensorInfo : BoxContainer
             }
 
             var fractionGas = amount / data.TotalMoles;
-            label.SetMarkup(Loc.GetString("air-alarm-ui-gases-indicator", ("gas", $"{gas}"),
+            label.SetMarkup(Loc.GetString("air-alarm-ui-gases-indicator",
+                ("gas", $"{gas}"),
                 ("color", AirAlarmWindow.ColorForThreshold(fractionGas, data.GasThresholds[gas])),
                 ("amount", $"{amount:0.####}"),
                 ("percentage", $"{(100 * fractionGas):0.##}")));
index 3612d84de4cbe0ab1b6f20dcb3da9ffe901a84b0..55f7c008987bd63fddfb83d3cef1983e461ddcbb 100644 (file)
@@ -1,7 +1,4 @@
-using Content.Client.Message;
-using Content.Shared.Atmos;
 using Content.Shared.Atmos.Monitor;
-using Content.Shared.Temperature;
 using Robust.Client.AutoGenerated;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
index 78c73fa573a75ddca718d2e83cda8a984b5ef907..651620f3e2595127c8ba590d1d009d043d052607 100644 (file)
@@ -1,12 +1,8 @@
-using System;
 using Content.Shared.Atmos;
 using Content.Shared.Atmos.Monitor;
-using Content.Shared.Atmos.Monitor.Components;
 using Robust.Client.AutoGenerated;
 using Robust.Client.UserInterface.Controls;
-using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
-using Robust.Shared.Localization;
 
 // holy FUCK
 // this technically works because some of this you can *not* do in XAML but holy FUCK
@@ -115,29 +111,38 @@ public sealed partial class ThresholdControl : BoxContainer
         _enabled.Pressed = !_threshold.Ignore;
     }
 
-    private String LabelForBound(string boundType) //<todo.eoin Replace this with enums
+    private string LabelForBound(string boundType) //<todo.eoin Replace this with enums
     {
         return Loc.GetString($"air-alarm-ui-thresholds-{boundType}");
     }
 
     public void UpdateThresholdData(AtmosAlarmThreshold threshold, float currentAmount)
     {
-        threshold.CheckThreshold(currentAmount, out AtmosAlarmType alarm, out AtmosMonitorThresholdBound which);
+        threshold.CheckThreshold(currentAmount, out var alarm, out var bound);
 
         var upperDangerState = AtmosAlarmType.Normal;
         var lowerDangerState = AtmosAlarmType.Normal;
         var upperWarningState = AtmosAlarmType.Normal;
         var lowerWarningState = AtmosAlarmType.Normal;
 
-        if(alarm == AtmosAlarmType.Danger)
+        switch (alarm)
         {
-            if(which == AtmosMonitorThresholdBound.Upper) upperDangerState = alarm;
-            else lowerDangerState = alarm;
-        }
-        else if(alarm == AtmosAlarmType.Warning)
-        {
-            if(which == AtmosMonitorThresholdBound.Upper) upperWarningState = alarm;
-            else lowerWarningState = alarm;
+            case AtmosAlarmType.Danger:
+            {
+                if (bound == AtmosMonitorThresholdBound.Upper)
+                    upperDangerState = alarm;
+                else
+                    lowerDangerState = alarm;
+                break;
+            }
+            case AtmosAlarmType.Warning:
+            {
+                if (bound == AtmosMonitorThresholdBound.Upper)
+                    upperWarningState = alarm;
+                else
+                    lowerWarningState = alarm;
+                break;
+            }
         }
 
         _upperBoundControl.SetValue(threshold.UpperBound.Value);
index c85dbd20512c2356e0fb087a9620da8aeb985062..ef24f1bee8ac31619abaa569b97f989318d9ed04 100644 (file)
@@ -1,3 +1,4 @@
+using System.Globalization;
 using System.Linq;
 using System.Numerics;
 using Content.Client.Atmos.EntitySystems;
@@ -101,14 +102,9 @@ public sealed class AtmosDebugOverlay : Overlay
         else
         {
             // Red-Green-Blue interpolation
-            if (interp < 0.5f)
-            {
-                res = Color.InterpolateBetween(Color.Red, Color.LimeGreen, interp * 2);
-            }
-            else
-            {
-                res = Color.InterpolateBetween(Color.LimeGreen, Color.Blue, (interp - 0.5f) * 2);
-            }
+            res = interp < 0.5f
+                ? Color.InterpolateBetween(Color.Red, Color.LimeGreen, interp * 2)
+                : Color.InterpolateBetween(Color.LimeGreen, Color.Blue, (interp - 0.5f) * 2);
         }
 
         res = res.WithAlpha(0.75f);
@@ -181,7 +177,10 @@ public sealed class AtmosDebugOverlay : Overlay
             handle.DrawCircle(tileCentre, 0.05f, Color.Black);
     }
 
-    private void CheckAndShowBlockDir(AtmosDebugOverlayData data, DrawingHandleWorld handle, AtmosDirection dir,
+    private void CheckAndShowBlockDir(
+        AtmosDebugOverlayData data,
+        DrawingHandleWorld handle,
+        AtmosDirection dir,
         Vector2 tileCentre)
     {
         if (!data.BlockDirection.HasFlag(dir))
@@ -243,7 +242,7 @@ public sealed class AtmosDebugOverlay : Overlay
 
         var moles = data.Moles == null
             ? "No Air"
-            : data.Moles.Sum().ToString();
+            : data.Moles.Sum().ToString(CultureInfo.InvariantCulture);
 
         handle.DrawString(_font, pos, $"Moles: {moles}");
         pos += offset;
@@ -263,7 +262,12 @@ public sealed class AtmosDebugOverlay : Overlay
     private void GetGrids(MapId mapId, Box2Rotated box)
     {
         _grids.Clear();
-        _mapManager.FindGridsIntersecting(mapId, box, ref _grids, (EntityUid uid, MapGridComponent grid,
+        _mapManager.FindGridsIntersecting(
+            mapId,
+            box,
+            ref _grids,
+            (EntityUid uid,
+                MapGridComponent grid,
             ref List<(Entity<MapGridComponent>, DebugMessage)> state) =>
         {
             if (_system.TileData.TryGetValue(uid, out var data))