Storage fixes (#36533)
* Storage fixes - Add size event. - Fix reclaim not running always. * Block the toggles * Standardise and popup explaining * Disable item toggles in bags * Fix verb popping up even if we can't activate * Conflicts * Validate * Stop drags if source closes * Really fixes * Real fix * Revert this
This commit is contained in:
@@ -16,6 +16,7 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Components;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Item.ItemToggle.Components;
|
||||
using Content.Shared.Lock;
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Placeable;
|
||||
@@ -146,13 +147,13 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
SubscribeLocalEvent<StorageComponent, BoundUserInterfaceMessageAttempt>(OnBoundUIAttempt);
|
||||
SubscribeLocalEvent<StorageComponent, BoundUIOpenedEvent>(OnBoundUIOpen);
|
||||
SubscribeLocalEvent<StorageComponent, LockToggledEvent>(OnLockToggled);
|
||||
SubscribeLocalEvent<MetaDataComponent, StackCountChangedEvent>(OnStackCountChanged);
|
||||
|
||||
SubscribeLocalEvent<StorageComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
|
||||
SubscribeLocalEvent<StorageComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
SubscribeLocalEvent<StorageComponent, ContainerIsInsertingAttemptEvent>(OnInsertAttempt);
|
||||
|
||||
SubscribeLocalEvent<StorageComponent, AreaPickupDoAfterEvent>(OnDoAfter);
|
||||
SubscribeLocalEvent<StorageComponent, GotReclaimedEvent>(OnReclaimed);
|
||||
|
||||
SubscribeLocalEvent<MetaDataComponent, StackCountChangedEvent>(OnStackCountChanged);
|
||||
|
||||
SubscribeAllEvent<OpenNestedStorageEvent>(OnStorageNested);
|
||||
SubscribeAllEvent<StorageTransferItemEvent>(OnStorageTransfer);
|
||||
@@ -161,7 +162,7 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
SubscribeAllEvent<StorageInsertItemIntoLocationEvent>(OnInsertItemIntoLocation);
|
||||
SubscribeAllEvent<StorageSaveItemLocationEvent>(OnSaveItemLocation);
|
||||
|
||||
SubscribeLocalEvent<StorageComponent, GotReclaimedEvent>(OnReclaimed);
|
||||
SubscribeLocalEvent<ItemSizeChangedEvent>(OnItemSizeChanged);
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.OpenBackpack, InputCmdHandler.FromDelegate(HandleOpenBackpack, handle: false))
|
||||
@@ -173,6 +174,21 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
UpdatePrototypeCache();
|
||||
}
|
||||
|
||||
private void OnItemSizeChanged(ref ItemSizeChangedEvent ev)
|
||||
{
|
||||
var itemEnt = new Entity<ItemComponent?>(ev.Entity, null);
|
||||
|
||||
if (!TryGetStorageLocation(itemEnt, out var container, out var storage, out var loc))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ItemFitsInGridLocation((itemEnt.Owner, itemEnt.Comp), (container.Owner, storage), loc))
|
||||
{
|
||||
ContainerSystem.Remove(itemEnt.Owner, container, force: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNestedStorageCvar(bool obj)
|
||||
{
|
||||
NestedStorage = obj;
|
||||
@@ -322,6 +338,25 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the storage location of an item.
|
||||
/// </summary>
|
||||
public bool TryGetStorageLocation(Entity<ItemComponent?> itemEnt, [NotNullWhen(true)] out BaseContainer? container, out StorageComponent? storage, out ItemStorageLocation loc)
|
||||
{
|
||||
loc = default;
|
||||
storage = null;
|
||||
|
||||
if (!ContainerSystem.TryGetContainingContainer(itemEnt, out container) ||
|
||||
!TryComp(container.Owner, out storage) ||
|
||||
!_itemQuery.Resolve(itemEnt, ref itemEnt.Comp, false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
loc = storage.StoredItems[itemEnt];
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OpenStorageUI(EntityUid uid, EntityUid actor, StorageComponent? storageComp = null, bool silent = true)
|
||||
{
|
||||
// Handle recursively opening nested storages.
|
||||
@@ -719,14 +754,23 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
|
||||
private void OnStorageTransfer(StorageTransferItemEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!TryGetEntity(msg.ItemEnt, out var itemEnt))
|
||||
if (!TryGetEntity(msg.ItemEnt, out var itemUid) || !TryComp(itemUid, out ItemComponent? itemComp))
|
||||
return;
|
||||
|
||||
var localPlayer = args.SenderSession.AttachedEntity;
|
||||
var itemEnt = new Entity<ItemComponent?>(itemUid.Value, itemComp);
|
||||
|
||||
if (!TryComp(localPlayer, out HandsComponent? handsComp) || !_sharedHandsSystem.TryPickup(localPlayer.Value, itemEnt.Value, handsComp: handsComp, animate: false))
|
||||
// Validate the source storage
|
||||
if (!TryGetStorageLocation(itemEnt, out var container, out _, out _) ||
|
||||
!ValidateInput(args, GetNetEntity(container.Owner), out _, out _))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryComp(localPlayer, out HandsComponent? handsComp) || !_sharedHandsSystem.TryPickup(localPlayer.Value, itemEnt, handsComp: handsComp, animate: false))
|
||||
return;
|
||||
|
||||
// Validate the target storage
|
||||
if (!ValidateInput(args, msg.StorageEnt, msg.ItemEnt, out var player, out var storage, out var item, held: true))
|
||||
return;
|
||||
|
||||
@@ -1525,6 +1569,8 @@ public abstract class SharedStorageSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void HandleOpenBackpack(ICommonSession? session)
|
||||
{
|
||||
HandleToggleSlotUI(session, "back");
|
||||
|
||||
Reference in New Issue
Block a user