6
StarHorizon_Public/Content.Client/_NF/Atmos/UI/GasPressureBidiPumpWindow.xaml.cs
2025-11-15 12:24:44 +03:00

80 lines
2.5 KiB
C#

using Content.Client.UserInterface.Controls;
using Content.Shared.Atmos;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
namespace Content.Client._NF.Atmos.UI;
/// <summary>
/// Client-side UI used to control a bidirectional gas pressure pump.
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class GasPressureBidiPumpWindow : FancyWindow
{
public bool PumpStatus = true;
public bool PumpInwards;
public event Action? ToggleStatusButtonPressed;
public event Action? ToggleDirectionButtonPressed;
public event Action<float>? PumpOutputPressureChanged;
public float MaxPressure
{
get => _maxPressure;
set
{
_maxPressure = value;
PumpPressureOutputInput.Value = MathF.Min(value, PumpPressureOutputInput.Value);
}
}
private float _maxPressure = Atmospherics.MaxOutputPressure;
public GasPressureBidiPumpWindow()
{
RobustXamlLoader.Load(this);
ToggleStatusButton.OnPressed += _ => SetPumpStatus(!PumpStatus);
ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke();
ToggleDirectionButton.OnPressed += _ => SetPumpDirection(!PumpInwards);
ToggleDirectionButton.OnPressed += _ => ToggleDirectionButtonPressed?.Invoke();
PumpPressureOutputInput.OnValueChanged += _ => SetOutputPressureButton.Disabled = false;
SetOutputPressureButton.OnPressed += _ =>
{
PumpPressureOutputInput.Value = Math.Clamp(PumpPressureOutputInput.Value, 0f, _maxPressure);
PumpOutputPressureChanged?.Invoke(PumpPressureOutputInput.Value);
SetOutputPressureButton.Disabled = true;
};
SetMaxPressureButton.OnPressed += _ =>
{
PumpPressureOutputInput.Value = _maxPressure;
SetOutputPressureButton.Disabled = false;
};
}
public void SetOutputPressure(float pressure)
{
PumpPressureOutputInput.Value = pressure;
}
public void SetPumpStatus(bool enabled)
{
PumpStatus = enabled;
ToggleStatusButton.Text = Loc.GetString(enabled
? "comp-gas-pump-ui-status-enabled"
: "comp-gas-pump-ui-status-disabled");
}
public void SetPumpDirection(bool inwards)
{
PumpInwards = inwards;
ToggleDirectionButton.Text = Loc.GetString(inwards
? "comp-gas-pump-ui-direction-in"
: "comp-gas-pump-ui-direction-out");
}
}