diff --git a/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs b/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs new file mode 100644 index 0000000000..271748e9d9 --- /dev/null +++ b/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs @@ -0,0 +1,98 @@ +using System; +using Content.Client.Atmos.EntitySystems; +using Content.Shared.Atmos; +using Content.Shared.Atmos.Piping.Trinary.Components; +using JetBrains.Annotations; +using Robust.Client.GameObjects; +using Robust.Shared.GameObjects; + +namespace Content.Client.Atmos.UI +{ + /// + /// Initializes a and updates it when new server messages are received. + /// + [UsedImplicitly] + public class GasFilterBoundUserInterface : BoundUserInterface + { + + private GasFilterWindow? _window; + private const float MaxTransferRate = Atmospherics.MaxTransferRate; + + public GasFilterBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + + var atmosSystem = EntitySystem.Get(); + + _window = new GasFilterWindow(atmosSystem.Gases); + + if(State != null) + UpdateState(State); + + _window.OpenCentered(); + + _window.OnClose += Close; + + _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; + _window.FilterTransferRateChanged += OnFilterTransferRatePressed; + _window.SelectGasPressed += OnSelectGasPressed; + } + + private void OnToggleStatusButtonPressed() + { + if (_window is null) return; + SendMessage(new GasFilterToggleStatusMessage(_window.FilterStatus)); + } + + private void OnFilterTransferRatePressed(string value) + { + float rate = float.TryParse(value, out var parsed) ? parsed : 0f; + if (rate > MaxTransferRate) rate = MaxTransferRate; + + SendMessage(new GasFilterChangeRateMessage(rate)); + } + + private void OnSelectGasPressed() + { + if (_window is null || _window.SelectedGas is null) return; + if (!Int32.TryParse(_window.SelectedGas, out var gas)) return; + SendMessage(new GasFilterSelectGasMessage(gas)); + } + + /// + /// Update the UI state based on server-sent info + /// + /// + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + if (_window == null || state is not GasFilterBoundUserInterfaceState cast) + return; + + _window.Title = (cast.FilterLabel); + _window.SetFilterStatus(cast.Enabled); + _window.SetTransferRate(cast.TransferRate); + if (cast.FilteredGas is not null) + { + var atmos = EntitySystem.Get(); + var gas = atmos.GetGas((Gas) cast.FilteredGas); + _window.SetGasFiltered(gas.ID, gas.Name); + } + else + { + _window.SetGasFiltered(null, "None"); + } + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) return; + _window?.Dispose(); + } + } +} diff --git a/Content.Client/Atmos/UI/GasFilterWindow.xaml b/Content.Client/Atmos/UI/GasFilterWindow.xaml new file mode 100644 index 0000000000..b6ea716fb4 --- /dev/null +++ b/Content.Client/Atmos/UI/GasFilterWindow.xaml @@ -0,0 +1,28 @@ + + + +