{
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!;
/// <summary>
/// The total time a speech bubble stays on screen.
/// </summary>
- private const float TotalTime = 4;
+ private static readonly TimeSpan TotalTime = TimeSpan.FromSeconds(4);
/// <summary>
/// The amount of time at the end of the bubble's life at which it starts fading.
/// </summary>
- private const float FadeTime = 0.25f;
+ private static readonly TimeSpan FadeTime = TimeSpan.FromSeconds(0.25f);
/// <summary>
/// The distance in world space to offset the speech bubble from the center of the entity.
private readonly EntityUid _senderEntity;
- private float _timeLeft = TotalTime;
+ /// <summary>
+ /// The time at which this bubble will die.
+ /// </summary>
+ private TimeSpan _deathTime;
public float VerticalOffset { get; set; }
private float _verticalOffsetAchieved;
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);
{
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);
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
{
var baseOffset = 0f;
- if (_entityManager.TryGetComponent<SpeechComponent>(_senderEntity, out var speech))
+ if (_entityManager.TryGetComponent<SpeechComponent>(_senderEntity, out var speech))
baseOffset = speech.SpeechBubbleOffset;
var offset = (-_eyeManager.CurrentEye.Rotation).ToWorldVec() * -(EntityVerticalOffset + baseOffset);
/// </summary>
public void FadeNow()
{
- if (_timeLeft > FadeTime)
+ if (_deathTime > _timing.RealTime)
{
- _timeLeft = FadeTime;
+ _deathTime = _timing.RealTime + FadeTime;
}
}