Adds a UI for gas mixers (#5165)
Co-authored-by: E F R <602406+Efruit@users.noreply.github.com> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: ike709 <ike709@github.com>
This commit is contained in:
97
Content.Client/Atmos/UI/GasMixerWindow.xaml.cs
Normal file
97
Content.Client/Atmos/UI/GasMixerWindow.xaml.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
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 partial class GasMixerWindow : SS14Window
|
||||
{
|
||||
public bool MixerStatus = true;
|
||||
|
||||
public event Action? ToggleStatusButtonPressed;
|
||||
public event Action<string>? MixerOutputPressureChanged;
|
||||
public event Action<string>? MixerNodePercentageChanged;
|
||||
|
||||
public bool NodeOneLastEdited = true;
|
||||
|
||||
public GasMixerWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
ToggleStatusButton.OnPressed += _ => SetMixerStatus(!MixerStatus);
|
||||
ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke();
|
||||
|
||||
MixerPressureOutputInput.OnTextChanged += _ => SetOutputPressureButton.Disabled = false;
|
||||
SetOutputPressureButton.OnPressed += _ =>
|
||||
{
|
||||
MixerOutputPressureChanged?.Invoke(MixerPressureOutputInput.Text ??= "");
|
||||
SetOutputPressureButton.Disabled = true;
|
||||
};
|
||||
|
||||
SetMaxPressureButton.OnPressed += _ =>
|
||||
{
|
||||
MixerPressureOutputInput.Text = Atmospherics.MaxOutputPressure.ToString(CultureInfo.InvariantCulture);
|
||||
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.InvariantCulture);
|
||||
}
|
||||
|
||||
public void SetNodePercentages(float nodeOne)
|
||||
{
|
||||
nodeOne *= 100.0f;
|
||||
MixerNodeOneInput.Text = nodeOne.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
float nodeTwo = 100.0f - nodeOne;
|
||||
MixerNodeTwoInput.Text = nodeTwo.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public void SetMixerStatus(bool enabled)
|
||||
{
|
||||
MixerStatus = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
ToggleStatusButton.Text = Loc.GetString("comp-gas-mixer-ui-status-enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
ToggleStatusButton.Text = Loc.GetString("comp-gas-mixer-ui-status-disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user