Skip to content

Commit

Permalink
Merge pull request #2181 from space-syndicate/upstream-sync
Browse files Browse the repository at this point in the history
Upstream sync
  • Loading branch information
Morb0 authored May 29, 2024
2 parents a6864e7 + 93a9309 commit acea81f
Show file tree
Hide file tree
Showing 73 changed files with 5,206 additions and 4,646 deletions.
27 changes: 0 additions & 27 deletions Content.Client/Cabinet/ItemCabinetSystem.cs

This file was deleted.

112 changes: 75 additions & 37 deletions Content.Client/Popups/PopupSystem.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using System.Linq;
using Content.Shared.Containers;
using Content.Shared.Examine;
using Content.Shared.GameTicking;
using Content.Shared.Popups;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Shared.Collections;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Replays;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client.Popups
{
Expand All @@ -29,11 +31,11 @@ public sealed class PopupSystem : SharedPopupSystem
[Dependency] private readonly ExamineSystemShared _examine = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

public IReadOnlyList<WorldPopupLabel> WorldLabels => _aliveWorldLabels;
public IReadOnlyList<CursorPopupLabel> CursorLabels => _aliveCursorLabels;
public IReadOnlyCollection<WorldPopupLabel> WorldLabels => _aliveWorldLabels.Values;
public IReadOnlyCollection<CursorPopupLabel> CursorLabels => _aliveCursorLabels.Values;

private readonly List<WorldPopupLabel> _aliveWorldLabels = new();
private readonly List<CursorPopupLabel> _aliveCursorLabels = new();
private readonly Dictionary<WorldPopupData, WorldPopupLabel> _aliveWorldLabels = new();
private readonly Dictionary<CursorPopupData, CursorPopupLabel> _aliveCursorLabels = new();

public const float MinimumPopupLifetime = 0.7f;
public const float MaximumPopupLifetime = 5f;
Expand Down Expand Up @@ -65,6 +67,15 @@ public override void Shutdown()
.RemoveOverlay<PopupOverlay>();
}

private void WrapAndRepeatPopup(PopupLabel existingLabel, string popupMessage)
{
existingLabel.TotalTime = 0;
existingLabel.Repeats += 1;
existingLabel.Text = Loc.GetString("popup-system-repeated-popup-stacking-wrap",
("popup-message", popupMessage),
("count", existingLabel.Repeats));
}

private void PopupMessage(string? message, PopupType type, EntityCoordinates coordinates, EntityUid? entity, bool recordReplay)
{
if (message == null)
Expand All @@ -78,13 +89,20 @@ private void PopupMessage(string? message, PopupType type, EntityCoordinates coo
_replayRecording.RecordClientMessage(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)));
}

var popupData = new WorldPopupData(message, type, coordinates, entity);
if (_aliveWorldLabels.TryGetValue(popupData, out var existingLabel))
{
WrapAndRepeatPopup(existingLabel, popupData.Message);
return;
}

var label = new WorldPopupLabel(coordinates)
{
Text = message,
Type = type,
};

_aliveWorldLabels.Add(label);
_aliveWorldLabels.Add(popupData, label);
}

#region Abstract Method Implementations
Expand Down Expand Up @@ -113,13 +131,20 @@ private void PopupCursorInternal(string? message, PopupType type, bool recordRep
if (recordReplay && _replayRecording.IsRecording)
_replayRecording.RecordClientMessage(new PopupCursorEvent(message, type));

var popupData = new CursorPopupData(message, type);
if (_aliveCursorLabels.TryGetValue(popupData, out var existingLabel))
{
WrapAndRepeatPopup(existingLabel, popupData.Message);
return;
}

var label = new CursorPopupLabel(_inputManager.MouseScreenPosition)
{
Text = message,
Type = type,
};

_aliveCursorLabels.Add(label);
_aliveCursorLabels.Add(popupData, label);
}

