ECS dragdrop (#12973)

* ECS dragdrop

No more excuses.

* AAAAAAAAAAAAAA

* kry

* events

* aaaaaaaaaa

* HUH

* Fix stripping

* aaaaaa

* spoike

* asease

* fix table vaulting

* ded

* rebiew

* aaaaaaaaaaaaa

* drag

* aeaeae

* weh
This commit is contained in:
metalgearsloth
2023-02-14 00:29:34 +11:00
committed by GitHub
parent 4183b5f449
commit c8f89eca60
53 changed files with 936 additions and 1079 deletions

View File

@@ -1,36 +0,0 @@
namespace Content.Shared.DragDrop;
/// <summary>
/// Event that gets send to the target of a drag drop action
/// Mark this event as handled to specify that the entity can be dropped on
/// and set CanDrop to true or false, depending on whether dropping the entity onto the target is actually possible.
/// </summary>
public sealed class CanDragDropOnEvent : HandledEntityEventArgs
{
/// <summary>
/// Entity doing the drag and drop.
/// </summary>
public EntityUid User { get; }
/// <summary>
/// Entity that is being dragged.
/// </summary>
public EntityUid Dragged { get; }
/// <summary>
/// Entity that is being dropped on.
/// </summary>
public EntityUid Target { get; }
/// <summary>
/// If the dragged entity can be dropped on the target.
/// </summary>
public bool CanDrop { get; set; } = false;
public CanDragDropOnEvent(EntityUid user, EntityUid dragged, EntityUid target)
{
User = user;
Dragged = dragged;
Target = target;
}
}

View File

@@ -1,33 +1,26 @@
using Robust.Shared.Map;
using Robust.Shared.Serialization;
namespace Content.Shared.DragDrop
{
/// <summary>
/// Requests a drag / drop interaction to be performed
/// Raised on the client to the server requesting a drag-drop.
/// </summary>
[Serializable, NetSerializable]
public sealed class DragDropRequestEvent : EntityEventArgs
{
/// <summary>
/// Location that the entity was dropped.
/// </summary>
public EntityCoordinates DropLocation { get; }
/// <summary>
/// Entity that was dragged and dropped.
/// </summary>
public EntityUid Dropped { get; }
public EntityUid Dragged { get; }
/// <summary>
/// Entity that was drag dropped on.
/// </summary>
public EntityUid Target { get; }
public DragDropRequestEvent(EntityCoordinates dropLocation, EntityUid dropped, EntityUid target)
public DragDropRequestEvent(EntityUid dragged, EntityUid target)
{
DropLocation = dropLocation;
Dropped = dropped;
Dragged = dragged;
Target = target;
}
}

View File

@@ -0,0 +1,67 @@
namespace Content.Shared.DragDrop;
/// <summary>
/// Raised directed on an entity when attempting to start a drag.
/// </summary>
[ByRefEvent]
public record struct CanDragEvent
{
/// <summary>
/// False if we are unable to drag this entity.
/// </summary>
public bool Handled;
}
/// <summary>
/// Raised directed on a dragged entity to indicate whether it has interactions with the target entity.
/// </summary>
[ByRefEvent]
public record struct CanDropDraggedEvent(EntityUid User, EntityUid Target)
{
public readonly EntityUid User = User;
public readonly EntityUid Target = Target;
public bool Handled = false;
/// <summary>
/// Can we drop the entity onto the target? If the event is not handled then there is no supported interactions.
/// </summary>
public bool CanDrop = false;
}
/// <summary>
/// Raised directed on the target entity to indicate whether it has interactions with the dragged entity.
/// </summary>
[ByRefEvent]
public record struct CanDropTargetEvent(EntityUid User, EntityUid Dragged)
{
public readonly EntityUid User = User;
public readonly EntityUid Dragged = Dragged;
public bool Handled = false;
/// <summary>
/// <see cref="CanDropDraggedEvent"/>
/// </summary>
public bool CanDrop = false;
}
/// <summary>
/// Raised directed on a dragged entity when it is dropped on a target entity.
/// </summary>
[ByRefEvent]
public record struct DragDropDraggedEvent(EntityUid User, EntityUid Target)
{
public readonly EntityUid User = User;
public readonly EntityUid Target = Target;
public bool Handled = false;
}
/// <summary>
/// Raised directed on the target entity when a dragged entity is dragged onto it.
/// </summary>
[ByRefEvent]
public record struct DragDropTargetEvent(EntityUid User, EntityUid Dragged)
{
public readonly EntityUid User = User;
public readonly EntityUid Dragged = Dragged;
public bool Handled = false;
}

View File

@@ -1,12 +0,0 @@
namespace Content.Shared.DragDrop
{
public sealed class DropAttemptEvent : CancellableEntityEventArgs
{
public DropAttemptEvent(EntityUid uid)
{
Uid = uid;
}
public EntityUid Uid { get; }
}
}

View File

@@ -1,32 +0,0 @@
namespace Content.Shared.DragDrop
{
/// <summary>
/// This interface allows the component's entity to be dragged and dropped
/// onto by another entity and gives it behavior when that occurs.
/// </summary>
[RequiresExplicitImplementation]
public interface IDragDropOn
{
/// <summary>
/// Invoked when another entity is being dragged and dropped
/// onto this one before invoking <see cref="DragDropOn"/>.
/// Note that other drag and drop interactions may be attempted if
/// this one fails.
/// </summary>
/// <param name="eventArgs"></param>
/// <returns>true if <see cref="eventArgs"/> is valid, false otherwise.</returns>
bool CanDragDropOn(DragDropEvent eventArgs);
/// <summary>
/// Invoked server-side when another entity is being dragged and dropped
/// onto this one before invoking <see cref="DragDropOn"/>
/// Note that other drag and drop interactions may be attempted if
/// this one fails.
/// </summary>
/// <returns>
/// true if an interaction occurred and no further interaction should
/// be processed for this drop.
/// </returns>
bool DragDropOn(DragDropEvent eventArgs);
}
}

View File

@@ -1,124 +0,0 @@
using Robust.Shared.Map;
namespace Content.Shared.DragDrop
{
/// <summary>
/// This interface allows a local client to initiate dragging of the component's
/// entity by mouse, for drag and drop interactions.
/// </summary>
[RequiresExplicitImplementation]
public interface IDraggable
{
/// <summary>
/// Invoked when an user is attempting to initiate a drag with
/// this component's entity in range. It's fine to return true even if there
/// wouldn't be any valid targets - just return true if this entity is in a
/// "draggable" state.
/// </summary>
/// <param name="args">
/// The information about the drag, such as who is doing it.
/// </param>
/// <returns>True if the drag should be initiated, false otherwise.</returns>
bool CanStartDrag(StartDragDropEvent args)
{
return true;
}
/// <summary>
/// Invoked on entities visible to the user to check if this component's
/// entity can be dropped on the indicated target entity.
/// No need to check range / reachability in here.
/// Returning true will cause the target entity to be highlighted as
/// a potential target and allow dropping when in range.
/// </summary>
/// <returns>
/// True if target is a valid target to be dropped on by this component's
/// entity, false otherwise.
/// </returns>
bool CanDrop(CanDropEvent args);
/// <summary>
/// Invoked when this component's entity is being dropped on another.
/// Other drag and drop interactions may be attempted if this one fails.
/// </summary>
/// <param name="args">
/// The information about the drag, such as who is doing it.
/// </param>
/// <returns>
/// True if an interaction occurred and no further interaction should
/// be processed for this drop, false otherwise.
/// </returns>
bool Drop(DragDropEvent args)
{
return false;
}
}
[Virtual]
public class StartDragDropEvent : HandledEntityEventArgs
{
/// <summary>
/// Entity doing the drag and drop.
/// </summary>
public EntityUid User { get; }
/// <summary>
/// Entity that is being dragged.
/// </summary>
public EntityUid Dragged { get; }
/// <summary>
/// Creates a new instance of <see cref="StartDragDropEvent"/>.
/// </summary>
/// <param name="user">The entity doing the drag and drop.</param>
/// <param name="dragged">The entity that is being dragged and dropped.</param>
public StartDragDropEvent(EntityUid user, EntityUid dragged)
{
User = user;
Dragged = dragged;
}
}
[Virtual]
public class CanDropEvent : StartDragDropEvent
{
/// <summary>
/// The entity uid that <see cref="StartDragDropEvent.Dragged"/>
/// is being dropped onto.
/// </summary>
public EntityUid Target { get; }
/// <summary>
/// Creates a new instance of <see cref="CanDropEvent"/>.
/// </summary>
/// <param name="user">The entity doing the drag and drop.</param>
/// <param name="dragged">The entity that is being dragged and dropped.</param>
/// <param name="target">The entity that <see cref="dragged"/> is being dropped onto.</param>
public CanDropEvent(EntityUid user, EntityUid dragged, EntityUid target) : base(user, dragged)
{
Target = target;
}
}
[Virtual]
public class DragDropEvent : CanDropEvent
{
/// <summary>
/// The location where <see cref="StartDragDropEvent.Dragged"/>
/// is being dropped.
/// </summary>
public EntityCoordinates DropLocation { get; }
/// <summary>
/// Creates a new instance of <see cref="DragDropEvent"/>.
/// </summary>
/// <param name="user">The entity doing the drag and drop.</param>
/// <param name="dropLocation">The location where <see cref="dropped"/> is being dropped.</param>
/// <param name="dragged">The entity that is being dragged and dropped.</param>
/// <param name="target">The entity that <see cref="dropped"/> is being dropped onto.</param>
public DragDropEvent(EntityUid user, EntityCoordinates dropLocation, EntityUid dragged, EntityUid target) : base(user, dragged, target)
{
DropLocation = dropLocation;
}
}
}

View File

@@ -2,12 +2,5 @@
public abstract class SharedDragDropSystem : EntitySystem
{
protected bool? CheckDragDropOn(DragDropEvent eventArgs)
{
var canDragDropOnEvent = new CanDragDropOnEvent(eventArgs.User, eventArgs.Dragged, eventArgs.Target);
RaiseLocalEvent(eventArgs.Target, canDragDropOnEvent, false);
return canDragDropOnEvent.Handled ? canDragDropOnEvent.CanDrop : null;
}
}