From bf908512bda167ab939494d4e85858441f3eb4ce Mon Sep 17 00:00:00 2001 From: Vordenburg <114301317+Vordenburg@users.noreply.github.com> Date: Thu, 3 Nov 2022 21:27:20 -0400 Subject: [PATCH] Allow gas filters to not filter gases. (#12051) --- .../Atmos/UI/GasFilterBoundUserInterface.cs | 19 ++++++++----- .../Atmos/UI/GasFilterWindow.xaml.cs | 6 ++++ .../Trinary/EntitySystems/GasFilterSystem.cs | 28 ++++++++++++++----- .../Components/SharedGasFilterComponent.cs | 4 +-- .../en-US/components/gas-filter-component.ftl | 1 + 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs b/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs index 3b16fc0609..bde3111516 100644 --- a/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs @@ -1,10 +1,8 @@ -using System; -using Content.Client.Atmos.EntitySystems; +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 { @@ -58,9 +56,16 @@ namespace Content.Client.Atmos.UI private void OnSelectGasPressed() { - if (_window is null || _window.SelectedGas is null) return; - if (!int.TryParse(_window.SelectedGas, out var gas)) return; - SendMessage(new GasFilterSelectGasMessage(gas)); + if (_window is null) return; + if (_window.SelectedGas is null) + { + SendMessage(new GasFilterSelectGasMessage(null)); + } + else + { + if (!int.TryParse(_window.SelectedGas, out var gas)) return; + SendMessage(new GasFilterSelectGasMessage(gas)); + } } /// @@ -84,7 +89,7 @@ namespace Content.Client.Atmos.UI } else { - _window.SetGasFiltered(null, "None"); + _window.SetGasFiltered(null, Loc.GetString("comp-gas-filter-ui-filter-gas-none")); } } diff --git a/Content.Client/Atmos/UI/GasFilterWindow.xaml.cs b/Content.Client/Atmos/UI/GasFilterWindow.xaml.cs index d52de513d6..cd5212b996 100644 --- a/Content.Client/Atmos/UI/GasFilterWindow.xaml.cs +++ b/Content.Client/Atmos/UI/GasFilterWindow.xaml.cs @@ -75,6 +75,12 @@ namespace Content.Client.Atmos.UI private void PopulateGasList(IEnumerable gases) { + GasList.Add(new ItemList.Item(GasList) + { + Metadata = null, + Text = Loc.GetString("comp-gas-filter-ui-filter-gas-none") + }); + foreach (GasPrototype gas in gases) { GasList.Add(GetGasItem(gas.ID, gas.Name, GasList)); diff --git a/Content.Server/Atmos/Piping/Trinary/EntitySystems/GasFilterSystem.cs b/Content.Server/Atmos/Piping/Trinary/EntitySystems/GasFilterSystem.cs index f15e0e7290..1d83bbb389 100644 --- a/Content.Server/Atmos/Piping/Trinary/EntitySystems/GasFilterSystem.cs +++ b/Content.Server/Atmos/Piping/Trinary/EntitySystems/GasFilterSystem.cs @@ -13,6 +13,7 @@ using Content.Shared.Interaction; using Content.Shared.Popups; using JetBrains.Annotations; using Robust.Server.GameObjects; +using Robust.Shared.Player; using Robust.Shared.Timing; namespace Content.Server.Atmos.Piping.Trinary.EntitySystems @@ -25,6 +26,8 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems [Dependency] private IAdminLogManager _adminLogger = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!; + [Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; public override void Initialize() { @@ -110,7 +113,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems } else { - args.User.PopupMessageCursor(Loc.GetString("comp-gas-filter-ui-needs-anchor")); + _popupSystem.PopupCursor(Loc.GetString("comp-gas-filter-ui-needs-anchor"), Filter.Entities(args.User)); } args.Handled = true; @@ -125,12 +128,12 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems new GasFilterBoundUserInterfaceState(EntityManager.GetComponent(filter.Owner).EntityName, filter.TransferRate, filter.Enabled, filter.FilteredGas)); } - private void UpdateAppearance(EntityUid uid, GasFilterComponent? filter = null, AppearanceComponent? appearance = null) + private void UpdateAppearance(EntityUid uid, GasFilterComponent? filter = null) { - if (!Resolve(uid, ref filter, ref appearance, false)) + if (!Resolve(uid, ref filter, false)) return; - appearance.SetData(FilterVisuals.Enabled, filter.Enabled); + _appearanceSystem.SetData(uid, FilterVisuals.Enabled, filter.Enabled); } private void OnToggleStatusMessage(EntityUid uid, GasFilterComponent filter, GasFilterToggleStatusMessage args) @@ -153,12 +156,23 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems private void OnSelectGasMessage(EntityUid uid, GasFilterComponent filter, GasFilterSelectGasMessage args) { - if (Enum.TryParse(args.ID.ToString(), true, out var parsedGas)) + if (args.ID.HasValue) { - filter.FilteredGas = parsedGas; + if (Enum.TryParse(args.ID.ToString(), true, out var parsedGas)) + { + filter.FilteredGas = parsedGas; + DirtyUI(uid, filter); + } + else + { + Logger.Warning("atmos", $"{ToPrettyString(uid)} received GasFilterSelectGasMessage with an invalid ID: {args.ID}"); + } + } + else + { + filter.FilteredGas = null; DirtyUI(uid, filter); } - } /// diff --git a/Content.Shared/Atmos/Piping/Trinary/Components/SharedGasFilterComponent.cs b/Content.Shared/Atmos/Piping/Trinary/Components/SharedGasFilterComponent.cs index a5e2b19612..947ad01e1b 100644 --- a/Content.Shared/Atmos/Piping/Trinary/Components/SharedGasFilterComponent.cs +++ b/Content.Shared/Atmos/Piping/Trinary/Components/SharedGasFilterComponent.cs @@ -50,9 +50,9 @@ namespace Content.Shared.Atmos.Piping.Trinary.Components [Serializable, NetSerializable] public sealed class GasFilterSelectGasMessage : BoundUserInterfaceMessage { - public int ID { get; } + public int? ID { get; } - public GasFilterSelectGasMessage(int id) + public GasFilterSelectGasMessage(int? id) { ID = id; } diff --git a/Resources/Locale/en-US/components/gas-filter-component.ftl b/Resources/Locale/en-US/components/gas-filter-component.ftl index 20edf6938f..f0b2a67cb8 100644 --- a/Resources/Locale/en-US/components/gas-filter-component.ftl +++ b/Resources/Locale/en-US/components/gas-filter-component.ftl @@ -8,5 +8,6 @@ comp-gas-filter-ui-filter-set-rate = Set comp-gas-filter-ui-filter-gas-current = Currently Filtering: comp-gas-filter-ui-filter-gas-select = Select a gas to filter out: comp-gas-filter-ui-filter-gas-confirm = Set Gas +comp-gas-filter-ui-filter-gas-none = None comp-gas-filter-ui-needs-anchor = Anchor it first!