Refactor Context Menus and make them use XAML & stylesheets (#4768)
* XAML verb menu * fix ghost FOV * spacing * rename missed "ContextMenu"->"EntityMenu" instances * move visibility checks to verb system * update comment * Remove CanSeeContainerCheck * use ScrollContainer measure option * MaxWidth / texxt line wrapping * verb category default Now when you click on a verb category, it should default to running the first member of that category. This makes it much more convenient to eject/insert when there is only a single option * only apply style to first verb category entry * Use new visibility flags * FoV -> Fov * Revert "only apply style to first verb category entry" This reverts commit 9a6a17dba600e3ae0421caed59fcab145c260c99. * make all entity menu visibility checks clientside * Fix empty unbuckle category * fix merge
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
@@ -13,58 +10,18 @@ namespace Content.Server.Verbs
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
|
||||
/// <summary>
|
||||
/// List of players that can see all entities on the context menu, ignoring normal visibility rules.
|
||||
/// </summary>
|
||||
public readonly HashSet<IPlayerSession> SeeAllContextPlayers = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
SubscribeNetworkEvent<RequestServerVerbsEvent>(HandleVerbRequest);
|
||||
SubscribeNetworkEvent<TryExecuteVerbEvent>(HandleTryExecuteVerb);
|
||||
|
||||
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
_playerManager.PlayerStatusChanged -= PlayerStatusChanged;
|
||||
}
|
||||
|
||||
private void PlayerStatusChanged(object? sender, SessionStatusEventArgs args)
|
||||
{
|
||||
if (args.NewStatus == SessionStatus.Disconnected)
|
||||
{
|
||||
SeeAllContextPlayers.Remove(args.Session);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
SeeAllContextPlayers.Clear();
|
||||
}
|
||||
|
||||
public void ToggleSeeAllContext(IPlayerSession player)
|
||||
{
|
||||
if (!SeeAllContextPlayers.Add(player))
|
||||
{
|
||||
SeeAllContextPlayers.Remove(player);
|
||||
}
|
||||
|
||||
SetSeeAllContextEvent args = new() { CanSeeAllContext = SeeAllContextPlayers.Contains(player) };
|
||||
RaiseNetworkEvent(args, player.ConnectedClient);
|
||||
SubscribeNetworkEvent<ExecuteVerbEvent>(HandleTryExecuteVerb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when asked over the network to run a given verb.
|
||||
/// </summary>
|
||||
public void HandleTryExecuteVerb(TryExecuteVerbEvent args, EntitySessionEventArgs eventArgs)
|
||||
public void HandleTryExecuteVerb(ExecuteVerbEvent args, EntitySessionEventArgs eventArgs)
|
||||
{
|
||||
var session = eventArgs.SenderSession;
|
||||
var userEntity = session.AttachedEntity;
|
||||
@@ -81,18 +38,20 @@ namespace Content.Server.Verbs
|
||||
}
|
||||
|
||||
// Get the list of verbs. This effectively also checks that the requested verb is in fact a valid verb that
|
||||
// the user can perform. In principle, this might waste time checking & preparing unrelated verbs even
|
||||
// though we know precisely which one we want. However, MOST entities will only have 1 or 2 verbs of a given
|
||||
// type. The one exception here is the "other" verb type, which has 3-4 verbs + all the debug verbs. So maybe
|
||||
// the debug verbs should be made a separate type?
|
||||
var verbs = GetVerbs(targetEntity, userEntity, args.Type)[args.Type];
|
||||
// the user can perform.
|
||||
var verbs = GetLocalVerbs(targetEntity, userEntity, args.Type)[args.Type];
|
||||
|
||||
// Note that GetLocalVerbs might waste time checking & preparing unrelated verbs even though we know
|
||||
// precisely which one we want to run. However, MOST entities will only have 1 or 2 verbs of a given type.
|
||||
// The one exception here is the "other" verb type, which has 3-4 verbs + all the debug verbs.
|
||||
|
||||
// Find the requested verb.
|
||||
if (verbs.TryGetValue(args.RequestedVerb, out var verb))
|
||||
TryExecuteVerb(verb);
|
||||
ExecuteVerb(verb);
|
||||
else
|
||||
// 404 Verb not found
|
||||
Logger.Warning($"{nameof(HandleTryExecuteVerb)} called by player {session} with an invalid verb: {args.RequestedVerb.Category?.Text} {args.RequestedVerb.Text}");
|
||||
// 404 Verb not found. Note that this could happen due to something as simple as opening the verb menu, walking away, then trying
|
||||
// to run the pickup-item verb. So maybe this shouldn't even be logged?
|
||||
Logger.Info($"{nameof(HandleTryExecuteVerb)} called by player {session} with an invalid verb: {args.RequestedVerb.Category?.Text} {args.RequestedVerb.Text}");
|
||||
}
|
||||
|
||||
private void HandleVerbRequest(RequestServerVerbsEvent args, EntitySessionEventArgs eventArgs)
|
||||
@@ -105,32 +64,17 @@ namespace Content.Server.Verbs
|
||||
return;
|
||||
}
|
||||
|
||||
var user = player.AttachedEntity;
|
||||
|
||||
if (user == null)
|
||||
if (player.AttachedEntity == null)
|
||||
{
|
||||
Logger.Warning($"{nameof(HandleVerbRequest)} called by player {player} with no attached entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate input (check that the user can see the entity)
|
||||
TryGetContextEntities(user,
|
||||
target.Transform.MapPosition,
|
||||
out var entities,
|
||||
buffer: true,
|
||||
ignoreVisibility: SeeAllContextPlayers.Contains(player));
|
||||
|
||||
VerbsResponseEvent response;
|
||||
if (entities != null && entities.Contains(target))
|
||||
{
|
||||
response = new(args.EntityUid, GetVerbs(target, user, args.Type));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Don't leave the client hanging on "Waiting for server....", send empty response.
|
||||
response = new(args.EntityUid, null);
|
||||
}
|
||||
// We do not verify that the user has access to the requested entity. The individual verbs should check
|
||||
// this, and some verbs (e.g. view variables) won't even care about whether an entity is accessible through
|
||||
// the entity menu or not.
|
||||
|
||||
var response = new VerbsResponseEvent(args.EntityUid, GetLocalVerbs(target, player.AttachedEntity, args.Type));
|
||||
RaiseNetworkEvent(response, player.ConnectedClient);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user