Make popup messages track the source entity (#2414)
* Make popup messages track the source entity * Fix jitteryness when popping a message up on the player
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Content.Client.Interfaces;
|
using Content.Client.Interfaces;
|
||||||
@@ -54,27 +55,23 @@ namespace Content.Client
|
|||||||
|
|
||||||
private void DoNotifyEntity(MsgDoNotifyEntity message)
|
private void DoNotifyEntity(MsgDoNotifyEntity message)
|
||||||
{
|
{
|
||||||
if (!_entityManager.TryGetEntity(message.Entity, out var entity))
|
if (_playerManager.LocalPlayer?.ControlledEntity == null ||
|
||||||
|
!_entityManager.TryGetEntity(message.Entity, out var entity))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PopupMessage(_eyeManager.CoordinatesToScreen(entity.Transform.Coordinates), message.Message);
|
PopupMessage(entity, _playerManager.LocalPlayer.ControlledEntity, message.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PopupMessage(IEntity source, IEntity viewer, string message)
|
public override void PopupMessage(IEntity source, IEntity viewer, string message)
|
||||||
{
|
{
|
||||||
if (viewer != _playerManager.LocalPlayer?.ControlledEntity)
|
PopupMessage(_eyeManager.CoordinatesToScreen(source.Transform.Coordinates), message, source);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PopupMessage(_eyeManager.CoordinatesToScreen(source.Transform.Coordinates), message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PopupMessage(EntityCoordinates coordinates, IEntity viewer, string message)
|
public override void PopupMessage(EntityCoordinates coordinates, IEntity viewer, string message)
|
||||||
{
|
{
|
||||||
if (viewer != _playerManager.LocalPlayer.ControlledEntity)
|
if (viewer != _playerManager.LocalPlayer?.ControlledEntity)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -84,7 +81,7 @@ namespace Content.Client
|
|||||||
|
|
||||||
public override void PopupMessageCursor(IEntity viewer, string message)
|
public override void PopupMessageCursor(IEntity viewer, string message)
|
||||||
{
|
{
|
||||||
if (viewer != _playerManager.LocalPlayer.ControlledEntity)
|
if (viewer != _playerManager.LocalPlayer?.ControlledEntity)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -94,13 +91,21 @@ namespace Content.Client
|
|||||||
|
|
||||||
public void PopupMessage(ScreenCoordinates coordinates, string message)
|
public void PopupMessage(ScreenCoordinates coordinates, string message)
|
||||||
{
|
{
|
||||||
var label = new PopupLabel
|
PopupMessage(coordinates, message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PopupMessage(ScreenCoordinates coordinates, string message, IEntity? entity)
|
||||||
|
{
|
||||||
|
var label = new PopupLabel(_eyeManager)
|
||||||
{
|
{
|
||||||
|
Entity = entity,
|
||||||
Text = message,
|
Text = message,
|
||||||
StyleClasses = { StyleNano.StyleClassPopupMessage },
|
StyleClasses = { StyleNano.StyleClassPopupMessage },
|
||||||
};
|
};
|
||||||
|
|
||||||
_userInterfaceManager.PopupRoot.AddChild(label);
|
_userInterfaceManager.PopupRoot.AddChild(label);
|
||||||
var minimumSize = label.CombinedMinimumSize;
|
var minimumSize = label.CombinedMinimumSize;
|
||||||
|
|
||||||
LayoutContainer.SetPosition(label, label.InitialPos = coordinates.Position - minimumSize / 2);
|
LayoutContainer.SetPosition(label, label.InitialPos = coordinates.Position - minimumSize / 2);
|
||||||
_aliveLabels.Add(label);
|
_aliveLabels.Add(label);
|
||||||
}
|
}
|
||||||
@@ -125,20 +130,30 @@ namespace Content.Client
|
|||||||
|
|
||||||
private class PopupLabel : Label
|
private class PopupLabel : Label
|
||||||
{
|
{
|
||||||
|
private readonly IEyeManager _eyeManager;
|
||||||
|
|
||||||
public float TimeLeft { get; private set; }
|
public float TimeLeft { get; private set; }
|
||||||
public Vector2 InitialPos { get; set; }
|
public Vector2 InitialPos { get; set; }
|
||||||
|
public IEntity? Entity { get; set; }
|
||||||
|
|
||||||
public PopupLabel()
|
public PopupLabel(IEyeManager eyeManager)
|
||||||
{
|
{
|
||||||
|
_eyeManager = eyeManager;
|
||||||
ShadowOffsetXOverride = 1;
|
ShadowOffsetXOverride = 1;
|
||||||
ShadowOffsetYOverride = 1;
|
ShadowOffsetYOverride = 1;
|
||||||
FontColorShadowOverride = Color.Black;
|
FontColorShadowOverride = Color.Black;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(FrameEventArgs eventArgs)
|
protected override void FrameUpdate(FrameEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
TimeLeft += eventArgs.DeltaSeconds;
|
TimeLeft += eventArgs.DeltaSeconds;
|
||||||
LayoutContainer.SetPosition(this, InitialPos - (0, 20 * (TimeLeft * TimeLeft + TimeLeft)));
|
|
||||||
|
var position = Entity == null
|
||||||
|
? InitialPos
|
||||||
|
: _eyeManager.CoordinatesToScreen(Entity.Transform.Coordinates).Position - CombinedMinimumSize / 2;
|
||||||
|
|
||||||
|
LayoutContainer.SetPosition(this, position - (0, 20 * (TimeLeft * TimeLeft + TimeLeft)));
|
||||||
|
|
||||||
if (TimeLeft > 0.5f)
|
if (TimeLeft > 0.5f)
|
||||||
{
|
{
|
||||||
Modulate = Color.White.WithAlpha(1f - 0.2f * (float)Math.Pow(TimeLeft - 0.5f, 3f));
|
Modulate = Color.White.WithAlpha(1f - 0.2f * (float)Math.Pow(TimeLeft - 0.5f, 3f));
|
||||||
|
|||||||
Reference in New Issue
Block a user