Files
Delta-v/Content.Client/Atmos/UI/GasMixerWindow.xaml.cs
T
Absotively 3d9c2bc891 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-06-29 12:43:45 +02:00

87 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using Content.Client.Atmos.EntitySystems;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
namespace Content.Client.Atmos.UI
{
/// <summary>
/// Client-side UI used to control a gas mixer.
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class GasMixerWindow : DefaultWindow
{
public event Action<bool>? ToggleStatusButtonPressed;
public event Action<string>? MixerOutputPressureChanged;
public event Action<string>? MixerNodePercentageChanged;
public bool NodeOneLastEdited = true;
public GasMixerWindow()
{
RobustXamlLoader.Load(this);
ToggleStatusButton.OnToggled += _ => ToggleStatusButtonPressed?.Invoke(ToggleStatusButton.Pressed);
MixerPressureOutputInput.OnTextChanged += _ => SetOutputPressureButton.Disabled = false;
SetOutputPressureButton.OnPressed += _ =>
{
MixerOutputPressureChanged?.Invoke(MixerPressureOutputInput.Text ??= "");
SetOutputPressureButton.Disabled = true;
};
SetMaxPressureButton.OnPressed += _ =>
{
MixerPressureOutputInput.Text = Atmospherics.MaxOutputPressure.ToString(CultureInfo.CurrentCulture);
SetOutputPressureButton.Disabled = false;
};
MixerNodeOneInput.OnTextChanged += _ =>
{
SetMixerPercentageButton.Disabled = false;
NodeOneLastEdited = true;
};
MixerNodeTwoInput.OnTextChanged += _ =>
{
SetMixerPercentageButton.Disabled = false;
NodeOneLastEdited = false;
};
SetMixerPercentageButton.OnPressed += _ =>
{
MixerNodePercentageChanged?.Invoke(NodeOneLastEdited ? MixerNodeOneInput.Text ??= "" : MixerNodeTwoInput.Text ??= "");
SetMixerPercentageButton.Disabled = true;
};
}
public void SetOutputPressure(float pressure)
{
MixerPressureOutputInput.Text = pressure.ToString(CultureInfo.CurrentCulture);
}
public void SetNodePercentages(float nodeOne)
{
nodeOne *= 100.0f;
MixerNodeOneInput.Text = nodeOne.ToString("0.##", CultureInfo.CurrentCulture);
float nodeTwo = 100.0f - nodeOne;
MixerNodeTwoInput.Text = nodeTwo.ToString("0.##", CultureInfo.CurrentCulture);
}
public void SetMixerStatus(bool enabled)
{
ToggleStatusButton.Pressed = enabled;
}
}
}