2021-10-28 18:21:19 +13:00
|
|
|
using System;
|
2018-11-21 20:58:11 +01:00
|
|
|
using System.Collections.Generic;
|
2021-10-28 18:21:19 +13:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-10-05 14:29:03 +11:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.ContextMenu.UI;
|
2021-11-22 09:40:09 +13:00
|
|
|
using Content.Client.Examine;
|
2021-10-28 18:21:19 +13:00
|
|
|
using Content.Client.Popups;
|
|
|
|
|
using Content.Client.Verbs.UI;
|
2021-11-22 09:40:09 +13:00
|
|
|
using Content.Client.Viewport;
|
2021-10-28 18:21:19 +13:00
|
|
|
using Content.Shared.Examine;
|
2020-10-26 12:11:32 +01:00
|
|
|
using Content.Shared.GameTicking;
|
2021-10-28 18:21:19 +13:00
|
|
|
using Content.Shared.Tag;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Verbs;
|
2019-08-25 12:54:55 +02:00
|
|
|
using JetBrains.Annotations;
|
2021-10-28 18:21:19 +13:00
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
using Robust.Client.Graphics;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Client.Player;
|
2021-11-22 09:40:09 +13:00
|
|
|
using Robust.Client.State;
|
2021-10-28 18:21:19 +13:00
|
|
|
using Robust.Shared.Containers;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Maths;
|
2021-11-22 09:40:09 +13:00
|
|
|
using static Content.Shared.Interaction.SharedInteractionSystem;
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Verbs
|
2018-11-21 20:58:11 +01:00
|
|
|
{
|
2019-08-25 12:54:55 +02:00
|
|
|
[UsedImplicitly]
|
2021-06-29 15:56:07 +02:00
|
|
|
public sealed class VerbSystem : SharedVerbSystem
|
2018-11-21 20:58:11 +01:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
2021-11-22 09:40:09 +13:00
|
|
|
[Dependency] private readonly ExamineSystem _examineSystem = default!;
|
|
|
|
|
[Dependency] private readonly IStateManager _stateManager = default!;
|
2021-10-28 18:21:19 +13:00
|
|
|
[Dependency] private readonly IEntityLookup _entityLookup = default!;
|
2021-10-05 14:29:03 +11:00
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// When a user right clicks somewhere, how large is the box we use to get entities for the context menu?
|
|
|
|
|
/// </summary>
|
2021-11-20 18:25:29 +13:00
|
|
|
public const float EntityMenuLookupSize = 0.25f;
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
public EntityMenuPresenter EntityMenu = default!;
|
|
|
|
|
public VerbMenuPresenter VerbMenu = default!;
|
|
|
|
|
|
|
|
|
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
2021-02-25 19:42:16 -06:00
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
/// <summary>
|
2021-10-28 18:21:19 +13:00
|
|
|
/// These flags determine what entities the user can see on the context menu.
|
2021-10-05 14:29:03 +11:00
|
|
|
/// </summary>
|
2021-10-28 18:21:19 +13:00
|
|
|
public MenuVisibility Visibility;
|
2018-11-21 20:58:11 +01:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2020-09-06 16:11:53 +02:00
|
|
|
|
2021-06-29 15:56:07 +02:00
|
|
|
SubscribeNetworkEvent<RoundRestartCleanupEvent>(Reset);
|
2021-10-05 14:29:03 +11:00
|
|
|
SubscribeNetworkEvent<VerbsResponseEvent>(HandleVerbResponse);
|
2020-02-18 19:43:54 -08:00
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
EntityMenu = new(this);
|
|
|
|
|
VerbMenu = new(this);
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
public void Reset(RoundRestartCleanupEvent ev)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
CloseAllMenus();
|
2020-05-31 14:32:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
2021-04-09 16:08:12 +02:00
|
|
|
base.Shutdown();
|
2021-10-28 18:21:19 +13:00
|
|
|
EntityMenu?.Dispose();
|
|
|
|
|
VerbMenu?.Dispose();
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
public override void Update(float frameTime)
|
2020-10-26 12:11:32 +01:00
|
|
|
{
|
2021-10-05 14:29:03 +11:00
|
|
|
base.Update(frameTime);
|
2021-10-28 18:21:19 +13:00
|
|
|
EntityMenu?.Update();
|
2020-10-26 12:11:32 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
public void CloseAllMenus()
|
2021-02-25 19:42:16 -06:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
EntityMenu.Close();
|
|
|
|
|
VerbMenu.Close();
|
2021-02-25 19:42:16 -06:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
/// <summary>
|
2021-10-28 18:21:19 +13:00
|
|
|
/// Get all of the entities in an area for displaying on the context menu.
|
2021-10-05 14:29:03 +11:00
|
|
|
/// </summary>
|
2021-10-28 18:21:19 +13:00
|
|
|
public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true)] out List<IEntity>? result)
|
2021-02-25 19:42:16 -06:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
result = null;
|
2020-10-26 12:11:32 +01:00
|
|
|
|
2021-11-22 09:40:09 +13:00
|
|
|
if (_stateManager.CurrentState is not GameScreenBase gameScreenBase)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
2021-10-28 18:21:19 +13:00
|
|
|
if (player == null)
|
|
|
|
|
return false;
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-11-22 09:40:09 +13:00
|
|
|
// If FOV drawing is disabled, we will modify the visibility option to ignore visiblity checks.
|
2021-10-28 18:21:19 +13:00
|
|
|
var visibility = _eyeManager.CurrentEye.DrawFov
|
|
|
|
|
? Visibility
|
|
|
|
|
: Visibility | MenuVisibility.NoFov;
|
2021-10-05 14:29:03 +11:00
|
|
|
|
2021-11-22 09:40:09 +13:00
|
|
|
// Do we have to do FoV checks?
|
|
|
|
|
if ((visibility & MenuVisibility.NoFov) == 0)
|
|
|
|
|
{
|
|
|
|
|
var entitiesUnderMouse = gameScreenBase.GetEntitiesUnderPosition(targetPos);
|
|
|
|
|
Ignored? predicate = e => e == player || entitiesUnderMouse.Contains(e);
|
|
|
|
|
if (!_examineSystem.CanExamine(player, targetPos, predicate))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
// Get entities
|
2021-11-20 18:25:29 +13:00
|
|
|
var entities = _entityLookup.GetEntitiesInRange(targetPos.MapId, targetPos.Position, EntityMenuLookupSize)
|
2021-10-28 18:21:19 +13:00
|
|
|
.ToList();
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
if (entities.Count == 0)
|
|
|
|
|
return false;
|
2021-10-05 14:29:03 +11:00
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
if (visibility == MenuVisibility.All)
|
2020-07-23 00:56:30 +02:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
result = entities;
|
|
|
|
|
return true;
|
2020-07-23 00:56:30 +02:00
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
// remove any entities in containers
|
|
|
|
|
if ((visibility & MenuVisibility.InContainer) == 0)
|
2018-11-21 20:58:11 +01:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
foreach (var entity in entities.ToList())
|
|
|
|
|
{
|
|
|
|
|
if (!player.IsInSameOrTransparentContainer(entity))
|
|
|
|
|
entities.Remove(entity);
|
|
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
// remove any invisible entities
|
|
|
|
|
if ((visibility & MenuVisibility.Invisible) == 0)
|
2019-10-30 11:31:35 -04:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
foreach (var entity in entities.ToList())
|
|
|
|
|
{
|
|
|
|
|
if (!EntityManager.TryGetComponent(entity.Uid, out ISpriteComponent? spriteComponent) ||
|
|
|
|
|
!spriteComponent.Visible)
|
|
|
|
|
{
|
|
|
|
|
entities.Remove(entity);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity.HasTag("HideContextMenu"))
|
|
|
|
|
entities.Remove(entity);
|
|
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
// Remove any entities that do not have LOS
|
|
|
|
|
if ((visibility & MenuVisibility.NoFov) == 0)
|
2018-11-21 20:58:11 +01:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
var playerPos = player.Transform.MapPosition;
|
|
|
|
|
foreach (var entity in entities.ToList())
|
2018-11-21 20:58:11 +01:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
if (!ExamineSystemShared.InRangeUnOccluded(
|
|
|
|
|
playerPos,
|
|
|
|
|
entity.Transform.MapPosition,
|
|
|
|
|
ExamineSystemShared.ExamineRange,
|
|
|
|
|
null))
|
|
|
|
|
{
|
|
|
|
|
entities.Remove(entity);
|
|
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
if (entities.Count == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
result = entities;
|
|
|
|
|
return true;
|
2020-05-23 03:09:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Ask the server to send back a list of server-side verbs, and for now return an incomplete list of verbs
|
|
|
|
|
/// (only those defined locally).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Dictionary<VerbType, SortedSet<Verb>> GetVerbs(IEntity target, IEntity user, VerbType verbTypes)
|
2020-05-23 03:09:44 +02:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
if (!target.Uid.IsClientSide())
|
2020-05-23 03:09:44 +02:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
RaiseNetworkEvent(new RequestServerVerbsEvent(target.Uid, verbTypes));
|
2020-05-23 03:09:44 +02:00
|
|
|
}
|
2021-10-28 18:21:19 +13:00
|
|
|
|
|
|
|
|
return GetLocalVerbs(target, user, verbTypes);
|
2020-05-23 03:09:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
/// <summary>
|
2021-10-28 18:21:19 +13:00
|
|
|
/// Execute actions associated with the given verb.
|
2021-10-05 14:29:03 +11:00
|
|
|
/// </summary>
|
2021-10-28 18:21:19 +13:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Unless this is a client-exclusive verb, this will also tell the server to run the same verb. However, if the verb
|
|
|
|
|
/// is disabled and has a tooltip, this function will only generate a pop-up-message instead of executing anything.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void ExecuteVerb(EntityUid target, Verb verb, VerbType verbType)
|
2020-05-23 03:09:44 +02:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
if (verb.Disabled)
|
|
|
|
|
{
|
|
|
|
|
if (verb.Message != null)
|
|
|
|
|
_popupSystem.PopupCursor(verb.Message);
|
2021-10-05 14:29:03 +11:00
|
|
|
return;
|
2021-10-28 18:21:19 +13:00
|
|
|
}
|
2020-05-23 03:09:44 +02:00
|
|
|
|
2021-11-23 23:00:16 +13:00
|
|
|
var user = _playerManager.LocalPlayer?.ControlledEntityUid;
|
|
|
|
|
if (user == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ExecuteVerb(verb, user.Value, target);
|
2020-05-23 03:09:44 +02:00
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
if (!verb.ClientExclusive)
|
2020-05-23 03:09:44 +02:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
RaiseNetworkEvent(new ExecuteVerbEvent(target, verb, verbType));
|
2020-05-23 03:09:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
private void HandleVerbResponse(VerbsResponseEvent msg)
|
2020-05-23 03:09:44 +02:00
|
|
|
{
|
2021-10-28 18:21:19 +13:00
|
|
|
if (!VerbMenu.RootMenu.Visible || VerbMenu.CurrentTarget != msg.Entity)
|
|
|
|
|
return;
|
2021-10-05 14:29:03 +11:00
|
|
|
|
2021-10-28 18:21:19 +13:00
|
|
|
VerbMenu.AddServerVerbs(msg.Verbs);
|
2019-08-25 12:54:55 +02:00
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|
2021-10-28 18:21:19 +13:00
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
|
public enum MenuVisibility
|
|
|
|
|
{
|
|
|
|
|
// What entities can a user see on the entity menu?
|
|
|
|
|
Default = 0, // They can only see entities in FoV.
|
|
|
|
|
NoFov = 1 << 0, // They ignore FoV restrictions
|
|
|
|
|
InContainer = 1 << 1, // They can see through containers.
|
|
|
|
|
Invisible = 1 << 2, // They can see entities without sprites and the "HideContextMenu" tag is ignored.
|
|
|
|
|
All = NoFov | InContainer | Invisible
|
|
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
}
|