Add commands to show and hide organs inside bodies (#2292)

* Add seeing entities through containers and on the context menu and 4 commands

* Remove unused imports
This commit is contained in:
DrSmugleaf
2020-10-26 12:11:32 +01:00
committed by GitHub
parent 8a2e0ed142
commit ebe8a82033
8 changed files with 257 additions and 15 deletions

View File

@@ -8,8 +8,10 @@ using Content.Client.UserInterface;
using Content.Client.Utility;
using Content.Shared.GameObjects.EntitySystemMessages;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.GameTicking;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.GameObjects.EntitySystems;
using Robust.Client.Graphics;
using Robust.Client.Graphics.Drawing;
@@ -38,7 +40,7 @@ using Timer = Robust.Shared.Timers.Timer;
namespace Content.Client.GameObjects.EntitySystems
{
[UsedImplicitly]
public sealed class VerbSystem : SharedVerbSystem
public sealed class VerbSystem : SharedVerbSystem, IResettingEntitySystem
{
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
@@ -56,12 +58,14 @@ namespace Content.Client.GameObjects.EntitySystems
private bool IsAnyContextMenuOpen => _currentEntityList != null || _currentVerbListRoot != null;
private bool _playerCanSeeThroughContainers;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<VerbSystemMessages.VerbsResponseMessage>(FillEntityPopup);
SubscribeNetworkEvent<PlayerContainerVisibilityMessage>(HandleContainerVisibilityMessage);
IoCManager.InjectDependencies(this);
@@ -77,6 +81,16 @@ namespace Content.Client.GameObjects.EntitySystems
base.Shutdown();
}
public void Reset()
{
_playerCanSeeThroughContainers = false;
}
private void HandleContainerVisibilityMessage(PlayerContainerVisibilityMessage ev)
{
_playerCanSeeThroughContainers = ev.CanSeeThrough;
}
public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates)
{
if (_currentVerbListRoot != null)
@@ -99,6 +113,28 @@ namespace Content.Client.GameObjects.EntitySystems
_currentVerbListRoot.Open(box);
}
public bool CanSeeOnContextMenu(IEntity entity)
{
if (!entity.TryGetComponent(out SpriteComponent sprite) || !sprite.Visible)
{
return false;
}
if (entity.GetAllComponents<IShowContextMenu>().Any(s => !s.ShowContextMenu(entity)))
{
return false;
}
if (!_playerCanSeeThroughContainers &&
ContainerHelpers.TryGetContainer(entity, out var container) &&
!container.ShowContents)
{
return false;
}
return true;
}
private bool OnOpenContextMenu(in PointerInputCmdHandler.PointerInputCmdArgs args)
{
if (IsAnyContextMenuOpen)
@@ -125,17 +161,7 @@ namespace Content.Client.GameObjects.EntitySystems
var first = true;
foreach (var entity in entities)
{
if (!entity.TryGetComponent(out ISpriteComponent sprite) || !sprite.Visible)
{
continue;
}
if (entity.GetAllComponents<IShowContextMenu>().Any(s => !s.ShowContextMenu(playerEntity)))
{
continue;
}
if (ContainerHelpers.TryGetContainer(entity, out var container) && !container.ShowContents)
if (!CanSeeOnContextMenu(entity))
{
continue;
}