mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* move * NetworkedComponent * anchor * split * move * mixer * fix * builds * I forgor * moar * filename typo * fix admin log * ftl * metadata * IOC readonly 2 * yet another IOC readonly * new features * test I fix you * review 1 * review 2 * docs
67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using Content.Shared.Atmos.Piping.Trinary.Components;
|
|
using Content.Shared.Localizations;
|
|
using JetBrains.Annotations;
|
|
using Robust.Client.UserInterface;
|
|
|
|
namespace Content.Client.Atmos.UI;
|
|
|
|
/// <summary>
|
|
/// Initializes a <see cref="GasMixerWindow"/> and updates it from the entity's <see cref="GasMixerComponent"/>.
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
public sealed class GasMixerBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
|
|
{
|
|
[ViewVariables]
|
|
private GasMixerWindow? _window;
|
|
|
|
protected override void Open()
|
|
{
|
|
base.Open();
|
|
|
|
_window = this.CreateWindow<GasMixerWindow>();
|
|
|
|
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
|
|
_window.MixerOutputPressureChanged += OnMixerOutputPressurePressed;
|
|
_window.MixerNodePercentageChanged += OnMixerSetPercentagePressed;
|
|
|
|
Update();
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
if (_window == null || !EntMan.TryGetComponent(Owner, out GasMixerComponent? mixer))
|
|
return;
|
|
|
|
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
|
|
_window.SetMixerStatus(mixer.Enabled);
|
|
_window.SetOutputPressure(mixer.TargetPressure);
|
|
_window.SetNodePercentages(mixer.InletOneConcentration);
|
|
}
|
|
|
|
private void OnToggleStatusButtonPressed(bool status)
|
|
{
|
|
SendPredictedMessage(new GasMixerToggleStatusMessage(status));
|
|
}
|
|
|
|
private void OnMixerOutputPressurePressed(string value)
|
|
{
|
|
var pressure = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f;
|
|
|
|
SendPredictedMessage(new GasMixerChangeOutputPressureMessage(pressure));
|
|
}
|
|
|
|
private void OnMixerSetPercentagePressed(string value)
|
|
{
|
|
// We don't need to send both nodes because it's just 100.0f - node
|
|
var node = UserInputParser.TryFloat(value, out var parsed) ? parsed : 1.0f;
|
|
|
|
node = Math.Clamp(node, 0f, 100.0f);
|
|
|
|
if (_window is not null)
|
|
node = _window.NodeOneLastEdited ? node : 100.0f - node;
|
|
|
|
SendPredictedMessage(new GasMixerChangeNodePercentageMessage(node));
|
|
}
|
|
}
|