From fc858f551b1e9cf832bc392a9c8cd29b901b9a0b Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Wed, 3 May 2023 22:40:38 -0700 Subject: [PATCH] Feature parity with vanilla client: making space for inventory items that aren't displayed causes them to appear --- EndlessClient/HUD/Panels/InventoryPanel.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/EndlessClient/HUD/Panels/InventoryPanel.cs b/EndlessClient/HUD/Panels/InventoryPanel.cs index d95cfea3..a83e58e9 100644 --- a/EndlessClient/HUD/Panels/InventoryPanel.cs +++ b/EndlessClient/HUD/Panels/InventoryPanel.cs @@ -256,6 +256,11 @@ protected override void OnUpdateControl(GameTime gameTime) } _cachedInventory = _characterInventoryProvider.ItemInventory.ToHashSet(); + + if (removed.Any()) + { + RemoveHiddenItemsFromCachedInventory(); + } } base.OnUpdateControl(gameTime); @@ -498,6 +503,10 @@ private void HandleItemDoneDragging(object sender, DragCompletedEventArgs childItems) _inventoryService.SetSlots(_inventorySlotRepository.FilledSlots, childItem.Slot, childItem.Data.Size); } + private void RemoveHiddenItemsFromCachedInventory() + { + // the item fits in the new slot, and there is no chained drag, snapback, or continued drag + // under these conditions, check if there are any items that don't have a matching childItem and remove them from the cached list + // the next update loop will detect these items as 'added' and attempt to show them in the empty space + + var notDisplayedItems = _cachedInventory.Where(x => _childItems.All(ci => x != ci.InventoryItem)); + _cachedInventory.RemoveWhere(notDisplayedItems.Contains); + } + private static IEnumerable GetOverlappingTakenSlots(int newSlot, ItemSize size, IEnumerable<(int Slot, ItemSize Size)> items) { var slotX = newSlot % InventoryRowSlots;