Examine fixes (#13696)

This commit is contained in:
Jacob Tong
2023-01-27 18:15:39 -05:00
committed by GitHub
parent ce3bb0e859
commit 6de75669d1
3 changed files with 33 additions and 14 deletions

View File

@@ -31,9 +31,12 @@ namespace Content.Client.Examine
public const string StyleClassEntityTooltip = "entity-tooltip"; public const string StyleClassEntityTooltip = "entity-tooltip";
private EntityUid _examinedEntity; private EntityUid _examinedEntity;
private EntityUid _lastExaminedEntity;
private EntityUid _playerEntity; private EntityUid _playerEntity;
private Popup? _examineTooltipOpen; private Popup? _examineTooltipOpen;
private ScreenCoordinates _popupPos;
private CancellationTokenSource? _requestCancelTokenSource; private CancellationTokenSource? _requestCancelTokenSource;
private int _idCounter;
public override void Initialize() public override void Initialize()
{ {
@@ -46,6 +49,8 @@ namespace Content.Client.Examine
CommandBinds.Builder CommandBinds.Builder
.Bind(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine, outsidePrediction: true)) .Bind(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine, outsidePrediction: true))
.Register<ExamineSystem>(); .Register<ExamineSystem>();
_idCounter = 0;
} }
public override void Update(float frameTime) public override void Update(float frameTime)
@@ -124,6 +129,10 @@ namespace Content.Client.Examine
if (player == null) if (player == null)
return; return;
// Prevent updating a new tooltip.
if (ev.Id != 0 && ev.Id != _idCounter)
return;
// Tooltips coming in from the server generally prioritize // Tooltips coming in from the server generally prioritize
// opening at the old tooltip rather than the cursor/another entity, // 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. // 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 // 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 // Before we do that, save its position. We'll prioritize opening any new popups there if
// openAtOldTooltip is true. // openAtOldTooltip is true.
var oldTooltipPos = _examineTooltipOpen?.ScreenCoordinates; ScreenCoordinates? oldTooltipPos = _examineTooltipOpen != null ? _popupPos : null;
CloseTooltip(); CloseTooltip();
// cache entity for Update function // cache entity for Update function
_examinedEntity = target; _examinedEntity = target;
const float minWidth = 300; const float minWidth = 300;
ScreenCoordinates popupPos;
if (openAtOldTooltip && oldTooltipPos != null) if (openAtOldTooltip && oldTooltipPos != null)
{ {
popupPos = _userInterfaceManager.ScreenToUIPosition(oldTooltipPos.Value); _popupPos = oldTooltipPos.Value;
} }
else if (centeredOnCursor) else if (centeredOnCursor)
{ {
popupPos = _userInterfaceManager.MousePositionScaled; _popupPos = _userInterfaceManager.MousePositionScaled;
} }
else else
{ {
popupPos = _eyeManager.CoordinatesToScreen(Transform(target).Coordinates); _popupPos = _eyeManager.CoordinatesToScreen(Transform(target).Coordinates);
popupPos = _userInterfaceManager.ScreenToUIPosition(popupPos); _popupPos = _userInterfaceManager.ScreenToUIPosition(_popupPos);
} }
// Actually open the tooltip. // Actually open the tooltip.
@@ -222,7 +230,7 @@ namespace Content.Client.Examine
panel.Measure(Vector2.Infinity); panel.Measure(Vector2.Infinity);
var size = Vector2.ComponentMax((minWidth, 0), panel.DesiredSize); var size = Vector2.ComponentMax((minWidth, 0), panel.DesiredSize);
_examineTooltipOpen.Open(UIBox2.FromDimensions(popupPos.Position, size)); _examineTooltipOpen.Open(UIBox2.FromDimensions(_popupPos.Position, size));
} }
/// <summary> /// <summary>
@@ -334,8 +342,13 @@ namespace Content.Client.Examine
else else
{ {
// Ask server for extra examine info. // 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() private void CloseTooltip()

View File

@@ -45,7 +45,7 @@ namespace Content.Server.Examine
verbs = _verbSystem.GetLocalVerbs(target, player, typeof(ExamineVerb)); verbs = _verbSystem.GetLocalVerbs(target, player, typeof(ExamineVerb));
var ev = new ExamineSystemMessages.ExamineInfoResponseMessage( var ev = new ExamineSystemMessages.ExamineInfoResponseMessage(
target, message, verbs?.ToList(), centerAtCursor target, 0, message, verbs?.ToList(), centerAtCursor
); );
RaiseNetworkEvent(ev, session.ConnectedClient); RaiseNetworkEvent(ev, session.ConnectedClient);
@@ -61,14 +61,14 @@ namespace Content.Server.Examine
|| !EntityManager.EntityExists(request.EntityUid)) || !EntityManager.EntityExists(request.EntityUid))
{ {
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage( RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
request.EntityUid, _entityNotFoundMessage), channel); request.EntityUid, request.Id, _entityNotFoundMessage), channel);
return; return;
} }
if (!CanExamine(playerEnt, request.EntityUid)) if (!CanExamine(playerEnt, request.EntityUid))
{ {
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage( RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
request.EntityUid, _entityOutOfRangeMessage, knowTarget: false), channel); request.EntityUid, request.Id, _entityOutOfRangeMessage, knowTarget: false), channel);
return; return;
} }
@@ -77,7 +77,8 @@ namespace Content.Server.Examine
verbs = _verbSystem.GetLocalVerbs(request.EntityUid, playerEnt, typeof(ExamineVerb)); verbs = _verbSystem.GetLocalVerbs(request.EntityUid, playerEnt, typeof(ExamineVerb));
var text = GetExamineText(request.EntityUid, player.AttachedEntity); 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);
} }
} }
} }

View File

@@ -11,11 +11,14 @@ namespace Content.Shared.Examine
{ {
public readonly EntityUid EntityUid; public readonly EntityUid EntityUid;
public readonly int Id;
public readonly bool GetVerbs; public readonly bool GetVerbs;
public RequestExamineInfoMessage(EntityUid entityUid, bool getVerbs=false) public RequestExamineInfoMessage(EntityUid entityUid, int id, bool getVerbs=false)
{ {
EntityUid = entityUid; EntityUid = entityUid;
Id = id;
GetVerbs = getVerbs; GetVerbs = getVerbs;
} }
} }
@@ -24,6 +27,7 @@ namespace Content.Shared.Examine
public sealed class ExamineInfoResponseMessage : EntityEventArgs public sealed class ExamineInfoResponseMessage : EntityEventArgs
{ {
public readonly EntityUid EntityUid; public readonly EntityUid EntityUid;
public readonly int Id;
public readonly FormattedMessage Message; public readonly FormattedMessage Message;
public List<Verb>? Verbs; public List<Verb>? Verbs;
@@ -33,10 +37,11 @@ namespace Content.Shared.Examine
public readonly bool KnowTarget; 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) bool centerAtCursor=true, bool openAtOldTooltip=true, bool knowTarget = true)
{ {
EntityUid = entityUid; EntityUid = entityUid;
Id = id;
Message = message; Message = message;
Verbs = verbs; Verbs = verbs;
CenterAtCursor = centerAtCursor; CenterAtCursor = centerAtCursor;