CatStation/Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml.cs
Rouden cc2c14f8e4
Device Network refactor part 1: API improvements (#44346)
* Refactor DeviceNetwork

* Singleton

* NetworkPayloads refactor

* Reorganize DeviceNetworkSystem

* Surveillance cameras

* Fix code

* Fix build

* Fix test fail by rewriting entire singleton logic

* Properly predict examine

* Update DeviceNetworkSystem.API.cs

* Update EntityTest.cs

* Update DeviceNetworkSystem.cs

* Alright I'll do this expensive check fine

* Fix disposals debug assert

* Implement device network static events support

* Use frozen dictionaries for performance

* Update SharedDeviceNetworkSystem.Payloads.cs

* Parallel payload handling support

* Fix some spagetti-code

* Optimize NetworkPayload cancellation

* Parallel payloads are now cancellable

* Fix screens

* Fix robotics console

* Allow new methods for shared

* Mail fix

* Turret fix

* Fix network system method usage + signal and borg fix

* finally fix atmos devices OH MY GOOOD

* Remove stupid parallelism from fax

* Fix surveiollance cameras

* Working on a single thing for 2 days straight award

* Fix the test?

* Update units.yml

* Add IDevice interface because why not

* Add more device network suffixes

* Fix camera router failing test

* yaml linter peak

* Improve docs for DeviceNetworkHandlers

* fix build

* Update CartridgeLoaderSystem.Relay.cs

* Remove parallel system and EntitySystem post init

* Add more docs and also events

* Remove unnecessary caching

* Update DevicePayloadComponentSystem.cs

* Back to entity events

* Implement DeviceData

* Remove serializable from payloads

* Update DeviceData.cs

* Add a prototype for a singleton

* Fix tests

* Fix air alarms

* Update DeviceNetworkSystem.cs

* Fix cameras

* Make camera router event-less

* Fix atmos sync payloads, add more docs

* Remove singleton + instant packets

* oops remove public access

* Fix tests?

* Why the hell overload effect makes puddle sparks

* Apparently it was redundant

* Update gates.yml

* Finish documentation

* Review

* Mark relay properties as obsolete

* Struct payloads support (#blazinglyfastmemorysafe)

* Update DeviceNetworkTest.cs

* Make device structs stuff better

* Move address prefix to DeviceNetworkComponent

* Locale fixes

* Fix tests

* Doesn't know boolean logic award

* Update AtmosAlarmableSystem.cs

* Fix address predicted examine

* Partial fix to air alarmables

* Fix deployable turrets UI

* Fix firelocks, maybe

* Apparently Activatable UI was enough lol

* Fix surveillance cameras

* Rename `QueuePacket` into `SendPacket`

* Simplify DeviceData as much as possible

* Update DeviceData.cs

* Update FaxMachineComponent.cs

* Remove DeviceData because its stupid

* Update ScreenSystem.cs

* Fix build (camera map broken still)

* Fix map

* fix usings

* Review changes

* Build fix
2026-08-31 19:42:56 +00:00

155 lines
5.3 KiB
C#

using Content.Shared.Atmos;
using Content.Shared.Atmos.EntitySystems;
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Atmos.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client.Atmos.Monitor.UI.Widgets;
[GenerateTypedNameReferences]
public sealed partial class ScrubberControl : BoxContainer
{
[Dependency] private IPrototypeManager _prototypeManager = default!;
[Dependency] private IEntityManager _entMan = default!;
private GasVentScrubberData _dataPayload;
private string _address;
public event Action<string, IAtmosDeviceData>? ScrubberDataChanged;
public event Action<IAtmosDeviceData>? ScrubberDataCopied;
private CheckBox _enabled => CEnableDevice;
private CollapsibleHeading _addressLabel => CAddress;
private OptionButton _pumpDirection => CPumpDirection;
private FloatSpinBox _volumeRate => CVolumeRate;
private CheckBox _wideNet => CWideNet;
private Button _copySettings => CCopySettings;
private Button _selectAll => CSelectAll;
private Button _deselectAll => CDeselectAll;
private GridContainer _gases => CGasContainer;
private Dictionary<Gas, Button> _gasControls = new();
public ScrubberControl(GasVentScrubberData dataPayload, string address)
{
IoCManager.InjectDependencies(this);
var atmosphereSystem = _entMan.System<SharedAtmosphereSystem>();
RobustXamlLoader.Load(this);
Name = address;
_dataPayload = dataPayload;
_address = address;
_addressLabel.Title = Loc.GetString("air-alarm-ui-atmos-net-device-label", ("address", $"{address}"));
_enabled.Pressed = dataPayload.Enabled;
_enabled.OnToggled += _ =>
{
_dataPayload.Enabled = _enabled.Pressed;
ScrubberDataChanged?.Invoke(_address, _dataPayload);
};
_wideNet.Pressed = dataPayload.WideNet;
_wideNet.OnToggled += _ =>
{
_dataPayload.WideNet = _wideNet.Pressed;
ScrubberDataChanged?.Invoke(_address, _dataPayload);
};
_volumeRate.Value = _dataPayload.VolumeRate;
_volumeRate.OnValueChanged += _ =>
{
_dataPayload.VolumeRate = _volumeRate.Value;
ScrubberDataChanged?.Invoke(_address, _dataPayload);
};
_volumeRate.IsValid += value => value >= 0;
foreach (var value in Enum.GetValues<ScrubberPumpDirection>())
{
_pumpDirection.AddItem(Loc.GetString($"air-alarm-ui-pump-direction-{value.ToString().ToLower()}"), (int) value);
}
_pumpDirection.SelectId((int) _dataPayload.PumpDirection);
_pumpDirection.OnItemSelected += args =>
{
_pumpDirection.SelectId(args.Id);
_dataPayload.PumpDirection = (ScrubberPumpDirection) args.Id;
ScrubberDataChanged?.Invoke(_address, _dataPayload);
};
_pumpDirection.Disabled = dataPayload.AirAlarmPanicWireCut;
_copySettings.OnPressed += _ =>
{
ScrubberDataCopied?.Invoke(_dataPayload);
};
var allGases = Enum.GetValues<Gas>();
_selectAll.OnPressed += _ =>
{
_dataPayload.FilterGases = new HashSet<Gas>(allGases);
ScrubberDataChanged?.Invoke(_address, _dataPayload);
};
_deselectAll.OnPressed += _ =>
{
_dataPayload.FilterGases = [];
ScrubberDataChanged?.Invoke(_address, _dataPayload);
};
foreach (var value in allGases)
{
ProtoId<GasPrototype> gasProtoId = atmosphereSystem.GetGas(value);
var gasName = _prototypeManager.Index(gasProtoId).Name;
var gasButton = new Button
{
Name = value.ToString(),
Text = Loc.GetString(gasName),
ToggleMode = true,
HorizontalExpand = true,
Pressed = _dataPayload.FilterGases.Contains(value)
};
gasButton.OnToggled += args =>
{
if (args.Pressed)
_dataPayload.FilterGases.Add(value);
else
_dataPayload.FilterGases.Remove(value);
ScrubberDataChanged?.Invoke(_address, _dataPayload);
};
_gasControls.Add(value, gasButton);
_gases.AddChild(gasButton);
}
}
public void ChangeData(GasVentScrubberData dataPayload)
{
_dataPayload.Enabled = dataPayload.Enabled;
_enabled.Pressed = _dataPayload.Enabled;
_dataPayload.PumpDirection = dataPayload.PumpDirection;
_pumpDirection.Select((int) _dataPayload.PumpDirection);
_pumpDirection.Disabled = dataPayload.AirAlarmPanicWireCut;
_dataPayload.VolumeRate = dataPayload.VolumeRate;
_volumeRate.Value = _dataPayload.VolumeRate;
_dataPayload.WideNet = dataPayload.WideNet;
_wideNet.Pressed = _dataPayload.WideNet;
_dataPayload.FilterGases = dataPayload.FilterGases;
foreach (var value in Enum.GetValues<Gas>())
{
_gasControls[value].Pressed = dataPayload.FilterGases.Contains(value);
}
}
}