Makes GasCanisterSystem use ECS BoundUserInterfaces. (#4608)
This commit is contained in:
committed by
GitHub
parent
cdcf11e417
commit
08d6801ec5
@@ -17,16 +17,19 @@ using Content.Shared.Interaction;
|
|||||||
using Content.Shared.Interaction.Helpers;
|
using Content.Shared.Interaction.Helpers;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
|
using Robust.Shared.Players;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class GasCanisterSystem : EntitySystem
|
public class GasCanisterSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
||||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -40,14 +43,14 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
SubscribeLocalEvent<GasCanisterComponent, InteractUsingEvent>(OnCanisterInteractUsing);
|
SubscribeLocalEvent<GasCanisterComponent, InteractUsingEvent>(OnCanisterInteractUsing);
|
||||||
SubscribeLocalEvent<GasCanisterComponent, EntInsertedIntoContainerMessage>(OnCanisterContainerInserted);
|
SubscribeLocalEvent<GasCanisterComponent, EntInsertedIntoContainerMessage>(OnCanisterContainerInserted);
|
||||||
SubscribeLocalEvent<GasCanisterComponent, EntRemovedFromContainerMessage>(OnCanisterContainerRemoved);
|
SubscribeLocalEvent<GasCanisterComponent, EntRemovedFromContainerMessage>(OnCanisterContainerRemoved);
|
||||||
|
// Bound UI subscriptions
|
||||||
|
SubscribeLocalEvent<GasCanisterComponent, GasCanisterHoldingTankEjectMessage>(OnHoldingTankEjectMessage);
|
||||||
|
SubscribeLocalEvent<GasCanisterComponent, GasCanisterChangeReleasePressureMessage>(OnCanisterChangeReleasePressure);
|
||||||
|
SubscribeLocalEvent<GasCanisterComponent, GasCanisterChangeReleaseValveMessage>(OnCanisterChangeReleaseValve);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent canister, ComponentStartup args)
|
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent canister, ComponentStartup args)
|
||||||
{
|
{
|
||||||
// TODO ATMOS: Don't use Owner to get the UI.
|
|
||||||
if(canister.Owner.GetUIOrNull(GasCanisterUiKey.Key) is {} ui)
|
|
||||||
ui.OnReceiveMessage += msg => OnCanisterUIMessage(uid, canister, msg);
|
|
||||||
|
|
||||||
// Ensure container manager.
|
// Ensure container manager.
|
||||||
if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
|
if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
|
||||||
{
|
{
|
||||||
@@ -61,14 +64,22 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool CheckInteract(ICommonSession session)
|
||||||
|
{
|
||||||
|
if (session.AttachedEntity is not {} entity
|
||||||
|
|| !Get<ActionBlockerSystem>().CanInteract(entity)
|
||||||
|
|| !Get<ActionBlockerSystem>().CanUse(entity))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void DirtyUI(EntityUid uid)
|
private void DirtyUI(EntityUid uid)
|
||||||
{
|
{
|
||||||
if (!ComponentManager.TryGetComponent(uid, out IMetaDataComponent? metadata)
|
if (!ComponentManager.TryGetComponent(uid, out IMetaDataComponent? metadata)
|
||||||
|| !ComponentManager.TryGetComponent(uid, out GasCanisterComponent? canister)
|
|| !ComponentManager.TryGetComponent(uid, out GasCanisterComponent? canister)
|
||||||
|| !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|
|| !ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|
||||||
|| !nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode)
|
|| !nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode))
|
||||||
|| !ComponentManager.TryGetComponent(uid, out ServerUserInterfaceComponent? userInterfaceComponent)
|
|
||||||
|| !userInterfaceComponent.TryGetBoundUserInterface(GasCanisterUiKey.Key, out var ui))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string? tankLabel = null;
|
string? tankLabel = null;
|
||||||
@@ -84,45 +95,45 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
tankPressure = tankComponent.Air.Pressure;
|
tankPressure = tankComponent.Air.Pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.SetState(new GasCanisterBoundUserInterfaceState(metadata.EntityName, canister.Air.Pressure,
|
_userInterfaceSystem.TrySetUiState(uid, GasCanisterUiKey.Key, new GasCanisterBoundUserInterfaceState(metadata.EntityName, canister.Air.Pressure,
|
||||||
portNode.NodeGroup?.Nodes.Count > 1, tankLabel, tankPressure,
|
portNode.NodeGroup?.Nodes.Count > 1, tankLabel, tankPressure,
|
||||||
canister.ReleasePressure, canister.ReleaseValve,
|
canister.ReleasePressure, canister.ReleaseValve,
|
||||||
canister.MinReleasePressure, canister.MaxReleasePressure));
|
canister.MinReleasePressure, canister.MaxReleasePressure));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCanisterUIMessage(EntityUid uid, GasCanisterComponent canister, ServerBoundUserInterfaceMessage msg)
|
private void OnHoldingTankEjectMessage(EntityUid uid, GasCanisterComponent canister, GasCanisterHoldingTankEjectMessage args)
|
||||||
{
|
{
|
||||||
if (msg.Session.AttachedEntity is not {} entity
|
if (!CheckInteract(args.Session))
|
||||||
|| !Get<ActionBlockerSystem>().CanInteract(entity)
|
|
||||||
|| !Get<ActionBlockerSystem>().CanUse(entity))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)
|
if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)
|
||||||
|| !containerManager.TryGetContainer(canister.ContainerName, out var container))
|
|| !containerManager.TryGetContainer(canister.ContainerName, out var container))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (msg.Message)
|
if (container.ContainedEntities.Count == 0)
|
||||||
{
|
return;
|
||||||
case GasCanisterHoldingTankEjectMessage:
|
|
||||||
if (container.ContainedEntities.Count == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
container.Remove(container.ContainedEntities[0]);
|
container.Remove(container.ContainedEntities[0]);
|
||||||
break;
|
}
|
||||||
|
|
||||||
case GasCanisterChangeReleasePressureMessage changeReleasePressure:
|
private void OnCanisterChangeReleasePressure(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleasePressureMessage args)
|
||||||
var pressure = Math.Clamp(changeReleasePressure.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure);
|
{
|
||||||
|
if (!CheckInteract(args.Session))
|
||||||
|
return;
|
||||||
|
|
||||||
canister.ReleasePressure = pressure;
|
var pressure = Math.Clamp(args.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure);
|
||||||
DirtyUI(uid);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GasCanisterChangeReleaseValveMessage changeReleaseValve:
|
canister.ReleasePressure = pressure;
|
||||||
canister.ReleaseValve = changeReleaseValve.Valve;
|
DirtyUI(uid);
|
||||||
DirtyUI(uid);
|
}
|
||||||
break;
|
|
||||||
}
|
private void OnCanisterChangeReleaseValve(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleaseValveMessage args)
|
||||||
|
{
|
||||||
|
if (!CheckInteract(args.Session))
|
||||||
|
return;
|
||||||
|
|
||||||
|
canister.ReleaseValve = args.Valve;
|
||||||
|
DirtyUI(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args)
|
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args)
|
||||||
|
|||||||
Reference in New Issue
Block a user