Improve Popup animation (#18721)
* Cap and slow Popup Y-distance * Make Popup lifetime a function of text length
This commit is contained in:
@@ -115,10 +115,12 @@ public sealed class PopupOverlay : Overlay
|
|||||||
|
|
||||||
private void DrawPopup(PopupSystem.PopupLabel popup, DrawingHandleScreen handle, Vector2 position, float scale)
|
private void DrawPopup(PopupSystem.PopupLabel popup, DrawingHandleScreen handle, Vector2 position, float scale)
|
||||||
{
|
{
|
||||||
const float alphaMinimum = 0.5f;
|
var lifetime = PopupSystem.GetPopupLifetime(popup);
|
||||||
|
|
||||||
var alpha = MathF.Min(1f, 1f - (popup.TotalTime - alphaMinimum) / (PopupSystem.PopupLifetime - alphaMinimum));
|
// Keep alpha at 1 until TotalTime passes half its lifetime, then gradually decrease to 0.
|
||||||
var updatedPosition = position - new Vector2(0f, 20f * (popup.TotalTime * popup.TotalTime + popup.TotalTime));
|
var alpha = MathF.Min(1f, 1f - MathF.Max(0f, popup.TotalTime - lifetime / 2) * 2 / lifetime);
|
||||||
|
|
||||||
|
var updatedPosition = position - new Vector2(0f, MathF.Min(8f, 12f * (popup.TotalTime * popup.TotalTime + popup.TotalTime)));
|
||||||
var font = _smallFont;
|
var font = _smallFont;
|
||||||
var color = Color.White.WithAlpha(alpha);
|
var color = Color.White.WithAlpha(alpha);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ namespace Content.Client.Popups
|
|||||||
private readonly List<WorldPopupLabel> _aliveWorldLabels = new();
|
private readonly List<WorldPopupLabel> _aliveWorldLabels = new();
|
||||||
private readonly List<CursorPopupLabel> _aliveCursorLabels = 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()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -185,6 +187,13 @@ namespace Content.Client.Popups
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public static float GetPopupLifetime(PopupLabel label)
|
||||||
|
{
|
||||||
|
return Math.Clamp(PopupLifetimePerCharacter * label.Text.Length,
|
||||||
|
MinimumPopupLifetime,
|
||||||
|
MaximumPopupLifetime);
|
||||||
|
}
|
||||||
|
|
||||||
public override void FrameUpdate(float frameTime)
|
public override void FrameUpdate(float frameTime)
|
||||||
{
|
{
|
||||||
if (_aliveWorldLabels.Count == 0 && _aliveCursorLabels.Count == 0)
|
if (_aliveWorldLabels.Count == 0 && _aliveCursorLabels.Count == 0)
|
||||||
@@ -195,7 +204,7 @@ namespace Content.Client.Popups
|
|||||||
var label = _aliveWorldLabels[i];
|
var label = _aliveWorldLabels[i];
|
||||||
label.TotalTime += frameTime;
|
label.TotalTime += frameTime;
|
||||||
|
|
||||||
if (label.TotalTime > PopupLifetime || Deleted(label.InitialPos.EntityId))
|
if (label.TotalTime > GetPopupLifetime(label) || Deleted(label.InitialPos.EntityId))
|
||||||
{
|
{
|
||||||
_aliveWorldLabels.RemoveSwap(i);
|
_aliveWorldLabels.RemoveSwap(i);
|
||||||
i--;
|
i--;
|
||||||
@@ -207,7 +216,7 @@ namespace Content.Client.Popups
|
|||||||
var label = _aliveCursorLabels[i];
|
var label = _aliveCursorLabels[i];
|
||||||
label.TotalTime += frameTime;
|
label.TotalTime += frameTime;
|
||||||
|
|
||||||
if (label.TotalTime > PopupLifetime)
|
if (label.TotalTime > GetPopupLifetime(label))
|
||||||
{
|
{
|
||||||
_aliveCursorLabels.RemoveSwap(i);
|
_aliveCursorLabels.RemoveSwap(i);
|
||||||
i--;
|
i--;
|
||||||
|
|||||||
Reference in New Issue
Block a user