Gas analyzer compref removal (#17992)

* Gas analyzer compref removal

* don't question it
This commit is contained in:
Nemanja
2023-07-12 15:47:45 -04:00
committed by GitHub
parent 65d069a203
commit 37e6d99e49
7 changed files with 151 additions and 164 deletions

View File

@@ -1,9 +0,0 @@
using Content.Shared.Atmos.Components;
namespace Content.Client.Atmos.Components
{
[RegisterComponent]
internal sealed class GasAnalyzerComponent : SharedGasAnalyzerComponent
{
}
}

View File

@@ -1,5 +1,5 @@
using Robust.Client.GameObjects;
using static Content.Shared.Atmos.Components.SharedGasAnalyzerComponent;
using static Content.Shared.Atmos.Components.GasAnalyzerComponent;
namespace Content.Client.Atmos.UI
{
@@ -16,7 +16,7 @@ namespace Content.Client.Atmos.UI
{
base.Open();
_window = new GasAnalyzerWindow(this);
_window = new GasAnalyzerWindow();
_window.OnClose += OnClose;
_window.OpenCentered();
}

View File

@@ -7,23 +7,17 @@ using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.XAML;
using static Content.Shared.Atmos.Components.SharedGasAnalyzerComponent;
using static Content.Shared.Atmos.Components.GasAnalyzerComponent;
namespace Content.Client.Atmos.UI
{
[GenerateTypedNameReferences]
public sealed partial class GasAnalyzerWindow : DefaultWindow
{
private GasAnalyzerBoundUserInterface _owner;
private IEntityManager _entityManager;
public GasAnalyzerWindow(GasAnalyzerBoundUserInterface owner)
public GasAnalyzerWindow()
{
RobustXamlLoader.Load(this);
_entityManager = IoCManager.Resolve<IEntityManager>();
_owner = owner;
}
public void Populate(GasAnalyzerUserMessage msg)
@@ -74,7 +68,7 @@ namespace Content.Client.Atmos.UI
_ => GridIcon.OverrideDirection
};
GridIcon.Sprite = _entityManager.GetComponent<SpriteComponent>(msg.DeviceUid);
GridIcon.SetEntity(msg.DeviceUid);
LeftPanel.RemoveAllChildren();
MiddlePanel.RemoveAllChildren();
RightPanel.RemoveAllChildren();
@@ -262,10 +256,9 @@ namespace Content.Client.Atmos.UI
});
// This is the gas bar thingy
var height = 30;
var minSize = 24; // This basically allows gases which are too small, to be shown properly
var gasBar = new SplitBar()
var gasBar = new SplitBar
{
MinHeight = height
MinHeight = height,
};
// Separator
dataContainer.AddChild(new Control

View File

@@ -1,17 +1,4 @@
using Content.Shared.Atmos.Components;
using Robust.Shared.Map;
namespace Content.Server.Atmos.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedGasAnalyzerComponent))]
public sealed class GasAnalyzerComponent : SharedGasAnalyzerComponent
{
[ViewVariables] public EntityUid? Target;
[ViewVariables] public EntityUid User;
[ViewVariables] public EntityCoordinates? LastPosition;
[ViewVariables] public bool Enabled;
}
namespace Content.Server.Atmos.Components;
/// <summary>
/// Used to keep track of which analyzers are active for update purposes
@@ -20,11 +7,12 @@ namespace Content.Server.Atmos.Components
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
[DataField("accumulatedFrameTime"), ViewVariables(VVAccess.ReadWrite)]
public float AccumulatedFrametime = 2.01f;
/// <summary>
/// How often to update the analyzer
/// </summary>
[DataField("updateInterval"), ViewVariables(VVAccess.ReadWrite)]
public float UpdateInterval = 1f;
}
}

View File