public override void PopupCursor(string? message, PopupType type = PopupType.Small)
Expand Down Expand Up @@ -249,27 +274,37 @@ public override void FrameUpdate(float frameTime)
if (_aliveWorldLabels.Count == 0 && _aliveCursorLabels.Count == 0)
return;

for (var i = 0; i < _aliveWorldLabels.Count; i++)
if (_aliveWorldLabels.Count > 0)
{
var label = _aliveWorldLabels[i];
label.TotalTime += frameTime;

if (label.TotalTime > GetPopupLifetime(label) || Deleted(label.InitialPos.EntityId))
var aliveWorldToRemove = new ValueList<WorldPopupData>();
foreach (var (data, label) in _aliveWorldLabels)
{
label.TotalTime += frameTime;
if (label.TotalTime > GetPopupLifetime(label) || Deleted(label.InitialPos.EntityId))
{
aliveWorldToRemove.Add(data);
}
}
foreach (var data in aliveWorldToRemove)
{
_aliveWorldLabels.RemoveSwap(i);
i--;
_aliveWorldLabels.Remove(data);
}
}

for (var i = 0; i < _aliveCursorLabels.Count; i++)
if (_aliveCursorLabels.Count > 0)
{
var label = _aliveCursorLabels[i];
label.TotalTime += frameTime;

if (label.TotalTime > GetPopupLifetime(label))
var aliveCursorToRemove = new ValueList<CursorPopupData>();
foreach (var (data, label) in _aliveCursorLabels)
{
label.TotalTime += frameTime;
if (label.TotalTime > GetPopupLifetime(label))
{
aliveCursorToRemove.Add(data);
}
}
foreach (var data in aliveCursorToRemove)
{
_aliveCursorLabels.RemoveSwap(i);
i--;
_aliveCursorLabels.Remove(data);
}
}
}
Expand All @@ -279,29 +314,32 @@ public abstract class PopupLabel
public PopupType Type = PopupType.Small;
public string Text { get; set; } = string.Empty;
public float TotalTime { get; set; }
public int Repeats = 1;
}

public sealed class CursorPopupLabel : PopupLabel
{
public ScreenCoordinates InitialPos;

public CursorPopupLabel(ScreenCoordinates screenCoords)
{
InitialPos = screenCoords;
}
}

public sealed class WorldPopupLabel : PopupLabel
public sealed class WorldPopupLabel(EntityCoordinates coordinates) : PopupLabel
{
/// <summary>
/// The original EntityCoordinates of the label.
/// </summary>
public EntityCoordinates InitialPos;
public EntityCoordinates InitialPos = coordinates;
}

public WorldPopupLabel(EntityCoordinates coordinates)
{
InitialPos = coordinates;
}
public sealed class CursorPopupLabel(ScreenCoordinates screenCoords) : PopupLabel
{
public ScreenCoordinates InitialPos = screenCoords;
}

[UsedImplicitly]
private record struct WorldPopupData(
string Message,
PopupType Type,
EntityCoordinates Coordinates,
EntityUid? Entity);

[UsedImplicitly]
private record struct CursorPopupData(
string Message,
PopupType Type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override void Open()
_window.OpenCentered();
_window.OnNameConfirm += SendDeviceName;
_window.OnNetworkConfirm += SendSelectedNetwork;

_window.OnClose += Close;
}

private void SendSelectedNetwork(int idx)
Expand Down Expand Up @@ -63,7 +63,8 @@ protected override void Dispose(bool disposing)

if (disposing)
{
_window!.Dispose();
_window?.Dispose();
_window = null;
}
}
}
11 changes: 6 additions & 5 deletions Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ private void OnAfterInteract(EntityUid uid, GasAnalyzerComponent component, Afte
return;
}
ActivateAnalyzer(uid, component, args.User, args.Target);
OpenUserInterface(uid, args.User, component);
args.Handled = true;
}

