Files
tbd-station-14/Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml.cs
Ser11y d7f8614c35 localization support to air alarms, wire panels and more (#39307)
* Add localization to the air alarms, wire panels, network configurator list menu and loadout window

* delete unused

* redo gas localization, delete unused

* removed the extra key

* Moved and renamed air-alarm-ui-thresholds-gas-name

* Moved localization to the XAML

* Use existing strings for gas names

* it just works

* Rename _atmosphereSystem in ScrubberControl.xaml.cs

_atmosphereSystem -> atmosphereSystem

* Rename _atmosphereSystem in SensorInfo.xaml.cs

_atmosphereSystem -> atmosphereSystem
2025-08-05 17:13:04 +02:00

156 lines
5.0 KiB
C#

using Content.Shared.Atmos;
using Content.Shared.Atmos.EntitySystems;
using Content.Shared.Atmos.Monitor.Components;
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 readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
private GasVentScrubberData _data;
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 data, string address)
{
IoCManager.InjectDependencies(this);
var atmosphereSystem = _entMan.System<SharedAtmosphereSystem>();
RobustXamlLoader.Load(this);
Name = address;
_data = data;
_address = address;
_addressLabel.Title = Loc.GetString("air-alarm-ui-atmos-net-device-label", ("address", $"{address}"));
_enabled.Pressed = data.Enabled;
_enabled.OnToggled += _ =>
{
_data.Enabled = _enabled.Pressed;
ScrubberDataChanged?.Invoke(_address, _data);
};
_wideNet.Pressed = data.WideNet;
_wideNet.OnToggled += _ =>
{
_data.WideNet = _wideNet.Pressed;
ScrubberDataChanged?.Invoke(_address, _data);
};
_volumeRate.Value = _data.VolumeRate;
_volumeRate.OnValueChanged += _ =>
{
_data.VolumeRate = _volumeRate.Value;
ScrubberDataChanged?.Invoke(_address, _data);
};
_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) _data.PumpDirection);
_pumpDirection.OnItemSelected += args =>
{
_pumpDirection.SelectId(args.Id);
_data.PumpDirection = (ScrubberPumpDirection) args.Id;
ScrubberDataChanged?.Invoke(_address, _data);
};
_pumpDirection.Disabled = data.AirAlarmPanicWireCut;
_copySettings.OnPressed += _ =>
{
ScrubberDataCopied?.Invoke(_data);
};
var allGases = Enum.GetValues<Gas>();
_selectAll.OnPressed += _ =>
{
_data.FilterGases = new HashSet<Gas>(allGases);
ScrubberDataChanged?.Invoke(_address, _data);
};
_deselectAll.OnPressed += _ =>
{
_data.FilterGases = [];
ScrubberDataChanged?.Invoke(_address, _data);
};
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 = _data.FilterGases.Contains(value)
};
gasButton.OnToggled += args =>
{
if (args.Pressed)
_data.FilterGases.Add(value);
else
_data.FilterGases.Remove(value);
ScrubberDataChanged?.Invoke(_address, _data);
};
_gasControls.Add(value, gasButton);
_gases.AddChild(gasButton);
}
}
public void ChangeData(GasVentScrubberData data)
{
_data.Enabled = data.Enabled;
_enabled.Pressed = _data.Enabled;
_data.PumpDirection = data.PumpDirection;
_pumpDirection.Select((int) _data.PumpDirection);
_pumpDirection.Disabled = data.AirAlarmPanicWireCut;
_data.VolumeRate = data.VolumeRate;
_volumeRate.Value = _data.VolumeRate;
_data.WideNet = data.WideNet;
_wideNet.Pressed = _data.WideNet;
_data.FilterGases = data.FilterGases;
foreach (var value in Enum.GetValues<Gas>())
{
_gasControls[value].Pressed = data.FilterGases.Contains(value);
}
}
}