Improve Popup animation (#18721)
* Cap and slow Popup Y-distance * Make Popup lifetime a function of text length
This commit is contained in:
@@ -35,7 +35,9 @@ namespace Content.Client.Popups
|
||||
private readonly List<WorldPopupLabel> _aliveWorldLabels = new();
|
||||
private readonly List<CursorPopupLabel> _aliveCursorLabels = new();
|
||||
|
||||
public const float PopupLifetime = 3f;
|
||||
public const float MinimumPopupLifetime = 0.7f;
|
||||
public const float MaximumPopupLifetime = 5f;
|
||||
public const float PopupLifetimePerCharacter = 0.04f;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -185,6 +187,13 @@ namespace Content.Client.Popups
|
||||
|
||||
#endregion
|
||||
|
||||
public static float GetPopupLifetime(PopupLabel label)
|
||||
{
|
||||
return Math.Clamp(PopupLifetimePerCharacter * label.Text.Length,
|
||||
MinimumPopupLifetime,
|
||||
MaximumPopupLifetime);
|
||||
}
|
||||
|
||||
public override void FrameUpdate(float frameTime)
|
||||
{
|
||||
if (_aliveWorldLabels.Count == 0 && _aliveCursorLabels.Count == 0)
|
||||
@@ -195,7 +204,7 @@ namespace Content.Client.Popups
|
||||
var label = _aliveWorldLabels[i];
|
||||
label.TotalTime += frameTime;
|
||||
|
||||
if (label.TotalTime > PopupLifetime || Deleted(label.InitialPos.EntityId))
|
||||
if (label.TotalTime > GetPopupLifetime(label) || Deleted(label.InitialPos.EntityId))
|
||||
{
|
||||
_aliveWorldLabels.RemoveSwap(i);
|
||||
i--;
|
||||
@@ -207,7 +216,7 @@ namespace Content.Client.Popups
|
||||
var label = _aliveCursorLabels[i];
|
||||
label.TotalTime += frameTime;
|
||||
|
||||
if (label.TotalTime > PopupLifetime)
|
||||
if (label.TotalTime > GetPopupLifetime(label))
|
||||
{
|
||||
_aliveCursorLabels.RemoveSwap(i);
|
||||
i--;
|
||||
|
||||
Reference in New Issue
Block a user