From 4a347595143e777f5d0b67450dbe9088ce5fb7ac Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 10 Jun 2025 20:25:43 -0400 Subject: [PATCH] Replace Speech bubble time accumulator with TimeSpan (#38241) * Replace SpeechBubble time accumulator with TimeSpan * CurTime -> RealTime --- Content.Client/Chat/UI/SpeechBubble.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Content.Client/Chat/UI/SpeechBubble.cs b/Content.Client/Chat/UI/SpeechBubble.cs index 442368a3e6..0bfe6dc7c8 100644 --- a/Content.Client/Chat/UI/SpeechBubble.cs +++ b/Content.Client/Chat/UI/SpeechBubble.cs @@ -14,6 +14,7 @@ namespace Content.Client.Chat.UI { public abstract class SpeechBubble : Control { + [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IEyeManager _eyeManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] protected readonly IConfigurationManager ConfigManager = default!; @@ -30,12 +31,12 @@ namespace Content.Client.Chat.UI /// /// The total time a speech bubble stays on screen. /// - private const float TotalTime = 4; + private static readonly TimeSpan TotalTime = TimeSpan.FromSeconds(4); /// /// The amount of time at the end of the bubble's life at which it starts fading. /// - private const float FadeTime = 0.25f; + private static readonly TimeSpan FadeTime = TimeSpan.FromSeconds(0.25f); /// /// The distance in world space to offset the speech bubble from the center of the entity. @@ -50,7 +51,10 @@ namespace Content.Client.Chat.UI private readonly EntityUid _senderEntity; - private float _timeLeft = TotalTime; + /// + /// The time at which this bubble will die. + /// + private TimeSpan _deathTime; public float VerticalOffset { get; set; } private float _verticalOffsetAchieved; @@ -99,6 +103,7 @@ namespace Content.Client.Chat.UI bubble.Measure(Vector2Helpers.Infinity); ContentSize = bubble.DesiredSize; _verticalOffsetAchieved = -ContentSize.Y; + _deathTime = _timing.RealTime + TotalTime; } protected abstract Control BuildBubble(ChatMessage message, string speechStyleClass, Color? fontColor = null); @@ -107,8 +112,8 @@ namespace Content.Client.Chat.UI { base.FrameUpdate(args); - _timeLeft -= args.DeltaSeconds; - if (_entityManager.Deleted(_senderEntity) || _timeLeft <= 0) + var timeLeft = (float)(_deathTime - _timing.RealTime).TotalSeconds; + if (_entityManager.Deleted(_senderEntity) || timeLeft <= 0) { // Timer spawn to prevent concurrent modification exception. Timer.Spawn(0, Die); @@ -131,10 +136,10 @@ namespace Content.Client.Chat.UI return; } - if (_timeLeft <= FadeTime) + if (timeLeft <= FadeTime.TotalSeconds) { // Update alpha if we're fading. - Modulate = Color.White.WithAlpha(_timeLeft / FadeTime); + Modulate = Color.White.WithAlpha(timeLeft / (float)FadeTime.TotalSeconds); } else { @@ -144,7 +149,7 @@ namespace Content.Client.Chat.UI var baseOffset = 0f; - if (_entityManager.TryGetComponent(_senderEntity, out var speech)) + if (_entityManager.TryGetComponent(_senderEntity, out var speech)) baseOffset = speech.SpeechBubbleOffset; var offset = (-_eyeManager.CurrentEye.Rotation).ToWorldVec() * -(EntityVerticalOffset + baseOffset); @@ -175,9 +180,9 @@ namespace Content.Client.Chat.UI /// public void FadeNow() { - if (_timeLeft > FadeTime) + if (_deathTime > _timing.RealTime) { - _timeLeft = FadeTime; + _deathTime = _timing.RealTime + FadeTime; } } -- 2.51.2