Expand All @@ -86,6 +85,9 @@ private void OnUseInHand(EntityUid uid, GasAnalyzerComponent component, UseInHan
/// </summary>
private void ActivateAnalyzer(EntityUid uid, GasAnalyzerComponent component, EntityUid user, EntityUid? target = null)
{
if (!TryOpenUserInterface(uid, user, component))
return;

component.Target = target;
component.User = user;
if (target != null)
Expand All @@ -97,7 +99,6 @@ private void ActivateAnalyzer(EntityUid uid, GasAnalyzerComponent component, Ent
UpdateAppearance(uid, component);
EnsureComp<ActiveGasAnalyzerComponent>(uid);
UpdateAnalyzer(uid, component);
OpenUserInterface(uid, user, component);
}

/// <summary>
Expand Down Expand Up @@ -134,12 +135,12 @@ private void OnDisabledMessage(EntityUid uid, GasAnalyzerComponent component, Ga
DisableAnalyzer(uid, component);
}

private void OpenUserInterface(EntityUid uid, EntityUid user, GasAnalyzerComponent? component = null)
private bool TryOpenUserInterface(EntityUid uid, EntityUid user, GasAnalyzerComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
return false;

_userInterface.OpenUi(uid, GasAnalyzerUiKey.Key, user);
return _userInterface.TryOpenUi(uid, GasAnalyzerUiKey.Key, user);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public sealed partial class GasVentPumpComponent : Component
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("underPressureLockoutThreshold")]
public float UnderPressureLockoutThreshold = 2;
public float UnderPressureLockoutThreshold = 60; // this must be tuned in conjunction with atmos.mmos_spacing_speed

/// <summary>
/// Pressure locked vents still leak a little (leading to eventual pressurization of sealed sections)
Expand Down
12 changes: 10 additions & 2 deletions Content.Server/Body/Components/RespiratorComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Content.Server.Body.Systems;
using Content.Shared.Chat.Prototypes;
using Content.Shared.Damage;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Body.Components
Expand Down Expand Up @@ -50,10 +52,16 @@ public sealed partial class RespiratorComponent : Component
public DamageSpecifier DamageRecovery = default!;

[DataField]
public TimeSpan GaspPopupCooldown = TimeSpan.FromSeconds(8);
public TimeSpan GaspEmoteCooldown = TimeSpan.FromSeconds(8);

[ViewVariables]
public TimeSpan LastGaspPopupTime;
public TimeSpan LastGaspEmoteTime;

/// <summary>
/// The emote when gasps
/// </summary>
[DataField]
public ProtoId<EmotePrototype> GaspEmote = "Gasp";

/// <summary>
/// How many cycles in a row has the mob been under-saturated?
Expand Down
10 changes: 5 additions & 5 deletions Content.Server/Body/Systems/RespiratorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Components;
using Content.Server.Chat.Systems;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Popups;
using Content.Shared.Alert;
using Content.Shared.Atmos;
using Content.Shared.Body.Components;
Expand All @@ -25,9 +25,9 @@ public sealed class RespiratorSystem : EntitySystem
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly DamageableSystem _damageableSys = default!;
[Dependency] private readonly LungSystem _lungSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly ChatSystem _chat = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -84,10 +84,10 @@ public override void Update(float frameTime)

if (respirator.Saturation < respirator.SuffocationThreshold)
{
if (_gameTiming.CurTime >= respirator.LastGaspPopupTime + respirator.GaspPopupCooldown)
if (_gameTiming.CurTime >= respirator.LastGaspEmoteTime + respirator.GaspEmoteCooldown)
{
respirator.LastGaspPopupTime = _gameTiming.CurTime;
_popupSystem.PopupEntity(Loc.GetString("lung-behavior-gasp"), uid);
respirator.LastGaspEmoteTime = _gameTiming.CurTime;
_chat.TryEmoteWithChat(uid, respirator.GaspEmote, ignoreActionBlocker: true);
}

TakeSuffocationDamage((uid, respirator));
Expand Down
9 changes: 0 additions & 9 deletions Content.Server/Cabinet/ItemCabinetSystem.cs

This file was deleted.

Loading

0 comments on commit acea81f

Please sign in to comment.