Adds a UI for gas mixers (#5165)

Co-authored-by: E F R <602406+Efruit@users.noreply.github.com>
Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
Co-authored-by: ike709 <ike709@github.com>
This commit is contained in:
ike709
2021-11-11 16:10:21 -06:00
committed by GitHub
parent c6615fd805
commit c06f52a456
12 changed files with 401 additions and 6 deletions

View File

@@ -4,19 +4,31 @@ using Content.Server.Atmos.Piping.Trinary.Components;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
{
[UsedImplicitly]
public class GasMixerSystem : EntitySystem
{
[Dependency] private UserInterfaceSystem _userInterfaceSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasMixerComponent, AtmosDeviceUpdateEvent>(OnMixerUpdated);
SubscribeLocalEvent<GasMixerComponent, InteractHandEvent>(OnMixerInteractHand);
// Bound UI subscriptions
SubscribeLocalEvent<GasMixerComponent, GasMixerChangeOutputPressureMessage>(OnOutputPressureChangeMessage);
SubscribeLocalEvent<GasMixerComponent, GasMixerChangeNodePercentageMessage>(OnChangeNodePercentageMessage);
SubscribeLocalEvent<GasMixerComponent, GasMixerToggleStatusMessage>(OnToggleStatusMessage);
}
private void OnMixerUpdated(EntityUid uid, GasMixerComponent mixer, AtmosDeviceUpdateEvent args)
@@ -91,5 +103,53 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
outlet.AssumeAir(removed);
}
}
private void OnMixerInteractHand(EntityUid uid, GasMixerComponent component, InteractHandEvent args)
{
if (!args.User.TryGetComponent(out ActorComponent? actor))
return;
if (component.Owner.Transform.Anchored)
{
_userInterfaceSystem.TryOpen(uid, GasMixerUiKey.Key, actor.PlayerSession);
DirtyUI(uid, component);
}
else
{
args.User.PopupMessageCursor(Loc.GetString("comp-gas-mixer-ui-needs-anchor"));
}
args.Handled = true;
}
private void DirtyUI(EntityUid uid, GasMixerComponent? mixer)
{
if (!Resolve(uid, ref mixer))
return;
_userInterfaceSystem.TrySetUiState(uid, GasMixerUiKey.Key,
new GasMixerBoundUserInterfaceState(mixer.Owner.Name, mixer.TargetPressure, mixer.Enabled, mixer.InletOneConcentration));
}
private void OnToggleStatusMessage(EntityUid uid, GasMixerComponent mixer, GasMixerToggleStatusMessage args)
{
mixer.Enabled = args.Enabled;
DirtyUI(uid, mixer);
}
private void OnOutputPressureChangeMessage(EntityUid uid, GasMixerComponent mixer, GasMixerChangeOutputPressureMessage args)
{
mixer.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure);
DirtyUI(uid, mixer);
}
private void OnChangeNodePercentageMessage(EntityUid uid, GasMixerComponent mixer,
GasMixerChangeNodePercentageMessage args)
{
float nodeOne = Math.Clamp(args.NodeOne, 0f, 100.0f) / 100.0f;
mixer.InletOneConcentration = nodeOne;
mixer.InletTwoConcentration = 1.0f - mixer.InletOneConcentration;
DirtyUI(uid, mixer);
}
}
}