Make grinder use item slots (& misc eject-button changes) (#7197)
This commit is contained in:
32
Content.Shared/Containers/ItemSlot/ItemSlotEvents.cs
Normal file
32
Content.Shared/Containers/ItemSlot/ItemSlotEvents.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Containers.ItemSlots;
|
||||
|
||||
/// <summary>
|
||||
/// Used for various "eject this item" buttons.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ItemSlotButtonPressedEvent : BoundUserInterfaceMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the slot/container from which to insert or eject an item.
|
||||
/// </summary>
|
||||
public string SlotId;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to attempt to insert an item into the slot, if there is not already one inside.
|
||||
/// </summary>
|
||||
public bool TryInsert;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to attempt to eject the item from the slot, if it has one.
|
||||
/// </summary>
|
||||
public bool TryEject;
|
||||
|
||||
public ItemSlotButtonPressedEvent(string slotId, bool tryEject = true, bool tryInsert = true)
|
||||
{
|
||||
SlotId = slotId;
|
||||
TryEject = tryEject;
|
||||
TryInsert = tryInsert;
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,8 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
|
||||
SubscribeLocalEvent<ItemSlotsComponent, ComponentGetState>(GetItemSlotsState);
|
||||
SubscribeLocalEvent<ItemSlotsComponent, ComponentHandleState>(HandleItemSlotsState);
|
||||
|
||||
SubscribeLocalEvent<ItemSlotsComponent, ItemSlotButtonPressedEvent>(HandleButtonPressed);
|
||||
}
|
||||
|
||||
#region ComponentManagement
|
||||
@@ -291,7 +293,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
return false;
|
||||
|
||||
// hands.Drop(item) checks CanDrop action blocker
|
||||
if (_handsSystem.TryDrop(user, hands.ActiveHand))
|
||||
if (!_handsSystem.TryDrop(user, hands.ActiveHand))
|
||||
return false;
|
||||
|
||||
Insert(uid, slot, held, user);
|
||||
@@ -490,6 +492,19 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region BUIs
|
||||
private void HandleButtonPressed(EntityUid uid, ItemSlotsComponent component, ItemSlotButtonPressedEvent args)
|
||||
{
|
||||
if (!component.Slots.TryGetValue(args.SlotId, out var slot))
|
||||
return;
|
||||
|
||||
if (args.TryEject && slot.HasItem)
|
||||
TryEjectToHands(uid, slot, args.Session.AttachedEntity);
|
||||
else if (args.TryInsert && !slot.HasItem && args.Session.AttachedEntity is EntityUid user)
|
||||
TryInsertFromHand(uid, slot, user);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Eject items from (some) slots when the entity is destroyed.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user