2020-07-20 02:06:51 +02:00
|
|
|
|
using System;
|
2018-11-21 20:58:11 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2018-11-21 20:58:11 +01:00
|
|
|
|
|
2020-08-13 14:40:27 +02:00
|
|
|
|
namespace Content.Shared.GameObjects.Verbs
|
2018-11-21 20:58:11 +01:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A verb is an action in the right click menu of an entity.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// To add a verb to an entity, define it as a nested class inside the owning component,
|
|
|
|
|
|
/// and mark it with <see cref="VerbAttribute"/>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
[UsedImplicitly]
|
2020-08-20 21:45:28 +02:00
|
|
|
|
public abstract class Verb : VerbBase
|
2018-11-21 20:58:11 +01:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2020-05-23 03:09:44 +02:00
|
|
|
|
/// Gets the visible verb data for the user.
|
2018-11-21 20:58:11 +01:00
|
|
|
|
/// </summary>
|
2020-05-23 03:09:44 +02:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Implementations should write into <paramref name="data"/> to return their data.
|
|
|
|
|
|
/// </remarks>
|
2018-11-21 20:58:11 +01:00
|
|
|
|
/// <param name="user">The entity of the user opening this menu.</param>
|
|
|
|
|
|
/// <param name="component">The component instance for which this verb is being loaded.</param>
|
2020-05-23 03:09:44 +02:00
|
|
|
|
/// <param name="data">The data that must be filled into.</param>
|
|
|
|
|
|
protected abstract void GetData(IEntity user, IComponent component, VerbData data);
|
2018-11-21 20:58:11 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Invoked when this verb is activated from the right click menu.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="user">The entity of the user opening this menu.</param>
|
|
|
|
|
|
/// <param name="component">The component instance for which this verb is being loaded.</param>
|
|
|
|
|
|
public abstract void Activate(IEntity user, IComponent component);
|
2020-05-23 03:09:44 +02:00
|
|
|
|
|
|
|
|
|
|
public VerbData GetData(IEntity user, IComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
var data = new VerbData();
|
|
|
|
|
|
GetData(user, component, data);
|
|
|
|
|
|
return data;
|
|
|
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>
|
2020-08-13 14:40:27 +02:00
|
|
|
|
/// Sub class of <see cref="T:Content.Shared.GameObjects.Verbs.Verb" /> that works on a specific type of component,
|
2018-11-21 20:58:11 +01:00
|
|
|
|
/// to reduce casting boiler plate for implementations.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">The type of component that this verb will run on.</typeparam>
|
|
|
|
|
|
public abstract class Verb<T> : Verb where T : IComponent
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2020-05-23 03:09:44 +02:00
|
|
|
|
/// Gets the visible verb data for the user.
|
2018-11-21 20:58:11 +01:00
|
|
|
|
/// </summary>
|
2020-05-23 03:09:44 +02:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Implementations should write into <paramref name="data"/> to return their data.
|
|
|
|
|
|
/// </remarks>
|
2018-11-21 20:58:11 +01:00
|
|
|
|
/// <param name="user">The entity of the user opening this menu.</param>
|
|
|
|
|
|
/// <param name="component">The component instance for which this verb is being loaded.</param>
|
2020-05-23 03:09:44 +02:00
|
|
|
|
/// <param name="data">The data that must be filled into.</param>
|
|
|
|
|
|
protected abstract void GetData(IEntity user, T component, VerbData data);
|
2018-11-21 20:58:11 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Invoked when this verb is activated from the right click menu.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="user">The entity of the user opening this menu.</param>
|
|
|
|
|
|
/// <param name="component">The component instance for which this verb is being loaded.</param>
|
|
|
|
|
|
protected abstract void Activate(IEntity user, T component);
|
|
|
|
|
|
|
2020-05-23 03:09:44 +02:00
|
|
|
|
protected sealed override void GetData(IEntity user, IComponent component, VerbData data)
|
2020-03-06 20:11:24 +01:00
|
|
|
|
{
|
2020-05-23 03:09:44 +02:00
|
|
|
|
GetData(user, (T) component, data);
|
2018-11-21 20:58:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-15 12:49:29 -07:00
|
|
|
|
/// <inheritdoc />
|
2018-11-21 20:58:11 +01:00
|
|
|
|
public sealed override void Activate(IEntity user, IComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
Activate(user, (T) component);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This attribute should be used on <see cref="Verb"/> implementations nested inside component classes,
|
|
|
|
|
|
/// so that they're automatically detected.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
2019-10-10 11:51:38 +02:00
|
|
|
|
[MeansImplicitUse]
|
2018-11-21 20:58:11 +01:00
|
|
|
|
public sealed class VerbAttribute : Attribute
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|