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:
91
Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs
Normal file
91
Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using Content.Client.Atmos.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Piping.Binary.Components;
|
||||
using Content.Shared.Atmos.Piping.Trinary.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Atmos.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="GasMixerWindow"/> and updates it when new server messages are received.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public class GasMixerBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
|
||||
private GasMixerWindow? _window;
|
||||
private const float MaxPressure = Atmospherics.MaxOutputPressure;
|
||||
|
||||
public GasMixerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new GasMixerWindow();
|
||||
|
||||
if(State != null)
|
||||
UpdateState(State);
|
||||
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.OnClose += Close;
|
||||
|
||||
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
|
||||
_window.MixerOutputPressureChanged += OnMixerOutputPressurePressed;
|
||||
_window.MixerNodePercentageChanged += OnMixerSetPercentagePressed;
|
||||
}
|
||||
|
||||
private void OnToggleStatusButtonPressed()
|
||||
{
|
||||
if (_window is null) return;
|
||||
SendMessage(new GasMixerToggleStatusMessage(_window.MixerStatus));
|
||||
}
|
||||
|
||||
private void OnMixerOutputPressurePressed(string value)
|
||||
{
|
||||
float pressure = float.TryParse(value, out var parsed) ? parsed : 0f;
|
||||
if (pressure > MaxPressure) pressure = MaxPressure;
|
||||
|
||||
SendMessage(new GasMixerChangeOutputPressureMessage(pressure));
|
||||
}
|
||||
|
||||
private void OnMixerSetPercentagePressed(string value)
|
||||
{
|
||||
// We don't need to send both nodes because it's just 1.0f - node
|
||||
float node = float.TryParse(value, out var parsed) ? parsed : 1.0f;
|
||||
|
||||
if(_window is not null) node = _window.NodeOneLastEdited ? node : 1.0f - node;
|
||||
|
||||
SendMessage(new GasMixerChangeNodePercentageMessage(node));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the UI state based on server-sent info
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
if (_window == null || state is not GasMixerBoundUserInterfaceState cast)
|
||||
return;
|
||||
|
||||
_window.Title = (cast.MixerLabel);
|
||||
_window.SetMixerStatus(cast.Enabled);
|
||||
_window.SetOutputPressure(cast.OutputPressure);
|
||||
_window.SetNodePercentages(cast.NodeOne);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing) return;
|
||||
_window?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
38
Content.Client/Atmos/UI/GasMixerWindow.xaml
Normal file
38
Content.Client/Atmos/UI/GasMixerWindow.xaml
Normal file
@@ -0,0 +1,38 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:Content.Client.Stylesheets"
|
||||
MinSize="200 200" Title="Gas Mixer">
|
||||
<BoxContainer Orientation="Vertical" Margin="5 5 5 5" SeparationOverride="10">
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Label Text="{Loc comp-gas-mixer-ui-mixer-status} "/>
|
||||
<Control MinSize="5 0" />
|
||||
<Button Name="ToggleStatusButton"/>
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Label Text="{Loc comp-gas-mixer-ui-mixer-output-pressure} "/>
|
||||
<Control MinSize="5 0" />
|
||||
<LineEdit Name="MixerPressureOutputInput" MinSize="60 0" />
|
||||
<Control MinSize="5 0" />
|
||||
<Button Name="SetMaxPressureButton" Text="{Loc comp-gas-mixer-ui-mixer-max}" />
|
||||
<Control MinSize="5 0" />
|
||||
<Control HorizontalExpand="True" />
|
||||
<Button Name="SetOutputPressureButton" Text="{Loc comp-gas-mixer-ui-mixer-set}" HorizontalAlignment="Right" Disabled="True"/>
|
||||
<Control MinSize="0 5" />
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Control MinSize="0 5" />
|
||||
<Label Text="{Loc comp-gas-mixer-ui-mixer-node-primary} "/>
|
||||
<Control MinSize="5 0" />
|
||||
<LineEdit Name="MixerNodeOneInput" MinSize="60 0" />
|
||||
<Label Text=" %"/>
|
||||
<Control MinSize="5 0" />
|
||||
<Label Text="{Loc comp-gas-mixer-ui-mixer-node-side} "/>
|
||||
<Control MinSize="5 0" />
|
||||
<LineEdit Name="MixerNodeTwoInput" MinSize="60 0" />
|
||||
<Label Text=" %"/>
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Button Name="SetMixerPercentageButton" Text="{Loc comp-gas-mixer-ui-mixer-set}" HorizontalAlignment="Right" Disabled="True"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
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