Implement ECS alternative for IDragDropOn and fully ECS disposal units (#6380)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ using Robust.Shared.Serialization;
|
||||
namespace Content.Shared.Disposal.Components
|
||||
{
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedDisposalUnitComponent : Component, IDragDropOn
|
||||
public abstract class SharedDisposalUnitComponent : Component
|
||||
{
|
||||
public override string Name => "DisposalUnit";
|
||||
|
||||
@@ -134,13 +134,5 @@ namespace Content.Shared.Disposal.Components
|
||||
{
|
||||
Key
|
||||
}
|
||||
|
||||
// TODO: Unfortunately these aren't really ECS yet so soontm
|
||||
public virtual bool CanDragDropOn(DragDropEvent eventArgs)
|
||||
{
|
||||
return EntitySystem.Get<SharedDisposalUnitSystem>().CanInsert(this, eventArgs.Dragged);
|
||||
}
|
||||
|
||||
public abstract bool DragDropOn(DragDropEvent eventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Throwing;
|
||||
@@ -26,10 +27,11 @@ namespace Content.Shared.Disposal
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SharedDisposalUnitComponent, PreventCollideEvent>(HandlePreventCollide);
|
||||
SubscribeLocalEvent<SharedDisposalUnitComponent, PreventCollideEvent>(OnPreventCollide);
|
||||
SubscribeLocalEvent<SharedDisposalUnitComponent, CanDragDropOnEvent>(OnCanDragDropOn);
|
||||
}
|
||||
|
||||
private void HandlePreventCollide(EntityUid uid, SharedDisposalUnitComponent component, PreventCollideEvent args)
|
||||
private void OnPreventCollide(EntityUid uid, SharedDisposalUnitComponent component, PreventCollideEvent args)
|
||||
{
|
||||
var otherBody = args.BodyB.Owner;
|
||||
|
||||
@@ -47,6 +49,14 @@ namespace Content.Shared.Disposal
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCanDragDropOn(EntityUid uid, SharedDisposalUnitComponent component, CanDragDropOnEvent args)
|
||||
{
|
||||
if (args.Handled) return;
|
||||
|
||||
args.CanDrop = CanInsert(component, args.Dragged);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
public virtual bool CanInsert(SharedDisposalUnitComponent component, EntityUid entity)
|
||||
{
|
||||
if (!EntityManager.GetComponent<TransformComponent>(component.Owner).Anchored)
|
||||
|
||||
38
Content.Shared/DragDrop/CanDragDropOnEvent.cs
Normal file
38
Content.Shared/DragDrop/CanDragDropOnEvent.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
15
Content.Shared/DragDrop/SharedDragDropSystem.cs
Normal file
15
Content.Shared/DragDrop/SharedDragDropSystem.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.DragDrop;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user