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.Client.Utility;
|
||||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
using Content.Shared.GameObjects.EntitySystemMessages;
|
||||||
using Content.Shared.GameObjects.Verbs;
|
using Content.Shared.GameObjects.Verbs;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Client.GameObjects.EntitySystems;
|
using Robust.Client.GameObjects.EntitySystems;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
using Robust.Client.Graphics.Drawing;
|
using Robust.Client.Graphics.Drawing;
|
||||||
@@ -38,7 +40,7 @@ using Timer = Robust.Shared.Timers.Timer;
|
|||||||
namespace Content.Client.GameObjects.EntitySystems
|
namespace Content.Client.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class VerbSystem : SharedVerbSystem
|
public sealed class VerbSystem : SharedVerbSystem, IResettingEntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IStateManager _stateManager = default!;
|
[Dependency] private readonly IStateManager _stateManager = default!;
|
||||||
[Dependency] private readonly IEntityManager _entityManager = 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 IsAnyContextMenuOpen => _currentEntityList != null || _currentVerbListRoot != null;
|
||||||
|
|
||||||
|
private bool _playerCanSeeThroughContainers;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeNetworkEvent<VerbSystemMessages.VerbsResponseMessage>(FillEntityPopup);
|
SubscribeNetworkEvent<VerbSystemMessages.VerbsResponseMessage>(FillEntityPopup);
|
||||||
|
SubscribeNetworkEvent<PlayerContainerVisibilityMessage>(HandleContainerVisibilityMessage);
|
||||||
|
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
|
|
||||||
@@ -77,6 +81,16 @@ namespace Content.Client.GameObjects.EntitySystems
|
|||||||
base.Shutdown();
|
base.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
_playerCanSeeThroughContainers = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleContainerVisibilityMessage(PlayerContainerVisibilityMessage ev)
|
||||||
|
{
|
||||||
|
_playerCanSeeThroughContainers = ev.CanSeeThrough;
|
||||||
|
}
|
||||||
|
|
||||||
public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates)
|
public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates)
|
||||||
{
|
{
|
||||||
if (_currentVerbListRoot != null)
|
if (_currentVerbListRoot != null)
|
||||||
@@ -99,6 +113,28 @@ namespace Content.Client.GameObjects.EntitySystems
|
|||||||
_currentVerbListRoot.Open(box);
|
_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)
|
private bool OnOpenContextMenu(in PointerInputCmdHandler.PointerInputCmdArgs args)
|
||||||
{
|
{
|
||||||
if (IsAnyContextMenuOpen)
|
if (IsAnyContextMenuOpen)
|
||||||
@@ -125,17 +161,7 @@ namespace Content.Client.GameObjects.EntitySystems
|
|||||||
var first = true;
|
var first = true;
|
||||||
foreach (var entity in entities)
|
foreach (var entity in entities)
|
||||||
{
|
{
|
||||||
if (!entity.TryGetComponent(out ISpriteComponent sprite) || !sprite.Visible)
|
if (!CanSeeOnContextMenu(entity))
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.GetAllComponents<IShowContextMenu>().Any(s => !s.ShowContextMenu(playerEntity)))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ContainerHelpers.TryGetContainer(entity, out var container) && !container.ShowContents)
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
26
Content.Server/Commands/HideContainedContextCommand.cs
Normal file
26
Content.Server/Commands/HideContainedContextCommand.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#nullable enable
|
||||||
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
|
using Robust.Server.Interfaces.Console;
|
||||||
|
using Robust.Server.Interfaces.Player;
|
||||||
|
using Robust.Shared.GameObjects.Systems;
|
||||||
|
|
||||||
|
namespace Content.Server.Commands
|
||||||
|
{
|
||||||
|
public class HideContainedContextCommand : IClientCommand
|
||||||
|
{
|
||||||
|
public string Command => "hidecontainedcontext";
|
||||||
|
public string Description => $"Reverts the effects of {ShowContainedContextCommand.CommandName}";
|
||||||
|
public string Help => $"{Command}";
|
||||||
|
|
||||||
|
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||||
|
{
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
shell.SendText(player, "You need to be a player to use this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntitySystem.Get<VerbSystem>().RemoveContainerVisibility(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Content.Server/Commands/ShowContainedContextCommand.cs
Normal file
29
Content.Server/Commands/ShowContainedContextCommand.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#nullable enable
|
||||||
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
|
using Robust.Server.Interfaces.Console;
|
||||||
|
using Robust.Server.Interfaces.Player;
|
||||||
|
using Robust.Shared.GameObjects.Systems;
|
||||||
|
|
||||||
|
namespace Content.Server.Commands
|
||||||
|
{
|
||||||
|
public class ShowContainedContextCommand : IClientCommand
|
||||||
|
{
|
||||||
|
public const string CommandName = "showcontainedcontext";
|
||||||
|
|
||||||
|
// ReSharper disable once StringLiteralTypo
|
||||||
|
public string Command => CommandName;
|
||||||
|
public string Description => "Makes contained entities visible on the context menu, even when they shouldn't be.";
|
||||||
|
public string Help => $"{Command}";
|
||||||
|
|
||||||
|
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||||
|
{
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
shell.SendText(player, "You need to be a player to use this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntitySystem.Get<VerbSystem>().AddContainerVisibility(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
#nullable enable
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Content.Shared.GameObjects.EntitySystemMessages;
|
||||||
using Content.Shared.GameObjects.Verbs;
|
using Content.Shared.GameObjects.Verbs;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
|
using Robust.Server.Player;
|
||||||
|
using Robust.Shared.Enums;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -10,18 +15,63 @@ using static Content.Shared.GameObjects.EntitySystemMessages.VerbSystemMessages;
|
|||||||
|
|
||||||
namespace Content.Server.GameObjects.EntitySystems
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
public class VerbSystem : SharedVerbSystem
|
public class VerbSystem : SharedVerbSystem, IResettingEntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||||
|
|
||||||
|
private readonly HashSet<IPlayerSession> _seesThroughContainers = new HashSet<IPlayerSession>();
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
IoCManager.InjectDependencies(this);
|
||||||
|
|
||||||
SubscribeNetworkEvent<RequestVerbsMessage>(RequestVerbs);
|
SubscribeNetworkEvent<RequestVerbsMessage>(RequestVerbs);
|
||||||
SubscribeNetworkEvent<UseVerbMessage>(UseVerb);
|
SubscribeNetworkEvent<UseVerbMessage>(UseVerb);
|
||||||
|
|
||||||
IoCManager.InjectDependencies(this);
|
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlayerStatusChanged(object? sender, SessionStatusEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.NewStatus == SessionStatus.Disconnected)
|
||||||
|
{
|
||||||
|
_seesThroughContainers.Remove(args.Session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
_seesThroughContainers.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddContainerVisibility(IPlayerSession session)
|
||||||
|
{
|
||||||
|
if (!_seesThroughContainers.Add(session))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = new PlayerContainerVisibilityMessage(true);
|
||||||
|
RaiseNetworkEvent(message, session.ConnectedClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveContainerVisibility(IPlayerSession session)
|
||||||
|
{
|
||||||
|
if (!_seesThroughContainers.Remove(session))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = new PlayerContainerVisibilityMessage(false);
|
||||||
|
RaiseNetworkEvent(message, session.ConnectedClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasContainerVisibility(IPlayerSession session)
|
||||||
|
{
|
||||||
|
return _seesThroughContainers.Contains(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UseVerb(UseVerbMessage use, EntitySessionEventArgs eventArgs)
|
private void UseVerb(UseVerbMessage use, EntitySessionEventArgs eventArgs)
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.EntitySystemMessages
|
||||||
|
{
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public class PlayerContainerVisibilityMessage : EntitySystemMessage
|
||||||
|
{
|
||||||
|
public readonly bool CanSeeThrough;
|
||||||
|
|
||||||
|
public PlayerContainerVisibilityMessage(bool canSeeThrough)
|
||||||
|
{
|
||||||
|
CanSeeThrough = canSeeThrough;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,6 +109,10 @@
|
|||||||
- deleteewi
|
- deleteewi
|
||||||
- hurt
|
- hurt
|
||||||
- toggledisallowlatejoin
|
- toggledisallowlatejoin
|
||||||
|
- showcontainedcontext
|
||||||
|
- hidecontainedcontext
|
||||||
|
- showmechanisms
|
||||||
|
- hidemechanisms
|
||||||
- attachbodypart
|
- attachbodypart
|
||||||
- attachtoself
|
- attachtoself
|
||||||
- attachtogrid
|
- attachtogrid
|
||||||
@@ -215,6 +219,10 @@
|
|||||||
- deleteewi
|
- deleteewi
|
||||||
- hurt
|
- hurt
|
||||||
- toggledisallowlatejoin
|
- toggledisallowlatejoin
|
||||||
|
- showcontainedcontext
|
||||||
|
- hidecontainedcontext
|
||||||
|
- showmechanisms
|
||||||
|
- hidemechanisms
|
||||||
- attachbodypart
|
- attachbodypart
|
||||||
- attachtoself
|
- attachtoself
|
||||||
- attachtogrid
|
- attachtogrid
|
||||||
|
|||||||
Reference in New Issue
Block a user