Adds a UI for gas filters (#5052)

* Adds a UI for gas filters

* Address reviews

* Update Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs

* Update Content.Server/Atmos/Piping/Trinary/EntitySystems/GasFilterSystem.cs

* Fix build

Co-authored-by: ike709 <ike709@github.com>
Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Co-authored-by: Vera Aguilera Puerto <gradientvera@outlook.com>
This commit is contained in:
ike709
2021-11-02 04:44:40 -05:00
committed by GitHub
parent 025a930c08
commit 9da98e3916
8 changed files with 363 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
using System;
using Content.Server.Atmos.Piping.Trinary.EntitySystems;
using Content.Shared.Atmos;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

View File

@@ -1,9 +1,13 @@
using System;
using Content.Server.Atmos.Piping.Components;
using Content.Server.Atmos.Piping.Trinary.Components;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes;
using Content.Server.UserInterface;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping;
using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Interaction;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
@@ -16,12 +20,18 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
public class GasFilterSystem : EntitySystem
{
[Dependency] private IGameTiming _gameTiming = default!;
[Dependency] private UserInterfaceSystem _userInterfaceSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasFilterComponent, AtmosDeviceUpdateEvent>(OnFilterUpdated);
SubscribeLocalEvent<GasFilterComponent, InteractHandEvent>(OnFilterInteractHand);
// Bound UI subscriptions
SubscribeLocalEvent<GasFilterComponent, GasFilterChangeRateMessage>(OnTransferRateChangeMessage);
SubscribeLocalEvent<GasFilterComponent, GasFilterSelectGasMessage>(OnSelectGasMessage);
SubscribeLocalEvent<GasFilterComponent, GasFilterToggleStatusMessage>(OnToggleStatusMessage);
}
private void OnFilterUpdated(EntityUid uid, GasFilterComponent filter, AtmosDeviceUpdateEvent args)
@@ -66,5 +76,49 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
outletNode.AssumeAir(removed);
}
private void OnFilterInteractHand(EntityUid uid, GasFilterComponent component, InteractHandEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
return;
_userInterfaceSystem.TryOpen(uid, GasFilterUiKey.Key, actor.PlayerSession);
DirtyUI(uid, component);
args.Handled = true;
}
private void DirtyUI(EntityUid uid, GasFilterComponent? filter)
{
if (!Resolve(uid, ref filter))
return;
_userInterfaceSystem.TrySetUiState(uid, GasFilterUiKey.Key,
new GasFilterBoundUserInterfaceState(filter.Owner.Name, filter.TransferRate, filter.Enabled, filter.FilteredGas));
}
private void OnToggleStatusMessage(EntityUid uid, GasFilterComponent filter, GasFilterToggleStatusMessage args)
{
filter.Enabled = args.Enabled;
DirtyUI(uid, filter);
}
private void OnTransferRateChangeMessage(EntityUid uid, GasFilterComponent filter, GasFilterChangeRateMessage args)
{
filter.TransferRate = Math.Clamp(args.Rate, 0f, Atmospherics.MaxTransferRate);
DirtyUI(uid, filter);
}
private void OnSelectGasMessage(EntityUid uid, GasFilterComponent filter, GasFilterSelectGasMessage args)
{
if (Enum.TryParse<Gas>(args.ID.ToString(), true, out var parsedGas))
{
filter.FilteredGas = parsedGas;
DirtyUI(uid, filter);
}
}
}
}