Added a range check for examining entities. Now you can't examine things across the map.

Made the examine window a little transparent so that you can see things behind it. This prevents the examine popup from occluding gameplay.
Moved the ExamineEntity bind from Human to Common context so that it will always be available to clients. Ghosts can now examine things.
This commit is contained in:
Acruid
2019-05-16 14:41:43 -07:00
parent d81254e389
commit e40f9b20e3
3 changed files with 35 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Shared.GameObjects.EntitySystemMessages; using Content.Shared.GameObjects.EntitySystemMessages;
using Content.Shared.Input; using Content.Shared.Input;
@@ -7,6 +7,7 @@ using Robust.Client.GameObjects.EntitySystems;
using Robust.Client.Interfaces.GameObjects.Components; using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Client.Interfaces.Input; using Robust.Client.Interfaces.Input;
using Robust.Client.Interfaces.UserInterface; using Robust.Client.Interfaces.UserInterface;
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.GameObjects; using Robust.Shared.GameObjects;
@@ -25,10 +26,14 @@ namespace Content.Client.GameObjects.EntitySystems
{ {
public const string StyleClassEntityTooltip = "entity-tooltip"; public const string StyleClassEntityTooltip = "entity-tooltip";
public const float ExamineRange = 1.5f;
public const float ExamineRangeSquared = ExamineRange * ExamineRange;
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private IInputManager _inputManager; [Dependency] private IInputManager _inputManager;
[Dependency] private IUserInterfaceManager _userInterfaceManager; [Dependency] private IUserInterfaceManager _userInterfaceManager;
[Dependency] private IEntityManager _entityManager; [Dependency] private IEntityManager _entityManager;
[Dependency] private IPlayerManager _playerManager;
#pragma warning restore 649 #pragma warning restore 649
private Popup _examineTooltipOpen; private Popup _examineTooltipOpen;
@@ -56,6 +61,13 @@ namespace Content.Client.GameObjects.EntitySystems
return; return;
} }
var playerEntity = _playerManager.LocalPlayer.ControlledEntity;
if(playerEntity == null)
return;
if((entity.Transform.WorldPosition - playerEntity.Transform.WorldPosition).LengthSquared > ExamineRangeSquared)
return;
DoExamine(entity); DoExamine(entity);
} }
@@ -70,6 +82,7 @@ namespace Content.Client.GameObjects.EntitySystems
_userInterfaceManager.StateRoot.AddChild(_examineTooltipOpen); _userInterfaceManager.StateRoot.AddChild(_examineTooltipOpen);
var panel = new PanelContainer(); var panel = new PanelContainer();
panel.AddStyleClass(StyleClassEntityTooltip); panel.AddStyleClass(StyleClassEntityTooltip);
panel.ModulateSelfOverride = Color.LightGray.WithAlpha(0.90f);
_examineTooltipOpen.AddChild(panel); _examineTooltipOpen.AddChild(panel);
panel.SetAnchorAndMarginPreset(Control.LayoutPreset.Wide); panel.SetAnchorAndMarginPreset(Control.LayoutPreset.Wide);
var vBox = new VBoxContainer(); var vBox = new VBoxContainer();

View File

@@ -13,13 +13,13 @@ namespace Content.Client.Input
{ {
var common = contexts.GetContext("common"); var common = contexts.GetContext("common");
common.AddFunction(ContentKeyFunctions.FocusChat); common.AddFunction(ContentKeyFunctions.FocusChat);
common.AddFunction(ContentKeyFunctions.ExamineEntity);
var human = contexts.GetContext("human"); var human = contexts.GetContext("human");
human.AddFunction(ContentKeyFunctions.SwapHands); human.AddFunction(ContentKeyFunctions.SwapHands);
human.AddFunction(ContentKeyFunctions.Drop); human.AddFunction(ContentKeyFunctions.Drop);
human.AddFunction(ContentKeyFunctions.ActivateItemInHand); human.AddFunction(ContentKeyFunctions.ActivateItemInHand);
human.AddFunction(ContentKeyFunctions.OpenCharacterMenu); human.AddFunction(ContentKeyFunctions.OpenCharacterMenu);
human.AddFunction(ContentKeyFunctions.ExamineEntity);
human.AddFunction(ContentKeyFunctions.UseItemInHand); human.AddFunction(ContentKeyFunctions.UseItemInHand);
human.AddFunction(ContentKeyFunctions.ActivateItemInWorld); human.AddFunction(ContentKeyFunctions.ActivateItemInWorld);
human.AddFunction(ContentKeyFunctions.ThrowItemInHand); human.AddFunction(ContentKeyFunctions.ThrowItemInHand);

View File

@@ -29,8 +29,12 @@ namespace Content.Server.GameObjects.EntitySystems
public class ExamineSystem : EntitySystem public class ExamineSystem : EntitySystem
{ {
public const float ExamineRange = 1.5f;
public const float ExamineRangeSquared = ExamineRange * ExamineRange;
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private IEntityManager _entityManager; [Dependency] private IEntityManager _entityManager;
[Dependency] private IPlayerManager _playerManager;
#pragma warning restore 649 #pragma warning restore 649
private static readonly FormattedMessage _entityNotFoundMessage; private static readonly FormattedMessage _entityNotFoundMessage;
@@ -95,18 +99,24 @@ namespace Content.Server.GameObjects.EntitySystems
{ {
base.HandleNetMessage(channel, message); base.HandleNetMessage(channel, message);
if (message is ExamineSystemMessages.RequestExamineInfoMessage request) if (!(message is ExamineSystemMessages.RequestExamineInfoMessage request))
{ return;
if (!_entityManager.TryGetEntity(request.EntityUid, out var entity))
{
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
request.EntityUid, _entityNotFoundMessage));
return;
}
var text = GetExamineText(entity); var session = _playerManager.GetSessionByChannel(channel);
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text)); var playerEnt = session.AttachedEntity;
if((playerEnt == null) ||
(!_entityManager.TryGetEntity(request.EntityUid, out var entity)) ||
(entity.Transform.MapID != playerEnt.Transform.MapID) ||
((entity.Transform.WorldPosition - playerEnt.Transform.WorldPosition).LengthSquared > ExamineRangeSquared))
{
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
request.EntityUid, _entityNotFoundMessage));
return;
} }
var text = GetExamineText(entity);
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text));
} }
} }
} }