Adds UIs for volume and pressure pumps (#5155)

* Adds UIs for volume and pressure pumps

* Update Content.Server/Atmos/Piping/Binary/EntitySystems/GasPressurePumpSystem.cs

* Update Content.Server/Atmos/Piping/Binary/EntitySystems/GasVolumePumpSystem.cs

Co-authored-by: ike709 <ike709@github.com>
This commit is contained in:
ike709
2021-11-04 19:41:56 -05:00
committed by GitHub
parent b4f0051ca3
commit 17e1b7827e
12 changed files with 532 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
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="GasPressurePumpWindow"/> and updates it when new server messages are received.
/// </summary>
[UsedImplicitly]
public class GasPressurePumpBoundUserInterface : BoundUserInterface
{
private GasPressurePumpWindow? _window;
private const float MaxPressure = Atmospherics.MaxOutputPressure;
public GasPressurePumpBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = new GasPressurePumpWindow();
if(State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.PumpOutputPressureChanged += OnPumpOutputPressurePressed;
}
private void OnToggleStatusButtonPressed()
{
if (_window is null) return;
SendMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus));
}
private void OnPumpOutputPressurePressed(string value)
{
float pressure = float.TryParse(value, out var parsed) ? parsed : 0f;
if (pressure > MaxPressure) pressure = MaxPressure;
SendMessage(new GasPressurePumpChangeOutputPressureMessage(pressure));
}
/// <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 GasPressurePumpBoundUserInterfaceState cast)
return;
_window.Title = (cast.PumpLabel);
_window.SetPumpStatus(cast.Enabled);
_window.SetOutputPressure(cast.OutputPressure);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
}
}

View File

@@ -0,0 +1,23 @@
<SS14Window xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:Content.Client.Stylesheets"
MinSize="200 120" Title="Pressure Pump">
<BoxContainer Orientation="Vertical" Margin="5 5 5 5" SeparationOverride="10">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Label Text="{Loc comp-gas-pump-ui-pump-status} "/>
<Control MinSize="5 0" />
<Button Name="ToggleStatusButton"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Label Text="{Loc comp-gas-pump-ui-pump-output-pressure} "/>
<Control MinSize="5 0" />
<LineEdit Name="PumpPressureOutputInput" MinSize="60 0" />
<Control MinSize="5 0" />
<Button Name="SetMaxPressureButton" Text="{Loc comp-gas-pump-ui-pump-set-max}" />
<Control MinSize="5 0" />
<Control HorizontalExpand="True" />
<Button Name="SetOutputPressureButton" Text="{Loc comp-gas-pump-ui-pump-set-rate}" HorizontalAlignment="Right" Disabled="True"/>
</BoxContainer>
</BoxContainer>
</SS14Window>

View File

@@ -0,0 +1,65 @@
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.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization;
namespace Content.Client.Atmos.UI
{
/// <summary>
/// Client-side UI used to control a gas pressure pump.
/// </summary>
[GenerateTypedNameReferences]
public partial class GasPressurePumpWindow : SS14Window
{
public bool PumpStatus = true;
public event Action? ToggleStatusButtonPressed;
public event Action<string>? PumpOutputPressureChanged;
public GasPressurePumpWindow()
{
RobustXamlLoader.Load(this);
ToggleStatusButton.OnPressed += _ => SetPumpStatus(!PumpStatus);
ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke();
PumpPressureOutputInput.OnTextChanged += _ => SetOutputPressureButton.Disabled = false;
SetOutputPressureButton.OnPressed += _ =>
{
PumpOutputPressureChanged?.Invoke(PumpPressureOutputInput.Text ??= "");
SetOutputPressureButton.Disabled = true;
};
SetMaxPressureButton.OnPressed += _ =>
{
PumpPressureOutputInput.Text = Atmospherics.MaxOutputPressure.ToString(CultureInfo.InvariantCulture);
SetOutputPressureButton.Disabled = false;
};
}
public void SetOutputPressure(float pressure)
{
PumpPressureOutputInput.Text = pressure.ToString(CultureInfo.InvariantCulture);
}
public void SetPumpStatus(bool enabled)
{
PumpStatus = enabled;
if (enabled)
{
ToggleStatusButton.Text = Loc.GetString("comp-gas-pump-ui-status-enabled");
}
else
{
ToggleStatusButton.Text = Loc.GetString("comp-gas-pump-ui-status-disabled");
}
}
}
}

