Examine fixes (#13696)
This commit is contained in:
@@ -31,9 +31,12 @@ namespace Content.Client.Examine
|
||||
public const string StyleClassEntityTooltip = "entity-tooltip";
|
||||
|
||||
private EntityUid _examinedEntity;
|
||||
private EntityUid _lastExaminedEntity;
|
||||
private EntityUid _playerEntity;
|
||||
private Popup? _examineTooltipOpen;
|
||||
private ScreenCoordinates _popupPos;
|
||||
private CancellationTokenSource? _requestCancelTokenSource;
|
||||
private int _idCounter;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -46,6 +49,8 @@ namespace Content.Client.Examine
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine, outsidePrediction: true))
|
||||
.Register<ExamineSystem>();
|
||||
|
||||
_idCounter = 0;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -124,6 +129,10 @@ namespace Content.Client.Examine
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
// Prevent updating a new tooltip.
|
||||
if (ev.Id != 0 && ev.Id != _idCounter)
|
||||
return;
|
||||
|
||||
// Tooltips coming in from the server generally prioritize
|
||||
// opening at the old tooltip rather than the cursor/another entity,
|
||||
// since there's probably one open already if it's coming in from the server.
|
||||
@@ -147,27 +156,26 @@ namespace Content.Client.Examine
|
||||
// Close any examine tooltip that might already be opened
|
||||
// Before we do that, save its position. We'll prioritize opening any new popups there if
|
||||
// openAtOldTooltip is true.
|
||||
var oldTooltipPos = _examineTooltipOpen?.ScreenCoordinates;
|
||||
ScreenCoordinates? oldTooltipPos = _examineTooltipOpen != null ? _popupPos : null;
|
||||
CloseTooltip();
|
||||
|
||||
// cache entity for Update function
|
||||
_examinedEntity = target;
|
||||
|
||||
const float minWidth = 300;
|
||||
ScreenCoordinates popupPos;
|
||||
|
||||
if (openAtOldTooltip && oldTooltipPos != null)
|
||||
{
|
||||
popupPos = _userInterfaceManager.ScreenToUIPosition(oldTooltipPos.Value);
|
||||
_popupPos = oldTooltipPos.Value;
|
||||
}
|
||||
else if (centeredOnCursor)
|
||||
{
|
||||
popupPos = _userInterfaceManager.MousePositionScaled;
|
||||
_popupPos = _userInterfaceManager.MousePositionScaled;
|
||||
}
|
||||
else
|
||||
{
|
||||
popupPos = _eyeManager.CoordinatesToScreen(Transform(target).Coordinates);
|
||||
popupPos = _userInterfaceManager.ScreenToUIPosition(popupPos);
|
||||
_popupPos = _eyeManager.CoordinatesToScreen(Transform(target).Coordinates);
|
||||
_popupPos = _userInterfaceManager.ScreenToUIPosition(_popupPos);
|
||||
}
|
||||
|
||||
// Actually open the tooltip.
|
||||
@@ -222,7 +230,7 @@ namespace Content.Client.Examine
|
||||
panel.Measure(Vector2.Infinity);
|
||||
var size = Vector2.ComponentMax((minWidth, 0), panel.DesiredSize);
|
||||
|
||||
_examineTooltipOpen.Open(UIBox2.FromDimensions(popupPos.Position, size));
|
||||
_examineTooltipOpen.Open(UIBox2.FromDimensions(_popupPos.Position, size));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -334,8 +342,13 @@ namespace Content.Client.Examine
|
||||
else
|
||||
{
|
||||
// Ask server for extra examine info.
|
||||
RaiseNetworkEvent(new ExamineSystemMessages.RequestExamineInfoMessage(entity, true));
|
||||
if (entity != _lastExaminedEntity)
|
||||
_idCounter += 1;
|
||||
if (_idCounter == int.MaxValue)
|
||||
_idCounter = 0;
|
||||
RaiseNetworkEvent(new ExamineSystemMessages.RequestExamineInfoMessage(entity, _idCounter, true));
|
||||
}
|
||||
_lastExaminedEntity = entity;
|
||||
}
|
||||
|
||||
private void CloseTooltip()
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Content.Server.Examine
|
||||
verbs = _verbSystem.GetLocalVerbs(target, player, typeof(ExamineVerb));
|
||||
|
||||
var ev = new ExamineSystemMessages.ExamineInfoResponseMessage(
|
||||
target, message, verbs?.ToList(), centerAtCursor
|
||||
target, 0, message, verbs?.ToList(), centerAtCursor
|
||||
);
|
||||
|
||||
RaiseNetworkEvent(ev, session.ConnectedClient);
|
||||
@@ -61,14 +61,14 @@ namespace Content.Server.Examine
|
||||
|| !EntityManager.EntityExists(request.EntityUid))
|
||||
{
|
||||
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
|
||||
request.EntityUid, _entityNotFoundMessage), channel);
|
||||
request.EntityUid, request.Id, _entityNotFoundMessage), channel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CanExamine(playerEnt, request.EntityUid))
|
||||
{
|
||||
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
|
||||
request.EntityUid, _entityOutOfRangeMessage, knowTarget: false), channel);
|
||||
request.EntityUid, request.Id, _entityOutOfRangeMessage, knowTarget: false), channel);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ namespace Content.Server.Examine
|
||||
verbs = _verbSystem.GetLocalVerbs(request.EntityUid, playerEnt, typeof(ExamineVerb));
|
||||
|
||||
var text = GetExamineText(request.EntityUid, player.AttachedEntity);
|
||||
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text, verbs?.ToList()), channel);
|
||||
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
|
||||
request.EntityUid, request.Id, text, verbs?.ToList()), channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,14 @@ namespace Content.Shared.Examine
|
||||
{
|
||||
public readonly EntityUid EntityUid;
|
||||
|
||||
public readonly int Id;
|
||||
|
||||
public readonly bool GetVerbs;
|
||||
|
||||
public RequestExamineInfoMessage(EntityUid entityUid, bool getVerbs=false)
|
||||
public RequestExamineInfoMessage(EntityUid entityUid, int id, bool getVerbs=false)
|
||||
{
|
||||
EntityUid = entityUid;
|
||||
Id = id;
|
||||
GetVerbs = getVerbs;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +27,7 @@ namespace Content.Shared.Examine
|
||||
public sealed class ExamineInfoResponseMessage : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid EntityUid;
|
||||
public readonly int Id;
|
||||
public readonly FormattedMessage Message;
|
||||
|
||||
public List<Verb>? Verbs;
|
||||
@@ -33,10 +37,11 @@ namespace Content.Shared.Examine
|
||||
|
||||
public readonly bool KnowTarget;
|
||||
|
||||
public ExamineInfoResponseMessage(EntityUid entityUid, FormattedMessage message, List<Verb>? verbs=null,
|
||||
public ExamineInfoResponseMessage(EntityUid entityUid, int id, FormattedMessage message, List<Verb>? verbs=null,
|
||||
bool centerAtCursor=true, bool openAtOldTooltip=true, bool knowTarget = true)
|
||||
{
|
||||
EntityUid = entityUid;
|
||||
Id = id;
|
||||
Message = message;
|
||||
Verbs = verbs;
|
||||
CenterAtCursor = centerAtCursor;
|
||||
|
||||
Reference in New Issue
Block a user