@@ -9,8 +9,7 @@ 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;
using static Content.Shared.Atmos.Components.GasAnalyzerComponent;
namespace Content.Server.Atmos.EntitySystems
{
@@ -21,6 +20,7 @@ namespace Content.Server.Atmos.EntitySystems
[Dependency] private readonly AtmosphereSystem _atmo = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
[Dependency] private readonly TransformSystem _transform = default!;
public override void Initialize()
{
@@ -34,8 +34,8 @@ namespace Content.Server.Atmos.EntitySystems
public override void Update(float frameTime)
{
foreach (var analyzer in EntityQuery<ActiveGasAnalyzerComponent>())
var query = EntityQueryEnumerator<ActiveGasAnalyzerComponent>();
while (query.MoveNext(out var uid, out var analyzer))
{
// Don't update every tick
analyzer.AccumulatedFrametime += frameTime;
@@ -45,8 +45,8 @@ namespace Content.Server.Atmos.EntitySystems
analyzer.AccumulatedFrametime -= analyzer.UpdateInterval;
if (!UpdateAnalyzer(analyzer.Owner))
RemCompDeferred<ActiveGasAnalyzerComponent>(analyzer.Owner);
if (!UpdateAnalyzer(uid))
RemCompDeferred<ActiveGasAnalyzerComponent>(uid);
}
}
@@ -61,7 +61,7 @@ namespace Content.Server.Atmos.EntitySystems
return;
}
ActivateAnalyzer(uid, component, args.User, args.Target);
OpenUserInterface(args.User, component);
OpenUserInterface(uid, args.User, component);
args.Handled = true;
}
@@ -87,7 +87,7 @@ namespace Content.Server.Atmos.EntitySystems
component.LastPosition = null;
component.Enabled = true;
Dirty(component);
UpdateAppearance(component);
UpdateAppearance(uid, component);
if(!HasComp<ActiveGasAnalyzerComponent>(uid))
AddComp<ActiveGasAnalyzerComponent>(uid);
UpdateAnalyzer(uid, component);
@@ -98,7 +98,7 @@ namespace Content.Server.Atmos.EntitySystems
/// </summary>
private void OnDropped(EntityUid uid, GasAnalyzerComponent component, DroppedEvent args)
{
if(args.User is { } userId && component.Enabled)
if(args.User is var userId && component.Enabled)
_popup.PopupEntity(Loc.GetString("gas-analyzer-shutoff"), userId, userId);
DisableAnalyzer(uid, component, args.User);
}
@@ -116,7 +116,7 @@ namespace Content.Server.Atmos.EntitySystems
component.Enabled = false;
Dirty(component);
UpdateAppearance(component);
UpdateAppearance(uid, component);
RemCompDeferred<ActiveGasAnalyzerComponent>(uid);
}
@@ -130,12 +130,15 @@ namespace Content.Server.Atmos.EntitySystems
DisableAnalyzer(uid, component);
}
private void OpenUserInterface(EntityUid user, GasAnalyzerComponent component)
private void OpenUserInterface(EntityUid uid, EntityUid user, GasAnalyzerComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
if (!TryComp<ActorComponent>(user, out var actor))
return;
_userInterface.TryOpen(component.Owner, GasAnalyzerUiKey.Key, actor.PlayerSession);
_userInterface.TryOpen(uid, GasAnalyzerUiKey.Key, actor.PlayerSession);
}
/// <summary>
@@ -157,7 +160,7 @@ namespace Content.Server.Atmos.EntitySystems
if (component.LastPosition.HasValue)
{
// Check if position is out of range => don't update and disable
if (!component.LastPosition.Value.InRange(EntityManager, userPos, SharedInteractionSystem.InteractionRange))
if (!component.LastPosition.Value.InRange(EntityManager, _transform, userPos, SharedInteractionSystem.InteractionRange))
{
if(component.User is { } userId && component.Enabled)
_popup.PopupEntity(Loc.GetString("gas-analyzer-shutoff"), userId, userId);
@@ -169,7 +172,7 @@ namespace Content.Server.Atmos.EntitySystems
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);
var tileMixture = _atmo.GetContainingMixture(uid, true);
if (tileMixture != null)
{
gasMixList.Add(new GasMixEntry(Loc.GetString("gas-analyzer-window-environment-tab-label"), tileMixture.Pressure, tileMixture.Temperature,
@@ -193,7 +196,7 @@ namespace Content.Server.Atmos.EntitySystems
// 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);
RaiseLocalEvent(component.Target.Value, ev);
if (ev.GasMixtures != null)
{
@@ -223,7 +226,7 @@ namespace Content.Server.Atmos.EntitySystems
if (gasMixList.Count == 0)
return false;
_userInterface.TrySendUiMessage(component.Owner, GasAnalyzerUiKey.Key,
_userInterface.TrySendUiMessage(uid, GasAnalyzerUiKey.Key,
new GasAnalyzerUserMessage(gasMixList.ToArray(),
component.Target != null ? Name(component.Target.Value) : string.Empty,
component.Target ?? EntityUid.Invalid,
@@ -234,9 +237,9 @@ namespace Content.Server.Atmos.EntitySystems
/// <summary>
/// Sets the appearance based on the analyzers Enabled state
/// </summary>
private void UpdateAppearance(GasAnalyzerComponent analyzer)
private void UpdateAppearance(EntityUid uid, GasAnalyzerComponent analyzer)
{
_appearance.SetData(analyzer.Owner, GasAnalyzerVisuals.Enabled, analyzer.Enabled);
_appearance.SetData(uid, GasAnalyzerVisuals.Enabled, analyzer.Enabled);
}
/// <summary>

View File

@@ -0,0 +1,111 @@
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Components;
[RegisterComponent, NetworkedComponent]
public sealed class GasAnalyzerComponent : Component
{
[ViewVariables]
public EntityUid? Target;
[ViewVariables]
public EntityUid User;
[ViewVariables(VVAccess.ReadWrite)]
public EntityCoordinates? LastPosition;
[DataField("enabled"), ViewVariables(VVAccess.ReadWrite)]
public bool Enabled;
[Serializable, NetSerializable]
public enum GasAnalyzerUiKey
{
Key,
}
/// <summary>
/// Atmospheric data is gathered in the system and sent to the user
/// </summary>
[Serializable, NetSerializable]
public sealed class GasAnalyzerUserMessage : BoundUserInterfaceMessage
{
public string DeviceName;
public EntityUid DeviceUid;
public bool DeviceFlipped;
public string? Error;
public GasMixEntry[] NodeGasMixes;
public GasAnalyzerUserMessage(GasMixEntry[] nodeGasMixes, string deviceName, EntityUid deviceUid, bool deviceFlipped, string? error = null)
{
NodeGasMixes = nodeGasMixes;
DeviceName = deviceName;
DeviceUid = deviceUid;
DeviceFlipped = deviceFlipped;
Error = error;
}
}
/// <summary>
/// Contains information on a gas mix entry, turns into a tab in the UI
/// </summary>
[Serializable, NetSerializable]
public struct GasMixEntry
{
/// <summary>
/// Name of the tab in the UI
/// </summary>
public readonly string Name;
public readonly float Pressure;
public readonly float Temperature;
public readonly GasEntry[]? Gases;
public GasMixEntry(string name, float pressure, float temperature, GasEntry[]? gases = null)
{
Name = name;
Pressure = pressure;
Temperature = temperature;
Gases = gases;
}
}
/// <summary>
/// Individual gas entry data for populating the UI
/// </summary>
[Serializable, NetSerializable]
public struct GasEntry
{
public readonly string Name;
public readonly float Amount;
public readonly string Color;
public GasEntry(string name, float amount, string color)
{
Name = name;
Amount = amount;
Color = color;
}
public override string ToString()
{
// e.g. "Plasma: 2000 mol"
return Loc.GetString(
"gas-entry-info",
("gasName", Name),
("gasAmount", Amount));
}
}
[Serializable, NetSerializable]
public sealed class GasAnalyzerDisableMessage : BoundUserInterfaceMessage
{
}
}
[Serializable, NetSerializable]
public enum GasAnalyzerVisuals : byte
{
Enabled,
}

View File

@@ -1,99 +0,0 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Components
{
[NetworkedComponent()]
public abstract class SharedGasAnalyzerComponent : Component
{
[Serializable, NetSerializable]
public enum GasAnalyzerUiKey
{
Key,
}
/// <summary>
/// Atmospheric data is gathered in the system and sent to the user
/// </summary>
[Serializable, NetSerializable]
public sealed class GasAnalyzerUserMessage : BoundUserInterfaceMessage
{
public string DeviceName;
public EntityUid DeviceUid;
public bool DeviceFlipped;
public string? Error;
public GasMixEntry[] NodeGasMixes;
public GasAnalyzerUserMessage(GasMixEntry[] nodeGasMixes, string deviceName, EntityUid deviceUid, bool deviceFlipped, string? error = null)
{
NodeGasMixes = nodeGasMixes;
DeviceName = deviceName;
DeviceUid = deviceUid;
DeviceFlipped = deviceFlipped;
Error = error;
}
}
/// <summary>
/// Contains information on a gas mix entry, turns into a tab in the UI
/// </summary>
[Serializable, NetSerializable]
public struct GasMixEntry
{
/// <summary>
/// Name of the tab in the UI
/// </summary>
public readonly string Name;
public readonly float Pressure;
public readonly float Temperature;
public readonly GasEntry[]? Gases;
public GasMixEntry(string name, float pressure, float temperature, GasEntry[]? gases = null)
{
Name = name;
Pressure = pressure;
Temperature = temperature;
Gases = gases;
}
}
/// <summary>
/// Individual gas entry data for populating the UI
/// </summary>
[Serializable, NetSerializable]
public struct GasEntry
{
public readonly string Name;
public readonly float Amount;
public readonly string Color;
public GasEntry(string name, float amount, string color)
{
Name = name;
Amount = amount;
Color = color;
}
public override string ToString()
{
// e.g. "Plasma: 2000 mol"
return Loc.GetString(
"gas-entry-info",
("gasName", Name),
("gasAmount", Amount));
}
}
[Serializable, NetSerializable]
public sealed class GasAnalyzerDisableMessage : BoundUserInterfaceMessage
{
public GasAnalyzerDisableMessage() {}
}
}
[Serializable, NetSerializable]
public enum GasAnalyzerVisuals : byte
{
Enabled,
}
}