View File

@@ -0,0 +1,76 @@
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Binary.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Client.Atmos.UI
{
/// <summary>
/// Initializes a <see cref="GasVolumePumpWindow"/> and updates it when new server messages are received.
/// </summary>
[UsedImplicitly]
public class GasVolumePumpBoundUserInterface : BoundUserInterface
{
private GasVolumePumpWindow? _window;
private const float MaxTransferRate = Atmospherics.MaxTransferRate;
public GasVolumePumpBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = new GasVolumePumpWindow();
if(State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.PumpTransferRateChanged += OnPumpTransferRatePressed;
}
private void OnToggleStatusButtonPressed()
{
if (_window is null) return;
SendMessage(new GasVolumePumpToggleStatusMessage(_window.PumpStatus));
}
private void OnPumpTransferRatePressed(string value)
{
float rate = float.TryParse(value, out var parsed) ? parsed : 0f;
if (rate > MaxTransferRate) rate = MaxTransferRate;
SendMessage(new GasVolumePumpChangeTransferRateMessage(rate));
}
/// <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 GasVolumePumpBoundUserInterfaceState cast)
return;
_window.Title = (cast.PumpLabel);
_window.SetPumpStatus(cast.Enabled);
_window.SetTransferRate(cast.TransferRate);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
}
}

View File

@@ -0,0 +1,23 @@
<SS14Window xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:Content.Client.Stylesheets"
MinSize="200 120" Title="Volume Pump">
<BoxContainer Orientation="Vertical" Margin="5 5 5 5" SeparationOverride="10">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Label Text="{Loc comp-gas-pump-ui-pump-status} "/>
<Control MinSize="5 0" />
<Button Name="ToggleStatusButton"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Label Text="{Loc comp-gas-pump-ui-pump-transfer-rate} "/>
<Control MinSize="5 0" />
<LineEdit Name="PumpTransferRateInput" MinSize="60 0" />
<Control MinSize="5 0" />
<Button Name="SetMaxRateButton" Text="{Loc comp-gas-pump-ui-pump-set-max}" />
<Control MinSize="5 0" />
<Control HorizontalExpand="True" />
<Button Name="SetTransferRateButton" Text="{Loc comp-gas-pump-ui-pump-set-rate}" HorizontalAlignment="Right" Disabled="True"/>
</BoxContainer>
</BoxContainer>
</SS14Window>

View File

@@ -0,0 +1,65 @@
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.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization;
namespace Content.Client.Atmos.UI
{
/// <summary>
/// Client-side UI used to control a gas volume pump.
/// </summary>
[GenerateTypedNameReferences]
public partial class GasVolumePumpWindow : SS14Window
{
public bool PumpStatus = true;
public event Action? ToggleStatusButtonPressed;
public event Action<string>? PumpTransferRateChanged;
public GasVolumePumpWindow()
{
RobustXamlLoader.Load(this);
ToggleStatusButton.OnPressed += _ => SetPumpStatus(!PumpStatus);
ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke();
PumpTransferRateInput.OnTextChanged += _ => SetTransferRateButton.Disabled = false;
SetTransferRateButton.OnPressed += _ =>
{
PumpTransferRateChanged?.Invoke(PumpTransferRateInput.Text ??= "");
SetTransferRateButton.Disabled = true;
};
SetMaxRateButton.OnPressed += _ =>
{
PumpTransferRateInput.Text = Atmospherics.MaxTransferRate.ToString(CultureInfo.InvariantCulture);
SetTransferRateButton.Disabled = false;
};
}
public void SetTransferRate(float rate)
{
PumpTransferRateInput.Text = rate.ToString(CultureInfo.InvariantCulture);
}
public void SetPumpStatus(bool enabled)
{
PumpStatus = enabled;
if (enabled)
{
ToggleStatusButton.Text = Loc.GetString("comp-gas-pump-ui-status-enabled");
}
else
{
ToggleStatusButton.Text = Loc.GetString("comp-gas-pump-ui-status-disabled");
}
}
}
}

View File

