Gas Analyzer can now scan pipes/devices along with the environment (#10976)
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
* GasAnalyzableComponent is a component for anything that can be examined with a gas analyzer.
|
||||
*/
|
||||
namespace Content.Server.Atmos.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class GasAnalyzableComponent : Component
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Atmos.Components
|
||||
@@ -17,227 +7,24 @@ namespace Content.Server.Atmos.Components
|
||||
[ComponentReference(typeof(SharedGasAnalyzerComponent))]
|
||||
public sealed class GasAnalyzerComponent : SharedGasAnalyzerComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
[ViewVariables] public EntityUid? Target;
|
||||
[ViewVariables] public EntityUid User;
|
||||
[ViewVariables] public EntityCoordinates? LastPosition;
|
||||
[ViewVariables] public bool Enabled;
|
||||
}
|
||||
|
||||
private GasAnalyzerDanger _pressureDanger;
|
||||
private float _timeSinceSync;
|
||||
private const float TimeBetweenSyncs = 2f;
|
||||
private bool _checkPlayer = false; // Check at the player pos or at some other tile?
|
||||
private EntityCoordinates? _position; // The tile that we scanned
|
||||
private AppearanceComponent? _appearance;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GasAnalyzerUiKey.Key);
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
||||
}
|
||||
|
||||
_entities.TryGetComponent(Owner, out _appearance);
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new GasAnalyzerComponentState(_pressureDanger);
|
||||
}
|
||||
/// <summary>
|
||||
/// Used to keep track of which analyzers are active for update purposes
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class ActiveGasAnalyzerComponent : Component
|
||||
{
|
||||
// Set to a tiny bit after the default because otherwise the user often gets a blank window when first using
|
||||
public float AccumulatedFrametime = 2.01f;
|
||||
|
||||
/// <summary>
|
||||
/// Call this from other components to open the gas analyzer UI.
|
||||
/// Uses the player position.
|
||||
/// How often to update the analyzer
|
||||
/// </summary>
|
||||
/// <param name="session">The session to open the ui for</param>
|
||||
public void OpenInterface(IPlayerSession session)
|
||||
{
|
||||
_checkPlayer = true;
|
||||
_position = null;
|
||||
UserInterface?.Open(session);
|
||||
UpdateUserInterface();
|
||||
UpdateAppearance(true);
|
||||
Resync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call this from other components to open the gas analyzer UI.
|
||||
/// Uses a given position.
|
||||
/// </summary>
|
||||
/// <param name="session">The session to open the ui for</param>
|
||||
/// <param name="pos">The position to analyze the gas</param>
|
||||
public void OpenInterface(IPlayerSession session, EntityCoordinates pos)
|
||||
{
|
||||
_checkPlayer = false;
|
||||
_position = pos;
|
||||
UserInterface?.Open(session);
|
||||
UpdateUserInterface();
|
||||
UpdateAppearance(true);
|
||||
Resync();
|
||||
}
|
||||
|
||||
public void ToggleInterface(IPlayerSession session)
|
||||
{
|
||||
if (UserInterface == null)
|
||||
return;
|
||||
|
||||
if (UserInterface.SessionHasOpen(session))
|
||||
CloseInterface(session);
|
||||
else
|
||||
OpenInterface(session);
|
||||
}
|
||||
|
||||
public void CloseInterface(IPlayerSession session)
|
||||
{
|
||||
_position = null;
|
||||
UserInterface?.Close(session);
|
||||
// Our OnClose will do the appearance stuff
|
||||
Resync();
|
||||
}
|
||||
|
||||
public void UpdateAppearance(bool open)
|
||||
{
|
||||
_appearance?.SetData(GasAnalyzerVisuals.VisualState,
|
||||
open ? GasAnalyzerVisualState.Working : GasAnalyzerVisualState.Off);
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
_timeSinceSync += frameTime;
|
||||
if (_timeSinceSync > TimeBetweenSyncs)
|
||||
{
|
||||
Resync();
|
||||
UpdateUserInterface();
|
||||
}
|
||||
}
|
||||
|
||||
private void Resync()
|
||||
{
|
||||
// Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth
|
||||
var pressure = 0f;
|
||||
var tile = EntitySystem.Get<AtmosphereSystem>().GetContainingMixture(Owner, true);
|
||||
if (tile != null)
|
||||
{
|
||||
pressure = tile.Pressure;
|
||||
}
|
||||
|
||||
if (pressure >= Atmospherics.HazardHighPressure || pressure <= Atmospherics.HazardLowPressure)
|
||||
{
|
||||
_pressureDanger = GasAnalyzerDanger.Hazard;
|
||||
}
|
||||
else if (pressure >= Atmospherics.WarningHighPressure || pressure <= Atmospherics.WarningLowPressure)
|
||||
{
|
||||
_pressureDanger = GasAnalyzerDanger.Warning;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pressureDanger = GasAnalyzerDanger.Nominal;
|
||||
}
|
||||
|
||||
Dirty();
|
||||
_timeSinceSync = 0f;
|
||||
}
|
||||
|
||||
private void UpdateUserInterface()
|
||||
{
|
||||
if (UserInterface == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string? error = null;
|
||||
|
||||
// Check if the player is still holding the gas analyzer => if not, don't update
|
||||
foreach (var session in UserInterface.SubscribedSessions)
|
||||
{
|
||||
if (session.AttachedEntity is not {Valid: true} playerEntity)
|
||||
return;
|
||||
|
||||
if (!_entities.TryGetComponent(playerEntity, out HandsComponent? handsComponent))
|
||||
return;
|
||||
|
||||
if (handsComponent?.ActiveHandEntity is not {Valid: true} activeHandEntity ||
|
||||
!_entities.TryGetComponent(activeHandEntity, out GasAnalyzerComponent? gasAnalyzer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var pos = _entities.GetComponent<TransformComponent>(Owner).Coordinates;
|
||||
if (!_checkPlayer && _position.HasValue)
|
||||
{
|
||||
// Check if position is out of range => don't update
|
||||
if (!_position.Value.InRange(_entities, pos, SharedInteractionSystem.InteractionRange))
|
||||
return;
|
||||
|
||||
pos = _position.Value;
|
||||
}
|
||||
|
||||
var gridUid = pos.GetGridUid(_entities);
|
||||
var mapUid = pos.GetMapUid(_entities);
|
||||
var position = pos.ToVector2i(_entities, IoCManager.Resolve<IMapManager>());
|
||||
|
||||
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
|
||||
var tile = atmosphereSystem.GetTileMixture(gridUid, mapUid, position);
|
||||
if (tile == null)
|
||||
{
|
||||
error = "No Atmosphere!";
|
||||
UserInterface.SetState(
|
||||
new GasAnalyzerBoundUserInterfaceState(
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
error));
|
||||
return;
|
||||
}
|
||||
|
||||
var gases = new List<GasEntry>();
|
||||
|
||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
||||
{
|
||||
var gas = atmosphereSystem.GetGas(i);
|
||||
|
||||
if (tile.Moles[i] <= Atmospherics.GasMinMoles) continue;
|
||||
|
||||
gases.Add(new GasEntry(gas.Name, tile.Moles[i], gas.Color));
|
||||
}
|
||||
|
||||
UserInterface.SetState(
|
||||
new GasAnalyzerBoundUserInterfaceState(
|
||||
tile.Pressure,
|
||||
tile.Temperature,
|
||||
gases.ToArray(),
|
||||
error));
|
||||
}
|
||||
|
||||
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
|
||||
{
|
||||
var message = serverMsg.Message;
|
||||
switch (message)
|
||||
{
|
||||
case GasAnalyzerRefreshMessage msg:
|
||||
if (serverMsg.Session.AttachedEntity is not {Valid: true} player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entities.TryGetComponent(player, out HandsComponent? handsComponent))
|
||||
{
|
||||
Owner.PopupMessage(player, Loc.GetString("gas-analyzer-component-player-has-no-hands-message"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (handsComponent.ActiveHandEntity is not {Valid: true} activeHandEntity ||
|
||||
!_entities.TryGetComponent(activeHandEntity, out GasAnalyzerComponent? gasAnalyzer))
|
||||
{
|
||||
serverMsg.Session.AttachedEntity.Value.PopupMessage(Loc.GetString("gas-analyzer-component-need-gas-analyzer-in-hand-message"));
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateUserInterface();
|
||||
Resync();
|
||||
break;
|
||||
}
|
||||
}
|
||||
public float UpdateInterval = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.NodeContainer.Nodes;
|
||||
using Content.Server.NodeContainer;
|
||||
using Content.Shared.Atmos.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Temperature;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class GasAnalyzableSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GasAnalyzableComponent, GetVerbsEvent<ExamineVerb>>(OnGetExamineVerbs);
|
||||
SubscribeLocalEvent<GasAnalyzerComponent, BoundUIClosedEvent>((_,c,_) => c.UpdateAppearance(false));
|
||||
}
|
||||
|
||||
private void OnGetExamineVerbs(EntityUid uid, GasAnalyzableComponent component, GetVerbsEvent<ExamineVerb> args)
|
||||
{
|
||||
// Must be in details range to try this.
|
||||
if (_examineSystem.IsInDetailsRange(args.User, args.Target))
|
||||
{
|
||||
var held = args.Using;
|
||||
var enabled = held != null && EntityManager.HasComponent<SharedGasAnalyzerComponent>(held);
|
||||
var verb = new ExamineVerb
|
||||
{
|
||||
Disabled = !enabled,
|
||||
Message = Loc.GetString("gas-analyzable-system-verb-tooltip"),
|
||||
Text = Loc.GetString("gas-analyzable-system-verb-name"),
|
||||
Category = VerbCategory.Examine,
|
||||
IconTexture = "/Textures/Interface/VerbIcons/examine.svg.192dpi.png",
|
||||
Act = () =>
|
||||
{
|
||||
var markup = FormattedMessage.FromMarkup(GeneratePipeMarkup(uid));
|
||||
_examineSystem.SendExamineTooltip(args.User, uid, markup, false, false);
|
||||
}
|
||||
};
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
}
|
||||
|
||||
private string GeneratePipeMarkup(EntityUid uid, NodeContainerComponent? nodeContainer = null)
|
||||
{
|
||||
if (!Resolve(uid, ref nodeContainer))
|
||||
return Loc.GetString("gas-analyzable-system-internal-error-missing-component");
|
||||
|
||||
List<string> portNames = new List<string>();
|
||||
List<string> portData = new List<string>();
|
||||
foreach (var node in nodeContainer.Nodes)
|
||||
{
|
||||
if (node.Value is not PipeNode pn)
|
||||
continue;
|
||||
float pressure = pn.Air.Pressure;
|
||||
float temp = pn.Air.Temperature;
|
||||
portNames.Add(node.Key);
|
||||
portData.Add(Loc.GetString("gas-analyzable-system-statistics",
|
||||
("pressure", pressure),
|
||||
("tempK", $"{temp:0.#}"),
|
||||
("tempC", $"{TemperatureHelpers.KelvinToCelsius(temp):0.#}")
|
||||
));
|
||||
}
|
||||
|
||||
int count = portNames.Count;
|
||||
if (count == 0)
|
||||
return Loc.GetString("gas-anlayzable-system-internal-error-no-gas-node");
|
||||
else if (count == 1)
|
||||
// omit names if only one node
|
||||
return Loc.GetString("gas-analyzable-system-header") + "\n" + portData[0];
|
||||
else
|
||||
{
|
||||
var outputs = portNames.Zip(portData, ((name, data) => name + ":\n" + data));
|
||||
return Loc.GetString("gas-analyzable-system-header") + "\n\n" + String.Join("\n\n", outputs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.NodeContainer;
|
||||
using Content.Server.NodeContainer.Nodes;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
using static Content.Shared.Atmos.Components.SharedGasAnalyzerComponent;
|
||||
|
||||
namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
@@ -11,22 +18,41 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
public sealed class GasAnalyzerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly AtmosphereSystem _atmo = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GasAnalyzerComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<GasAnalyzerComponent, GasAnalyzerDisableMessage>(OnDisabledMessage);
|
||||
SubscribeLocalEvent<GasAnalyzerComponent, DroppedEvent>(OnDropped);
|
||||
SubscribeLocalEvent<GasAnalyzerComponent, UseInHandEvent>(OnUseInHand);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var analyzer in EntityManager.EntityQuery<GasAnalyzerComponent>(true))
|
||||
|
||||
foreach (var analyzer in EntityQuery<ActiveGasAnalyzerComponent>())
|
||||
{
|
||||
analyzer.Update(frameTime);
|
||||
// Don't update every tick
|
||||
analyzer.AccumulatedFrametime += frameTime;
|
||||
|
||||
if (analyzer.AccumulatedFrametime < analyzer.UpdateInterval)
|
||||
continue;
|
||||
|
||||
analyzer.AccumulatedFrametime -= analyzer.UpdateInterval;
|
||||
|
||||
if (!UpdateAnalyzer(analyzer.Owner))
|
||||
RemCompDeferred<ActiveGasAnalyzerComponent>(analyzer.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates the analyzer when used in the world, scanning either the target entity or the tile clicked
|
||||
/// </summary>
|
||||
private void OnAfterInteract(EntityUid uid, GasAnalyzerComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (!args.CanReach)
|
||||
@@ -34,13 +60,207 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
_popup.PopupEntity(Loc.GetString("gas-analyzer-component-player-cannot-reach-message"), args.User, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
ActivateAnalyzer(uid, component, args.User, args.Target);
|
||||
OpenUserInterface(args.User, component);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
if (TryComp(args.User, out ActorComponent? actor))
|
||||
/// <summary>
|
||||
/// Activates the analyzer with no target, so it only scans the tile the user was on when activated
|
||||
/// </summary>
|
||||
private void OnUseInHand(EntityUid uid, GasAnalyzerComponent component, UseInHandEvent args)
|
||||
{
|
||||
ActivateAnalyzer(uid, component, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles analyzer activation logic
|
||||
/// </summary>
|
||||
private void ActivateAnalyzer(EntityUid uid, GasAnalyzerComponent component, EntityUid user, EntityUid? target = null)
|
||||
{
|
||||
component.Target = target;
|
||||
component.User = user;
|
||||
component.LastPosition = Transform(target ?? user).Coordinates;
|
||||
component.Enabled = true;
|
||||
Dirty(component);
|
||||
UpdateAppearance(component);
|
||||
if(!HasComp<ActiveGasAnalyzerComponent>(uid))
|
||||
AddComp<ActiveGasAnalyzerComponent>(uid);
|
||||
UpdateAnalyzer(uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close the UI, turn the analyzer off, and don't update when it's dropped
|
||||
/// </summary>
|
||||
private void OnDropped(EntityUid uid, GasAnalyzerComponent component, DroppedEvent args)
|
||||
{
|
||||
if(args.User is { } userId && component.Enabled)
|
||||
_popup.PopupEntity(Loc.GetString("gas-analyzer-shutoff"), userId, Filter.Entities(userId));
|
||||
DisableAnalyzer(uid, component, args.User);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the UI, sets the icon to off, and removes it from the update list
|
||||
/// </summary>
|
||||
private void DisableAnalyzer(EntityUid uid, GasAnalyzerComponent? component = null, EntityUid? user = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
if (user != null && TryComp<ActorComponent>(user, out var actor))
|
||||
_userInterface.TryClose(uid, GasAnalyzerUiKey.Key, actor.PlayerSession);
|
||||
|
||||
component.Enabled = false;
|
||||
Dirty(component);
|
||||
UpdateAppearance(component);
|
||||
RemCompDeferred<ActiveGasAnalyzerComponent>(uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the analyzer when the user closes the UI
|
||||
/// </summary>
|
||||
private void OnDisabledMessage(EntityUid uid, GasAnalyzerComponent component, GasAnalyzerDisableMessage message)
|
||||
{
|
||||
if (message.Session.AttachedEntity is not {Valid: true})
|
||||
return;
|
||||
DisableAnalyzer(uid, component);
|
||||
}
|
||||
|
||||
private void OpenUserInterface(EntityUid user, GasAnalyzerComponent component)
|
||||
{
|
||||
if (!TryComp<ActorComponent>(user, out var actor))
|
||||
return;
|
||||
|
||||
_userInterface.TryOpen(component.Owner, GasAnalyzerUiKey.Key, actor.PlayerSession);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches fresh data for the analyzer. Should only be called by Update or when the user requests an update via refresh button
|
||||
/// </summary>
|
||||
private bool UpdateAnalyzer(EntityUid uid, GasAnalyzerComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return false;
|
||||
|
||||
// check if the user has walked away from what they scanned
|
||||
var userPos = Transform(component.User).Coordinates;
|
||||
if (component.LastPosition.HasValue)
|
||||
{
|
||||
component.OpenInterface(actor.PlayerSession, args.ClickLocation);
|
||||
// Check if position is out of range => don't update and disable
|
||||
if (!component.LastPosition.Value.InRange(EntityManager, userPos, SharedInteractionSystem.InteractionRange))
|
||||
{
|
||||
if(component.User is { } userId && component.Enabled)
|
||||
_popup.PopupEntity(Loc.GetString("gas-analyzer-shutoff"), userId, Filter.Entities(userId));
|
||||
DisableAnalyzer(uid, component, component.User);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
var gasMixList = new List<GasMixEntry>();
|
||||
|
||||
// Fetch the environmental atmosphere around the scanner. This must be the first entry
|
||||
var tileMixture = _atmo.GetContainingMixture(component.Owner, true);
|
||||
if (tileMixture != null)
|
||||
{
|
||||
gasMixList.Add(new GasMixEntry(Loc.GetString("gas-analyzer-window-environment-tab-label"), tileMixture.Pressure, tileMixture.Temperature,
|
||||
GenerateGasEntryArray(tileMixture)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// No gases were found
|
||||
gasMixList.Add(new GasMixEntry(Loc.GetString("gas-analyzer-window-environment-tab-label"), 0f, 0f));
|
||||
}
|
||||
|
||||
var deviceFlipped = false;
|
||||
if (component.Target != null)
|
||||
{
|
||||
// gas analyzed was used on an entity, try to request gas data via event for override
|
||||
var ev = new GasAnalyzerScanEvent();
|
||||
RaiseLocalEvent(component.Target.Value, ev, false);
|
||||
|
||||
if (ev.GasMixtures != null)
|
||||
{
|
||||
foreach (var mixes in ev.GasMixtures)
|
||||
{
|
||||
if(mixes.Value != null)
|
||||
gasMixList.Add(new GasMixEntry(mixes.Key, mixes.Value.Pressure, mixes.Value.Temperature, GenerateGasEntryArray(mixes.Value)));
|
||||
}
|
||||
|
||||
deviceFlipped = ev.DeviceFlipped;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No override, fetch manually, to handle flippable devices you must subscribe to GasAnalyzerScanEvent
|
||||
if (TryComp(component.Target, out NodeContainerComponent? node))
|
||||
{
|
||||
foreach (var pair in node.Nodes)
|
||||
{
|
||||
if (pair.Value is PipeNode pipeNode)
|
||||
gasMixList.Add(new GasMixEntry(pair.Key, pipeNode.Air.Pressure, pipeNode.Air.Temperature, GenerateGasEntryArray(pipeNode.Air)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't bother sending a UI message with no content, and stop updating I guess?
|
||||
if (gasMixList.Count == 0)
|
||||
return false;
|
||||
|
||||
_userInterface.TrySendUiMessage(component.Owner, GasAnalyzerUiKey.Key,
|
||||
new GasAnalyzerUserMessage(gasMixList.ToArray(),
|
||||
component.Target != null ? Name(component.Target.Value) : string.Empty,
|
||||
component.Target ?? EntityUid.Invalid,
|
||||
deviceFlipped));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the appearance based on the analyzers Enabled state
|
||||
/// </summary>
|
||||
private void UpdateAppearance(GasAnalyzerComponent analyzer)
|
||||
{
|
||||
_appearance.SetData(analyzer.Owner, GasAnalyzerVisuals.Enabled, analyzer.Enabled);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a GasEntry array for a given GasMixture
|
||||
/// </summary>
|
||||
private GasEntry[] GenerateGasEntryArray(GasMixture? mixture)
|
||||
{
|
||||
var gases = new List<GasEntry>();
|
||||
|
||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
||||
{
|
||||
var gas = _atmo.GetGas(i);
|
||||
|
||||
if (mixture?.Moles[i] <= Atmospherics.GasMinMoles)
|
||||
continue;
|
||||
|
||||
if (mixture != null)
|
||||
gases.Add(new GasEntry(gas.Name, mixture.Moles[i], gas.Color));
|
||||
}
|
||||
|
||||
return gases.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the analyzer is used. An atmospherics device that does not rely on a NodeContainer or
|
||||
/// wishes to override the default analyzer behaviour of fetching all nodes in the attached NodeContainer
|
||||
/// should subscribe to this and return the GasMixtures as desired. A device that is flippable should subscribe
|
||||
/// to this event to report if it is flipped or not. See GasFilterSystem or GasMixerSystem for an example.
|
||||
/// </summary>
|
||||
public sealed class GasAnalyzerScanEvent : EntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Key is the mix name (ex "pipe", "inlet", "filter"), value is the pipe direction and GasMixture. Add all mixes that should be reported when scanned.
|
||||
/// </summary>
|
||||
public Dictionary<string, GasMixture?>? GasMixtures;
|
||||
|
||||
/// <summary>
|
||||
/// If the device is flipped. Flipped is defined as when the inline input is 90 degrees CW to the side input
|
||||
/// </summary>
|
||||
public bool DeviceFlipped;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
SubscribeLocalEvent<GasTankComponent, EntParentChangedMessage>(OnParentChange);
|
||||
SubscribeLocalEvent<GasTankComponent, GasTankSetPressureMessage>(OnGasTankSetPressure);
|
||||
SubscribeLocalEvent<GasTankComponent, GasTankToggleInternalsMessage>(OnGasTankToggleInternals);
|
||||
SubscribeLocalEvent<GasTankComponent, GasAnalyzerScanEvent>(OnAnalyzed);
|
||||
}
|
||||
|
||||
private void OnGasShutdown(EntityUid uid, GasTankComponent component, ComponentShutdown args)
|
||||
@@ -87,7 +88,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
// When an item is moved from hands -> pockets, the container removal briefly dumps the item on the floor.
|
||||
// So this is a shitty fix, where the parent check is just delayed. But this really needs to get fixed
|
||||
// properly at some point.
|
||||
// properly at some point.
|
||||
component.CheckUser = true;
|
||||
}
|
||||
|
||||
@@ -323,5 +324,13 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
return GetInternalsComponent(component) != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the gas mixture for the gas analyzer
|
||||
/// </summary>
|
||||
private void OnAnalyzed(EntityUid uid, GasTankComponent component, GasAnalyzerScanEvent args)
|
||||
{
|
||||
args.GasMixtures = new Dictionary<string, GasMixture?> { {Name(uid), component.Air} };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
|
||||
SubscribeLocalEvent<GasFilterComponent, AtmosDeviceUpdateEvent>(OnFilterUpdated);
|
||||
SubscribeLocalEvent<GasFilterComponent, AtmosDeviceDisabledEvent>(OnFilterLeaveAtmosphere);
|
||||
SubscribeLocalEvent<GasFilterComponent, InteractHandEvent>(OnFilterInteractHand);
|
||||
SubscribeLocalEvent<GasFilterComponent, GasAnalyzerScanEvent>(OnFilterAnalyzed);
|
||||
// Bound UI subscriptions
|
||||
SubscribeLocalEvent<GasFilterComponent, GasFilterChangeRateMessage>(OnTransferRateChangeMessage);
|
||||
SubscribeLocalEvent<GasFilterComponent, GasFilterSelectGasMessage>(OnSelectGasMessage);
|
||||
@@ -159,5 +160,29 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the gas mixture for the gas analyzer
|
||||
/// </summary>
|
||||
private void OnFilterAnalyzed(EntityUid uid, GasFilterComponent component, GasAnalyzerScanEvent args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
|
||||
return;
|
||||
|
||||
var gasMixDict = new Dictionary<string, GasMixture?>();
|
||||
|
||||
nodeContainer.TryGetNode(component.InletName, out PipeNode? inlet);
|
||||
nodeContainer.TryGetNode(component.FilterName, out PipeNode? filterNode);
|
||||
|
||||
if(inlet != null)
|
||||
gasMixDict.Add(Loc.GetString("gas-analyzer-window-text-inlet"), inlet.Air);
|
||||
if(filterNode != null)
|
||||
gasMixDict.Add(Loc.GetString("gas-analyzer-window-text-filter"), filterNode.Air);
|
||||
if(nodeContainer.TryGetNode(component.OutletName, out PipeNode? outlet))
|
||||
gasMixDict.Add(Loc.GetString("gas-analyzer-window-text-outlet"), outlet.Air);
|
||||
|
||||
args.GasMixtures = gasMixDict;
|
||||
args.DeviceFlipped = inlet != null && filterNode != null && inlet.CurrentPipeDirection.ToDirection() == filterNode.CurrentPipeDirection.ToDirection().GetClockwise90Degrees();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
|
||||
SubscribeLocalEvent<GasMixerComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<GasMixerComponent, AtmosDeviceUpdateEvent>(OnMixerUpdated);
|
||||
SubscribeLocalEvent<GasMixerComponent, InteractHandEvent>(OnMixerInteractHand);
|
||||
SubscribeLocalEvent<GasMixerComponent, GasAnalyzerScanEvent>(OnMixerAnalyzed);
|
||||
// Bound UI subscriptions
|
||||
SubscribeLocalEvent<GasMixerComponent, GasMixerChangeOutputPressureMessage>(OnOutputPressureChangeMessage);
|
||||
SubscribeLocalEvent<GasMixerComponent, GasMixerChangeNodePercentageMessage>(OnChangeNodePercentageMessage);
|
||||
@@ -203,5 +204,29 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
|
||||
$"{EntityManager.ToPrettyString(args.Session.AttachedEntity!.Value):player} set the ratio on {EntityManager.ToPrettyString(uid):device} to {mixer.InletOneConcentration}:{mixer.InletTwoConcentration}");
|
||||
DirtyUI(uid, mixer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the gas mixture for the gas analyzer
|
||||
/// </summary>
|
||||
private void OnMixerAnalyzed(EntityUid uid, GasMixerComponent component, GasAnalyzerScanEvent args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
|
||||
return;
|
||||
|
||||
var gasMixDict = new Dictionary<string, GasMixture?>();
|
||||
|
||||
nodeContainer.TryGetNode(component.InletOneName, out PipeNode? inletOne);
|
||||
nodeContainer.TryGetNode(component.InletTwoName, out PipeNode? inletTwo);
|
||||
|
||||
if(inletOne != null)
|
||||
gasMixDict.Add($"{inletOne.CurrentPipeDirection} {Loc.GetString("gas-analyzer-window-text-inlet")}", inletOne.Air);
|
||||
if(inletTwo != null)
|
||||
gasMixDict.Add($"{inletTwo.CurrentPipeDirection} {Loc.GetString("gas-analyzer-window-text-inlet")}", inletTwo.Air);
|
||||
if(nodeContainer.TryGetNode(component.OutletName, out PipeNode? outlet))
|
||||
gasMixDict.Add(Loc.GetString("gas-analyzer-window-text-outlet"), outlet.Air);
|
||||
|
||||
args.GasMixtures = gasMixDict;
|
||||
args.DeviceFlipped = inletOne != null && inletTwo != null && inletOne.CurrentPipeDirection.ToDirection() == inletTwo.CurrentPipeDirection.ToDirection().GetClockwise90Degrees();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
SubscribeLocalEvent<GasCanisterComponent, EntInsertedIntoContainerMessage>(OnCanisterContainerInserted);
|
||||
SubscribeLocalEvent<GasCanisterComponent, EntRemovedFromContainerMessage>(OnCanisterContainerRemoved);
|
||||
SubscribeLocalEvent<GasCanisterComponent, PriceCalculationEvent>(CalculateCanisterPrice);
|
||||
SubscribeLocalEvent<GasCanisterComponent, GasAnalyzerScanEvent>(OnAnalyzed);
|
||||
// Bound UI subscriptions
|
||||
SubscribeLocalEvent<GasCanisterComponent, GasCanisterHoldingTankEjectMessage>(OnHoldingTankEjectMessage);
|
||||
SubscribeLocalEvent<GasCanisterComponent, GasCanisterChangeReleasePressureMessage>(OnCanisterChangeReleasePressure);
|
||||
@@ -314,5 +315,13 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
}
|
||||
args.Price += basePrice * purity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the gas mixture for the gas analyzer
|
||||
/// </summary>
|
||||
private void OnAnalyzed(EntityUid uid, GasCanisterComponent component, GasAnalyzerScanEvent args)
|
||||
{
|
||||
args.GasMixtures = new Dictionary<string, GasMixture?> { {Name(uid), component.Air} };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
|
||||
private void OnGasThermoRefreshParts(EntityUid uid, GasThermoMachineComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
// Here we evaluate the average quality of relevant machine parts.
|
||||
// Here we evaluate the average quality of relevant machine parts.
|
||||
var nLasers = 0;
|
||||
var nBins= 0;
|
||||
var matterBinRating = 0;
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
SubscribeLocalEvent<GasVentPumpComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, ExaminedEvent>(OnExamine);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, SignalReceivedEvent>(OnSignalReceived);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, GasAnalyzerScanEvent>(OnAnalyzed);
|
||||
}
|
||||
|
||||
private void OnGasVentPumpUpdated(EntityUid uid, GasVentPumpComponent vent, AtmosDeviceUpdateEvent args)
|
||||
@@ -271,5 +272,28 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the gas mixture for the gas analyzer
|
||||
/// </summary>
|
||||
private void OnAnalyzed(EntityUid uid, GasVentPumpComponent component, GasAnalyzerScanEvent args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
|
||||
return;
|
||||
|
||||
var gasMixDict = new Dictionary<string, GasMixture?>();
|
||||
|
||||
// these are both called pipe, above it switches using this so I duplicated that...?
|
||||
var nodeName = component.PumpDirection switch
|
||||
{
|
||||
VentPumpDirection.Releasing => component.Inlet,
|
||||
VentPumpDirection.Siphoning => component.Outlet,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
if(nodeContainer.TryGetNode(nodeName, out PipeNode? pipe))
|
||||
gasMixDict.Add(nodeName, pipe.Air);
|
||||
|
||||
args.GasMixtures = gasMixDict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Content.Server.Atmos.Portable
|
||||
SubscribeLocalEvent<PortableScrubberComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<PortableScrubberComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<PortableScrubberComponent, DestructionEventArgs>(OnDestroyed);
|
||||
SubscribeLocalEvent<PortableScrubberComponent, GasAnalyzerScanEvent>(OnScrubberAnalyzed);
|
||||
}
|
||||
|
||||
private void OnDeviceUpdated(EntityUid uid, PortableScrubberComponent component, AtmosDeviceUpdateEvent args)
|
||||
@@ -158,5 +159,21 @@ namespace Content.Server.Atmos.Portable
|
||||
|
||||
appearance.SetData(PortableScrubberVisuals.IsDraining, isDraining);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the gas mixture for the gas analyzer
|
||||
/// </summary>
|
||||
private void OnScrubberAnalyzed(EntityUid uid, PortableScrubberComponent component, GasAnalyzerScanEvent args)
|
||||
{
|
||||
var gasMixDict = new Dictionary<string, GasMixture?>();
|
||||
// If it's connected to a port, include the port side
|
||||
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
|
||||
{
|
||||
if(nodeContainer != null && nodeContainer.TryGetNode(component.PortName, out PipeNode? port))
|
||||
gasMixDict.Add(component.PortName, port.Air);
|
||||
}
|
||||
gasMixDict.Add(Name(uid), component.Air);
|
||||
args.GasMixtures = gasMixDict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,12 @@ namespace Content.Server.UserInterface
|
||||
[DataField("allowSpectator")]
|
||||
public bool AllowSpectator = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the UI should close when the item is deselected due to a hand swap or drop
|
||||
/// </summary>
|
||||
[DataField("closeOnHandDeselect")]
|
||||
public bool CloseOnHandDeselect = true;
|
||||
|
||||
/// <summary>
|
||||
/// The client channel currently using the object, or null if there's none/not single user.
|
||||
/// NOTE: DO NOT DIRECTLY SET, USE ActivatableUISystem.SetCurrentSingleUser
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Content.Server.UserInterface
|
||||
|
||||
SubscribeLocalEvent<ActivatableUIComponent, ActivateInWorldEvent>(OnActivate);
|
||||
SubscribeLocalEvent<ActivatableUIComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<ActivatableUIComponent, HandDeselectedEvent>((uid, aui, _) => CloseAll(uid, aui));
|
||||
SubscribeLocalEvent<ActivatableUIComponent, HandDeselectedEvent>(OnHandDeselected);
|
||||
SubscribeLocalEvent<ActivatableUIComponent, GotUnequippedHandEvent>((uid, aui, _) => CloseAll(uid, aui));
|
||||
// *THIS IS A BLATANT WORKAROUND!* RATIONALE: Microwaves need it
|
||||
SubscribeLocalEvent<ActivatableUIComponent, EntParentChangedMessage>(OnParentChanged);
|
||||
@@ -169,6 +169,14 @@ namespace Content.Server.UserInterface
|
||||
if (!Resolve(uid, ref aui, false)) return;
|
||||
aui.UserInterface?.CloseAll();
|
||||
}
|
||||
|
||||
private void OnHandDeselected(EntityUid uid, ActivatableUIComponent? aui, HandDeselectedEvent args)
|
||||
{
|
||||
if (!Resolve(uid, ref aui, false)) return;
|
||||
if (!aui.CloseOnHandDeselect)
|
||||
return;
|
||||
CloseAll(uid, aui);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ActivatableUIOpenAttemptEvent : CancellableEntityEventArgs
|
||||
|
||||
Reference in New Issue
Block a user