Refactor drag and drop to use a shared interface (#2012)
* WIP in progress hours * Cleanup * Fix bugle * Fix nullable error * Merge fixes * Merge fixes * Merge fixes
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
using System;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface allows the component's entity to be dragged and dropped
|
||||
/// by mouse onto another entity and gives it behavior when that occurs.
|
||||
/// </summary>
|
||||
public interface IDragDrop
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked server-side when this component's entity is being dragged
|
||||
/// and dropped on another before invoking <see cref="DragDrop"/>.
|
||||
/// 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 CanDragDrop(DragDropEventArgs eventArgs);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked server-side when this component's entity is being dragged
|
||||
/// and dropped on another.
|
||||
/// 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 DragDrop(DragDropEventArgs eventArgs);
|
||||
}
|
||||
|
||||
public class DragDropEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="DragDropEventArgs"/>.
|
||||
/// </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="dropped">The entity that is being dragged and dropped.</param>
|
||||
/// <param name="target">The entity that <see cref="dropped"/> is being dropped onto.</param>
|
||||
public DragDropEventArgs(IEntity user, EntityCoordinates dropLocation, IEntity dropped, IEntity target)
|
||||
{
|
||||
User = user;
|
||||
DropLocation = dropLocation;
|
||||
Dropped = dropped;
|
||||
Target = target;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The entity doing the drag and drop.
|
||||
/// </summary>
|
||||
public IEntity User { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The location where <see cref="Dropped"/> is being dropped.
|
||||
/// </summary>
|
||||
public EntityCoordinates DropLocation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity that is being dragged and dropped.
|
||||
/// </summary>
|
||||
public IEntity Dropped { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity that <see cref="Dropped"/> is being dropped onto.
|
||||
/// </summary>
|
||||
public IEntity Target { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface allows a local client to initiate dragging of the component's
|
||||
/// entity by mouse, for drag and drop interactions.
|
||||
/// </summary>
|
||||
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(StartDragDropEventArgs 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(CanDropEventArgs 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(DragDropEventArgs args)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class StartDragDropEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="StartDragDropEventArgs"/>.
|
||||
/// </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 StartDragDropEventArgs(IEntity user, IEntity dragged)
|
||||
{
|
||||
User = user;
|
||||
Dragged = dragged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The entity doing the drag and drop.
|
||||
/// </summary>
|
||||
public IEntity User { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity that is being dragged.
|
||||
/// </summary>
|
||||
public IEntity Dragged { get; }
|
||||
}
|
||||
|
||||
public class CanDropEventArgs : StartDragDropEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="CanDropEventArgs"/>.
|
||||
/// </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="dropped"/> is being dropped onto.</param>
|
||||
public CanDropEventArgs(IEntity user, IEntity dragged, IEntity target) : base(user, dragged)
|
||||
{
|
||||
Target = target;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The entity that <see cref="StartDragDropEventArgs.Dragged"/>
|
||||
/// is being dropped onto.
|
||||
/// </summary>
|
||||
public IEntity Target { get; }
|
||||
}
|
||||
|
||||
public class DragDropEventArgs : CanDropEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="DragDropEventArgs"/>.
|
||||
/// </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 DragDropEventArgs(IEntity user, EntityCoordinates dropLocation, IEntity dragged, IEntity target) : base(user, dragged, target)
|
||||
{
|
||||
DropLocation = dropLocation;
|
||||
}
|
||||
/// <summary>
|
||||
/// The location where <see cref="StartDragDropEventArgs.Dragged"/>
|
||||
/// is being dropped.
|
||||
/// </summary>
|
||||
public EntityCoordinates DropLocation { get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user