@@ -1,13 +1,17 @@
using System;
using Content.Server.Atmos.Piping.Binary.Components; using Content.Server.Atmos.Piping.Binary.Components;
using Content.Server.Atmos.Piping.Components; using Content.Server.Atmos.Piping.Components;
using Content.Server.NodeContainer; using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes; using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping; using Content.Shared.Atmos.Piping;
using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Maths; using Robust.Shared.Maths;
@@ -16,6 +20,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
[UsedImplicitly] [UsedImplicitly]
public class GasPressurePumpSystem : EntitySystem public class GasPressurePumpSystem : EntitySystem
{ {
[Dependency] private UserInterfaceSystem _userInterfaceSystem = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -23,6 +29,10 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceUpdateEvent>(OnPumpUpdated); SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceUpdateEvent>(OnPumpUpdated);
SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceDisabledEvent>(OnPumpLeaveAtmosphere); SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceDisabledEvent>(OnPumpLeaveAtmosphere);
SubscribeLocalEvent<GasPressurePumpComponent, ExaminedEvent>(OnExamined); SubscribeLocalEvent<GasPressurePumpComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<GasPressurePumpComponent, InteractHandEvent>(OnPumpInteractHand);
// Bound UI subscriptions
SubscribeLocalEvent<GasPressurePumpComponent, GasPressurePumpChangeOutputPressureMessage>(OnOutputPressureChangeMessage);
SubscribeLocalEvent<GasPressurePumpComponent, GasPressurePumpToggleStatusMessage>(OnToggleStatusMessage);
} }
private void OnExamined(EntityUid uid, GasPressurePumpComponent pump, ExaminedEvent args) private void OnExamined(EntityUid uid, GasPressurePumpComponent pump, ExaminedEvent args)
@@ -79,5 +89,37 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
} }
} }
private void OnPumpInteractHand(EntityUid uid, GasPressurePumpComponent component, InteractHandEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
return;
_userInterfaceSystem.TryOpen(uid, GasPressurePumpUiKey.Key, actor.PlayerSession);
DirtyUI(uid, component);
args.Handled = true;
}
private void OnToggleStatusMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpToggleStatusMessage args)
{
pump.Enabled = args.Enabled;
DirtyUI(uid, pump);
}
private void OnOutputPressureChangeMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpChangeOutputPressureMessage args)
{
pump.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure);
DirtyUI(uid, pump);
}
private void DirtyUI(EntityUid uid, GasPressurePumpComponent? pump)
{
if (!Resolve(uid, ref pump))
return;
_userInterfaceSystem.TrySetUiState(uid, GasPressurePumpUiKey.Key,
new GasPressurePumpBoundUserInterfaceState(pump.Owner.Name, pump.TargetPressure, pump.Enabled));
}
} }
} }

View File

@@ -1,10 +1,15 @@
using System;
using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Piping.Binary.Components; using Content.Server.Atmos.Piping.Binary.Components;
using Content.Server.Atmos.Piping.Components; using Content.Server.Atmos.Piping.Components;
using Content.Server.NodeContainer; using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes; using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
@@ -17,6 +22,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private UserInterfaceSystem _userInterfaceSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -24,6 +30,10 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceUpdateEvent>(OnVolumePumpUpdated); SubscribeLocalEvent<GasVolumePumpComponent, AtmosDeviceUpdateEvent>(OnVolumePumpUpdated);
SubscribeLocalEvent<GasVolumePumpComponent, ExaminedEvent>(OnExamined); SubscribeLocalEvent<GasVolumePumpComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<GasVolumePumpComponent, InteractHandEvent>(OnPumpInteractHand);
// Bound UI subscriptions
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpChangeTransferRateMessage>(OnTransferRateChangeMessage);
SubscribeLocalEvent<GasVolumePumpComponent, GasVolumePumpToggleStatusMessage>(OnToggleStatusMessage);
} }
private void OnExamined(EntityUid uid, GasVolumePumpComponent pump, ExaminedEvent args) private void OnExamined(EntityUid uid, GasVolumePumpComponent pump, ExaminedEvent args)
@@ -83,5 +93,38 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
outlet.AssumeAir(removed); outlet.AssumeAir(removed);
} }
private void OnPumpInteractHand(EntityUid uid, GasVolumePumpComponent component, InteractHandEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
return;
_userInterfaceSystem.TryOpen(uid, GasVolumePumpUiKey.Key, actor.PlayerSession);
DirtyUI(uid, component);
args.Handled = true;
}
private void OnToggleStatusMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpToggleStatusMessage args)
{
pump.Enabled = args.Enabled;
DirtyUI(uid, pump);
}
private void OnTransferRateChangeMessage(EntityUid uid, GasVolumePumpComponent pump, GasVolumePumpChangeTransferRateMessage args)
{
pump.TransferRate = Math.Clamp(args.TransferRate, 0f, Atmospherics.MaxTransferRate);
DirtyUI(uid, pump);
}
private void DirtyUI(EntityUid uid, GasVolumePumpComponent? pump)
{
if (!Resolve(uid, ref pump))
return;
_userInterfaceSystem.TrySetUiState(uid, GasVolumePumpUiKey.Key,
new GasVolumePumpBoundUserInterfaceState(pump.Owner.Name, pump.TransferRate, pump.Enabled));
}
} }
} }

