Allow gas filters to not filter gases. (#12051)

This commit is contained in:
Vordenburg
2022-11-03 21:27:20 -04:00
committed by GitHub
parent 86ef8c5473
commit bf908512bd
5 changed files with 42 additions and 16 deletions

View File

@@ -1,10 +1,8 @@
using System; using Content.Client.Atmos.EntitySystems;
using Content.Client.Atmos.EntitySystems;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Trinary.Components; using Content.Shared.Atmos.Piping.Trinary.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Client.Atmos.UI namespace Content.Client.Atmos.UI
{ {
@@ -58,10 +56,17 @@ namespace Content.Client.Atmos.UI
private void OnSelectGasPressed() private void OnSelectGasPressed()
{ {
if (_window is null || _window.SelectedGas is null) return; if (_window is null) return;
if (_window.SelectedGas is null)
{
SendMessage(new GasFilterSelectGasMessage(null));
}
else
{
if (!int.TryParse(_window.SelectedGas, out var gas)) return; if (!int.TryParse(_window.SelectedGas, out var gas)) return;
SendMessage(new GasFilterSelectGasMessage(gas)); SendMessage(new GasFilterSelectGasMessage(gas));
} }
}
/// <summary> /// <summary>
/// Update the UI state based on server-sent info /// Update the UI state based on server-sent info
@@ -84,7 +89,7 @@ namespace Content.Client.Atmos.UI
} }
else else
{ {
_window.SetGasFiltered(null, "None"); _window.SetGasFiltered(null, Loc.GetString("comp-gas-filter-ui-filter-gas-none"));
} }
} }

View File

@@ -75,6 +75,12 @@ namespace Content.Client.Atmos.UI
private void PopulateGasList(IEnumerable<GasPrototype> gases) private void PopulateGasList(IEnumerable<GasPrototype> gases)
{ {
GasList.Add(new ItemList.Item(GasList)
{
Metadata = null,
Text = Loc.GetString("comp-gas-filter-ui-filter-gas-none")
});
foreach (GasPrototype gas in gases) foreach (GasPrototype gas in gases)
{ {
GasList.Add(GetGasItem(gas.ID, gas.Name, GasList)); GasList.Add(GetGasItem(gas.ID, gas.Name, GasList));

View File

@@ -13,6 +13,7 @@ using Content.Shared.Interaction;
using Content.Shared.Popups; using Content.Shared.Popups;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Player;
using Robust.Shared.Timing; using Robust.Shared.Timing;
namespace Content.Server.Atmos.Piping.Trinary.EntitySystems 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 IAdminLogManager _adminLogger = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!; [Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -110,7 +113,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
} }
else 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; args.Handled = true;
@@ -125,12 +128,12 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
new GasFilterBoundUserInterfaceState(EntityManager.GetComponent<MetaDataComponent>(filter.Owner).EntityName, filter.TransferRate, filter.Enabled, filter.FilteredGas)); new GasFilterBoundUserInterfaceState(EntityManager.GetComponent<MetaDataComponent>(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; return;
appearance.SetData(FilterVisuals.Enabled, filter.Enabled); _appearanceSystem.SetData(uid, FilterVisuals.Enabled, filter.Enabled);
} }
private void OnToggleStatusMessage(EntityUid uid, GasFilterComponent filter, GasFilterToggleStatusMessage args) private void OnToggleStatusMessage(EntityUid uid, GasFilterComponent filter, GasFilterToggleStatusMessage args)
@@ -152,13 +155,24 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
} }
private void OnSelectGasMessage(EntityUid uid, GasFilterComponent filter, GasFilterSelectGasMessage args) private void OnSelectGasMessage(EntityUid uid, GasFilterComponent filter, GasFilterSelectGasMessage args)
{
if (args.ID.HasValue)
{ {
if (Enum.TryParse<Gas>(args.ID.ToString(), true, out var parsedGas)) if (Enum.TryParse<Gas>(args.ID.ToString(), true, out var parsedGas))
{ {
filter.FilteredGas = parsedGas; filter.FilteredGas = parsedGas;
DirtyUI(uid, filter); DirtyUI(uid, filter);
} }
else
{
Logger.Warning("atmos", $"{ToPrettyString(uid)} received GasFilterSelectGasMessage with an invalid ID: {args.ID}");
}
}
else
{
filter.FilteredGas = null;
DirtyUI(uid, filter);
}
} }
/// <summary> /// <summary>

View File

@@ -50,9 +50,9 @@ namespace Content.Shared.Atmos.Piping.Trinary.Components
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class GasFilterSelectGasMessage : BoundUserInterfaceMessage public sealed class GasFilterSelectGasMessage : BoundUserInterfaceMessage
{ {
public int ID { get; } public int? ID { get; }
public GasFilterSelectGasMessage(int id) public GasFilterSelectGasMessage(int? id)
{ {
ID = id; ID = id;
} }

View File

@@ -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-current = Currently Filtering:
comp-gas-filter-ui-filter-gas-select = Select a gas to filter out: 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-confirm = Set Gas
comp-gas-filter-ui-filter-gas-none = None
comp-gas-filter-ui-needs-anchor = Anchor it first! comp-gas-filter-ui-needs-anchor = Anchor it first!