Files
ss14-wega/Content.Client/Atmos/UI/GasVolumePumpBoundUserInterface.cs
T
Absotively 118b83165b Gas device power switches use switch buttons (#42619)
* Switch button for gas filter power

* Switch button for gas mixer power

* Switch button for gas pump power

* Switch button for thermomachine power

* Switch button for space heater power

* Remove redundant switch labels
2026-02-01 19:54:05 +00:00

67 lines
2.0 KiB
C#

using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Localizations;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI
{
/// <summary>
/// Initializes a <see cref="GasVolumePumpWindow"/> and updates it when new server messages are received.
/// </summary>
[UsedImplicitly]
public sealed class GasVolumePumpBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private float _maxTransferRate;
[ViewVariables]
private GasVolumePumpWindow? _window;
public GasVolumePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = this.CreateWindow<GasVolumePumpWindow>();
if (EntMan.TryGetComponent(Owner, out GasVolumePumpComponent? pump))
{
_maxTransferRate = pump.MaxTransferRate;
}
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.PumpTransferRateChanged += OnPumpTransferRatePressed;
Update();
}
private void OnToggleStatusButtonPressed(bool status)
{
SendPredictedMessage(new GasVolumePumpToggleStatusMessage(status));
}
private void OnPumpTransferRatePressed(string value)
{
var rate = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f;
rate = Math.Clamp(rate, 0f, _maxTransferRate);
SendPredictedMessage(new GasVolumePumpChangeTransferRateMessage(rate));
}
public override void Update()
{
base.Update();
if (_window is null || !EntMan.TryGetComponent(Owner, out GasVolumePumpComponent? pump))
return;
_window.Title = Identity.Name(Owner, EntMan);
_window.SetPumpStatus(pump.Enabled);
_window.SetTransferRate(pump.TransferRate);
}
}
}