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,12 +1,14 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Strap;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Buckle
|
||||
{
|
||||
public abstract class SharedBuckleComponent : Component, IActionBlocker, IEffectBlocker
|
||||
public abstract class SharedBuckleComponent : Component, IActionBlocker, IEffectBlocker, IDraggable
|
||||
{
|
||||
public sealed override string Name => "Buckle";
|
||||
|
||||
@@ -17,6 +19,8 @@ namespace Content.Shared.GameObjects.Components.Buckle
|
||||
/// </summary>
|
||||
public abstract bool Buckled { get; }
|
||||
|
||||
public abstract bool TryBuckle(IEntity user, IEntity to);
|
||||
|
||||
bool IActionBlocker.CanMove()
|
||||
{
|
||||
return !Buckled;
|
||||
@@ -31,6 +35,16 @@ namespace Content.Shared.GameObjects.Components.Buckle
|
||||
{
|
||||
return !Buckled;
|
||||
}
|
||||
|
||||
bool IDraggable.CanDrop(CanDropEventArgs args)
|
||||
{
|
||||
return args.Target.HasComponent<SharedStrapComponent>();
|
||||
}
|
||||
|
||||
public bool Drop(DragDropEventArgs args)
|
||||
{
|
||||
return TryBuckle(args.User, args.Dragged);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
@@ -1,16 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.GUI
|
||||
{
|
||||
public class SharedStrippableComponent : Component
|
||||
public abstract class SharedStrippableComponent : Component, IDraggable
|
||||
{
|
||||
public override string Name => "Strippable";
|
||||
|
||||
public bool CanBeStripped(IEntity by)
|
||||
{
|
||||
return by != Owner
|
||||
&& by.HasComponent<ISharedHandsComponent>()
|
||||
&& ActionBlockerSystem.CanInteract(by);
|
||||
}
|
||||
|
||||
bool IDraggable.CanDrop(CanDropEventArgs args)
|
||||
{
|
||||
return args.Target != args.Dragged
|
||||
&& args.Target == args.User
|
||||
&& CanBeStripped(args.User);
|
||||
}
|
||||
|
||||
public abstract bool Drop(DragDropEventArgs args);
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public enum StrippingUiKey
|
||||
{
|
||||
|
||||
@@ -5,10 +5,11 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Movement
|
||||
{
|
||||
public abstract class SharedClimbingComponent : Component, IActionBlocker, ICollideSpecial
|
||||
public abstract class SharedClimbingComponent : Component, IActionBlocker, ICollideSpecial, IDraggable
|
||||
{
|
||||
public sealed override string Name => "Climbing";
|
||||
public sealed override uint? NetID => ContentNetIDs.CLIMBING;
|
||||
@@ -45,6 +46,16 @@ namespace Content.Shared.GameObjects.Components.Movement
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IDraggable.CanDrop(CanDropEventArgs args)
|
||||
{
|
||||
return args.Target.HasComponent<IClimbable>();
|
||||
}
|
||||
|
||||
bool IDraggable.Drop(DragDropEventArgs args)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components
|
||||
{
|
||||
public abstract class SharedPlaceableSurfaceComponent : Component
|
||||
{
|
||||
public override string Name => "PlaceableSurface";
|
||||
public override uint? NetID => ContentNetIDs.PLACEABLE_SURFACE;
|
||||
|
||||
public virtual bool IsPlaceable { get; set; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class PlaceableSurfaceComponentState : ComponentState
|
||||
{
|
||||
public readonly bool IsPlaceable;
|
||||
|
||||
public PlaceableSurfaceComponentState(bool placeable) : base(ContentNetIDs.PLACEABLE_SURFACE)
|
||||
{
|
||||
IsPlaceable = placeable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Storage
|
||||
{
|
||||
public abstract class SharedStorableComponent : Component
|
||||
{
|
||||
public override string Name => "Storable";
|
||||
public override uint? NetID => ContentNetIDs.STORABLE;
|
||||
|
||||
public virtual int Size { get; set; }
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(this, s => s.Size, "size", 1);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class StorableComponentState : ComponentState
|
||||
{
|
||||
public readonly int Size;
|
||||
|
||||
public StorableComponentState(int size) : base(ContentNetIDs.STORABLE)
|
||||
{
|
||||
Size = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,71 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Storage
|
||||
{
|
||||
public abstract class SharedStorageComponent : Component
|
||||
public abstract class SharedStorageComponent : Component, IDraggable
|
||||
{
|
||||
public override string Name => "Storage";
|
||||
public override uint? NetID => ContentNetIDs.INVENTORY;
|
||||
|
||||
public abstract IReadOnlyList<IEntity>? StoredEntities { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Removes from the storage container and updates the stored value
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to remove</param>
|
||||
/// <returns>True if no longer in storage, false otherwise</returns>
|
||||
public abstract bool Remove(IEntity entity);
|
||||
|
||||
public bool CanDrop(CanDropEventArgs args)
|
||||
{
|
||||
return args.Target.TryGetComponent(out SharedPlaceableSurfaceComponent? placeable) &&
|
||||
placeable.IsPlaceable;
|
||||
}
|
||||
|
||||
public bool Drop(DragDropEventArgs eventArgs)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(eventArgs.User))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var storedEntities = StoredEntities?.ToArray();
|
||||
|
||||
if (storedEntities == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// empty everything out
|
||||
foreach (var storedEntity in storedEntities)
|
||||
{
|
||||
if (Remove(storedEntity))
|
||||
{
|
||||
storedEntity.Transform.WorldPosition = eventArgs.DropLocation.Position;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class StorageComponentState : ComponentState
|
||||
{
|
||||
public readonly EntityUid[] StoredEntities;
|
||||
|
||||
public StorageComponentState(EntityUid[] storedEntities) : base(ContentNetIDs.INVENTORY)
|
||||
{
|
||||
StoredEntities = storedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -19,14 +76,14 @@ namespace Content.Shared.GameObjects.Components.Storage
|
||||
{
|
||||
public readonly int StorageSizeMax;
|
||||
public readonly int StorageSizeUsed;
|
||||
public Dictionary<EntityUid, int> StoredEntities;
|
||||
public readonly EntityUid[] StoredEntities;
|
||||
|
||||
public StorageHeldItemsMessage(Dictionary<EntityUid, int> storedentities, int storageused, int storagemaxsize)
|
||||
public StorageHeldItemsMessage(EntityUid[] storedEntities, int storageUsed, int storageMaxSize)
|
||||
{
|
||||
Directed = true;
|
||||
StorageSizeMax = storagemaxsize;
|
||||
StorageSizeUsed = storageused;
|
||||
StoredEntities = storedentities;
|
||||
StorageSizeMax = storageMaxSize;
|
||||
StorageSizeUsed = storageUsed;
|
||||
StoredEntities = storedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user