Close examine tooltip when moving out of range (#4273)
This commit is contained in:
@@ -8,6 +8,7 @@ using Robust.Client.GameObjects;
|
|||||||
using Robust.Client.Player;
|
using Robust.Client.Player;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Input.Binding;
|
using Robust.Shared.Input.Binding;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -15,6 +16,7 @@ using Robust.Shared.Map;
|
|||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Players;
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using static Content.Shared.Interaction.SharedInteractionSystem;
|
||||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||||
|
|
||||||
namespace Content.Client.Examine
|
namespace Content.Client.Examine
|
||||||
@@ -27,6 +29,8 @@ namespace Content.Client.Examine
|
|||||||
|
|
||||||
public const string StyleClassEntityTooltip = "entity-tooltip";
|
public const string StyleClassEntityTooltip = "entity-tooltip";
|
||||||
|
|
||||||
|
private IEntity? _examinedEntity;
|
||||||
|
private IEntity? _playerEntity;
|
||||||
private Popup? _examineTooltipOpen;
|
private Popup? _examineTooltipOpen;
|
||||||
private CancellationTokenSource? _requestCancelTokenSource;
|
private CancellationTokenSource? _requestCancelTokenSource;
|
||||||
|
|
||||||
@@ -39,6 +43,24 @@ namespace Content.Client.Examine
|
|||||||
.Register<ExamineSystem>();
|
.Register<ExamineSystem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
if (_examineTooltipOpen == null || !_examineTooltipOpen.Visible) return;
|
||||||
|
if (_examinedEntity == null || _playerEntity == null) return;
|
||||||
|
|
||||||
|
Ignored predicate = entity => entity == _playerEntity || entity == _examinedEntity;
|
||||||
|
|
||||||
|
if (_playerEntity.TryGetContainer(out var container))
|
||||||
|
{
|
||||||
|
predicate += entity => entity == container.Owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InRangeUnOccluded(_playerEntity, _examinedEntity, ExamineRange, predicate))
|
||||||
|
{
|
||||||
|
CloseTooltip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
{
|
{
|
||||||
CommandBinds.Unregister<ExamineSystem>();
|
CommandBinds.Unregister<ExamineSystem>();
|
||||||
@@ -47,51 +69,54 @@ namespace Content.Client.Examine
|
|||||||
|
|
||||||
private bool HandleExamine(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
private bool HandleExamine(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
||||||
{
|
{
|
||||||
if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out var examined))
|
if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out _examinedEntity))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerEntity = _playerManager.LocalPlayer?.ControlledEntity;
|
_playerEntity = _playerManager.LocalPlayer?.ControlledEntity;
|
||||||
|
|
||||||
if (playerEntity == null || !CanExamine(playerEntity, examined))
|
if (_playerEntity == null || !CanExamine(_playerEntity, _examinedEntity))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DoExamine(examined);
|
DoExamine(_examinedEntity);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void DoExamine(IEntity entity)
|
public async void DoExamine(IEntity entity)
|
||||||
{
|
{
|
||||||
const float minWidth = 300;
|
// Close any examine tooltip that might already be opened
|
||||||
CloseTooltip();
|
CloseTooltip();
|
||||||
|
|
||||||
|
const float minWidth = 300;
|
||||||
var popupPos = _userInterfaceManager.MousePositionScaled;
|
var popupPos = _userInterfaceManager.MousePositionScaled;
|
||||||
|
|
||||||
// Actually open the tooltip.
|
// Actually open the tooltip.
|
||||||
_examineTooltipOpen = new Popup { MaxWidth = 400};
|
_examineTooltipOpen = new Popup { MaxWidth = 400 };
|
||||||
_userInterfaceManager.ModalRoot.AddChild(_examineTooltipOpen);
|
_userInterfaceManager.ModalRoot.AddChild(_examineTooltipOpen);
|
||||||
var panel = new PanelContainer();
|
var panel = new PanelContainer();
|
||||||
panel.AddStyleClass(StyleClassEntityTooltip);
|
panel.AddStyleClass(StyleClassEntityTooltip);
|
||||||
panel.ModulateSelfOverride = Color.LightGray.WithAlpha(0.90f);
|
panel.ModulateSelfOverride = Color.LightGray.WithAlpha(0.90f);
|
||||||
_examineTooltipOpen.AddChild(panel);
|
_examineTooltipOpen.AddChild(panel);
|
||||||
//panel.SetAnchorAndMarginPreset(Control.LayoutPreset.Wide);
|
|
||||||
var vBox = new BoxContainer
|
var vBox = new BoxContainer
|
||||||
{
|
{
|
||||||
Orientation = LayoutOrientation.Vertical
|
Orientation = LayoutOrientation.Vertical
|
||||||
};
|
};
|
||||||
panel.AddChild(vBox);
|
panel.AddChild(vBox);
|
||||||
|
|
||||||
var hBox = new BoxContainer
|
var hBox = new BoxContainer
|
||||||
{
|
{
|
||||||
Orientation = LayoutOrientation.Horizontal,
|
Orientation = LayoutOrientation.Horizontal,
|
||||||
SeparationOverride = 5
|
SeparationOverride = 5
|
||||||
};
|
};
|
||||||
vBox.AddChild(hBox);
|
vBox.AddChild(hBox);
|
||||||
|
|
||||||
if (entity.TryGetComponent(out ISpriteComponent? sprite))
|
if (entity.TryGetComponent(out ISpriteComponent? sprite))
|
||||||
{
|
{
|
||||||
hBox.AddChild(new SpriteView {Sprite = sprite, OverrideDirection = Direction.South});
|
hBox.AddChild(new SpriteView { Sprite = sprite, OverrideDirection = Direction.South });
|
||||||
}
|
}
|
||||||
|
|
||||||
hBox.AddChild(new Label
|
hBox.AddChild(new Label
|
||||||
@@ -112,7 +137,6 @@ namespace Content.Client.Examine
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
// Ask server for extra examine info.
|
// Ask server for extra examine info.
|
||||||
RaiseNetworkEvent(new ExamineSystemMessages.RequestExamineInfoMessage(entity.Uid));
|
RaiseNetworkEvent(new ExamineSystemMessages.RequestExamineInfoMessage(entity.Uid));
|
||||||
|
|
||||||
@@ -138,17 +162,16 @@ namespace Content.Client.Examine
|
|||||||
|
|
||||||
foreach (var msg in message.Tags.OfType<FormattedMessage.TagText>())
|
foreach (var msg in message.Tags.OfType<FormattedMessage.TagText>())
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(msg.Text))
|
if (string.IsNullOrWhiteSpace(msg.Text)) continue;
|
||||||
{
|
|
||||||
var richLabel = new RichTextLabel();
|
var richLabel = new RichTextLabel();
|
||||||
richLabel.SetMessage(message);
|
richLabel.SetMessage(message);
|
||||||
vBox.AddChild(richLabel);
|
vBox.AddChild(richLabel);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void CloseTooltip()
|
private void CloseTooltip()
|
||||||
{
|
{
|
||||||
if (_examineTooltipOpen != null)
|
if (_examineTooltipOpen != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user