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:
49
Content.Client/Commands/HideMechanismsCommand.cs
Normal file
49
Content.Client/Commands/HideMechanismsCommand.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Content.Shared.GameObjects.Components.Body.Mechanism;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Interfaces.Console;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Client.Commands
|
||||
{
|
||||
public class HideMechanismsCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "hidemechanisms";
|
||||
public string Description => $"Reverts the effects of {ShowMechanismsCommand.CommandName}";
|
||||
public string Help => $"{Command}";
|
||||
|
||||
public bool Execute(IDebugConsole console, params string[] args)
|
||||
{
|
||||
var componentManager = IoCManager.Resolve<IComponentManager>();
|
||||
var mechanisms = componentManager.EntityQuery<IMechanism>();
|
||||
|
||||
foreach (var mechanism in mechanisms)
|
||||
{
|
||||
if (!mechanism.Owner.TryGetComponent(out SpriteComponent sprite))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sprite.ContainerOccluded = false;
|
||||
|
||||
var tempParent = mechanism.Owner;
|
||||
while (ContainerHelpers.TryGetContainer(tempParent, out var container))
|
||||
{
|
||||
if (!container.ShowContents)
|
||||
{
|
||||
sprite.ContainerOccluded = true;
|
||||
break;
|
||||
}
|
||||
|
||||
tempParent = container.Owner;
|
||||
}
|
||||
}
|
||||
|
||||
IoCManager.Resolve<IClientConsole>().ProcessCommand("hidecontainedcontext");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Content.Client/Commands/ShowMechanismsCommand.cs
Normal file
37
Content.Client/Commands/ShowMechanismsCommand.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Content.Shared.GameObjects.Components.Body.Mechanism;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Interfaces.Console;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Client.Commands
|
||||
{
|
||||
public class ShowMechanismsCommand : IConsoleCommand
|
||||
{
|
||||
public const string CommandName = "showmechanisms";
|
||||
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
public string Command => CommandName;
|
||||
public string Description => "Makes mechanisms visible, even when they shouldn't be.";
|
||||
public string Help => $"{Command}";
|
||||
|
||||
public bool Execute(IDebugConsole console, params string[] args)
|
||||
{
|
||||
var componentManager = IoCManager.Resolve<IComponentManager>();
|
||||
var mechanisms = componentManager.EntityQuery<IMechanism>();
|
||||
|
||||
foreach (var mechanism in mechanisms)
|
||||
{
|
||||
if (mechanism.Owner.TryGetComponent(out SpriteComponent sprite))
|
||||
{
|
||||
sprite.ContainerOccluded = false;
|
||||
}
|
||||
}
|
||||
|
||||
IoCManager.Resolve<IClientConsole>().ProcessCommand("showcontainedcontext");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user