Add utility verbs (#6473)

This commit is contained in:
Leon Friedrich
2022-02-24 23:48:53 +13:00
committed by GitHub
parent 8ae2ba9fa5
commit 53c9ecbf6a
7 changed files with 156 additions and 10 deletions

View File

@@ -47,16 +47,16 @@ namespace Content.Shared.Verbs
/// Raises a number of events in order to get all verbs of the given type(s) defined in local systems. This
/// does not request verbs from the server.
/// </summary>
public SortedSet<Verb> GetLocalVerbs(EntityUid target, EntityUid user, Type type, bool force = false, bool all = false)
public SortedSet<Verb> GetLocalVerbs(EntityUid target, EntityUid user, Type type, bool force = false)
{
return GetLocalVerbs(target, user, new List<Type>() { type }, force, all);
return GetLocalVerbs(target, user, new List<Type>() { type }, force);
}
/// <summary>
/// Raises a number of events in order to get all verbs of the given type(s) defined in local systems. This
/// does not request verbs from the server.
/// </summary>
public SortedSet<Verb> GetLocalVerbs(EntityUid target, EntityUid user, List<Type> types, bool force = false, bool all = false)
public SortedSet<Verb> GetLocalVerbs(EntityUid target, EntityUid user, List<Type> types, bool force = false)
{
SortedSet<Verb> verbs = new();
@@ -99,6 +99,15 @@ namespace Content.Shared.Verbs
verbs.UnionWith(verbEvent.Verbs);
}
if (types.Contains(typeof(UtilityVerb))
&& @using != null
&& @using != target)
{
var verbEvent = new GetVerbsEvent<UtilityVerb>(user, target, @using, hands, canInteract, canAccess);
RaiseLocalEvent(@using.Value, verbEvent); // directed at used, not at target
verbs.UnionWith(verbEvent.Verbs);
}
if (types.Contains(typeof(AlternativeVerb)))
{
var verbEvent = new GetVerbsEvent<AlternativeVerb>(user, target, @using, hands, canInteract, canAccess);

View File

@@ -121,6 +121,12 @@ namespace Content.Shared.Verbs
/// </summary>
public string? IconTexture;
/// <summary>
/// If this is not null, and no icon or icon texture were specified, a sprite view of this entity will be
/// used as the icon for this verb.
/// </summary>
public EntityUid? IconEntity;
/// <summary>
/// Whether or not to close the context menu after using it to run this verb.
/// </summary>
@@ -200,6 +206,7 @@ namespace Content.Shared.Verbs
{
{ typeof(Verb) },
{ typeof(InteractionVerb) },
{ typeof(UtilityVerb) },
{ typeof(AlternativeVerb) },
{ typeof(ActivationVerb) },
{ typeof(ExamineVerb) }
@@ -226,6 +233,27 @@ namespace Content.Shared.Verbs
}
}
/// <summary>
/// These verbs are similar to the normal interaction verbs, except these interactions are facilitated by the
/// currently held entity.
/// </summary>
/// <remarks>
/// The only notable difference between these and InteractionVerbs is that they are obtained by raising an event
/// directed at the currently held entity. Distinguishing between utility and interaction verbs helps avoid
/// confusion if a component enables verbs both when the item is used on something else, or when it is the
/// target of an interaction. These verbs are only obtained if the target and the held entity are NOT the same.
/// </remarks>
[Serializable, NetSerializable]
public sealed class UtilityVerb : Verb
{
public override int TypePriority => 3;
public UtilityVerb() : base()
{
TextStyleClass = InteractionVerb.DefaultTextStyleClass;
}
}
/// <summary>
/// Verbs for alternative-interactions.
/// </summary>