View File

@@ -0,0 +1,49 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Piping.Binary.Components
{
[Serializable, NetSerializable]
public enum GasPressurePumpUiKey
{
Key,
}
[Serializable, NetSerializable]
public class GasPressurePumpBoundUserInterfaceState : BoundUserInterfaceState
{
public string PumpLabel { get; }
public float OutputPressure { get; }
public bool Enabled { get; }
public GasPressurePumpBoundUserInterfaceState(string pumpLabel, float outputPressure, bool enabled)
{
PumpLabel = pumpLabel;
OutputPressure = outputPressure;
Enabled = enabled;
}
}
[Serializable, NetSerializable]
public class GasPressurePumpToggleStatusMessage : BoundUserInterfaceMessage
{
public bool Enabled { get; }
public GasPressurePumpToggleStatusMessage(bool enabled)
{
Enabled = enabled;
}
}
[Serializable, NetSerializable]
public class GasPressurePumpChangeOutputPressureMessage : BoundUserInterfaceMessage
{
public float Pressure { get; }
public GasPressurePumpChangeOutputPressureMessage(float pressure)
{
Pressure = pressure;
}
}
}

View File

@@ -0,0 +1,49 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Piping.Binary.Components
{
[Serializable, NetSerializable]
public enum GasVolumePumpUiKey
{
Key,
}
[Serializable, NetSerializable]
public class GasVolumePumpBoundUserInterfaceState : BoundUserInterfaceState
{
public string PumpLabel { get; }
public float TransferRate { get; }
public bool Enabled { get; }
public GasVolumePumpBoundUserInterfaceState(string pumpLabel, float transferRate, bool enabled)
{
PumpLabel = pumpLabel;
TransferRate = transferRate;
Enabled = enabled;
}
}
[Serializable, NetSerializable]
public class GasVolumePumpToggleStatusMessage : BoundUserInterfaceMessage
{
public bool Enabled { get; }
public GasVolumePumpToggleStatusMessage(bool enabled)
{
Enabled = enabled;
}
}
[Serializable, NetSerializable]
public class GasVolumePumpChangeTransferRateMessage : BoundUserInterfaceMessage
{
public float TransferRate { get; }
public GasVolumePumpChangeTransferRateMessage(float transferRate)
{
TransferRate = transferRate;
}
}
}

View File

@@ -0,0 +1,10 @@
comp-gas-pump-ui-pump-status = Status:
comp-gas-pump-ui-status-enabled = On
comp-gas-pump-ui-status-disabled = Off
comp-gas-pump-ui-pump-set-rate = Set
comp-gas-pump-ui-pump-set-max = Max
comp-gas-pump-ui-pump-output-pressure = Output Pressure (kPa):
comp-gas-pump-ui-pump-transfer-rate = Transfer Rate (L/s):

View File

@@ -43,6 +43,10 @@
disabledState: pumpPressure disabledState: pumpPressure
enabledState: pumpPressureOn enabledState: pumpPressureOn
- type: GasPressurePump - type: GasPressurePump
- type: UserInterface
interfaces:
- key: enum.GasPressurePumpUiKey.Key
type: GasPressurePumpBoundUserInterface
- type: entity - type: entity
parent: GasBinaryBase parent: GasBinaryBase
@@ -67,6 +71,10 @@
- type: PipeConnectorVisualizer - type: PipeConnectorVisualizer
- type: PipeColorVisualizer - type: PipeColorVisualizer
- type: GasVolumePump - type: GasVolumePump
- type: UserInterface
interfaces:
- key: enum.GasVolumePumpUiKey.Key
type: GasVolumePumpBoundUserInterface
- type: entity - type: entity
parent: GasBinaryBase parent: GasBinaryBase