Skip to content

Commit

Permalink
Feature parity with vanilla client: making space for inventory items …
Browse files Browse the repository at this point in the history
…that aren't displayed causes them to appear
  • Loading branch information
ethanmoffat committed May 4, 2023
1 parent 4dd21ea commit fc858f5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions EndlessClient/HUD/Panels/InventoryPanel.cs
Expand Up @@ -256,6 +256,11 @@ protected override void OnUpdateControl(GameTime gameTime)
}

_cachedInventory = _characterInventoryProvider.ItemInventory.ToHashSet();

if (removed.Any())
{
RemoveHiddenItemsFromCachedInventory();
}
}

base.OnUpdateControl(gameTime);
Expand Down Expand Up @@ -498,6 +503,10 @@ private void HandleItemDoneDragging(object sender, DragCompletedEventArgs<EIFRec
e.RestoreOriginalSlot = true;
}
}
else
{
RemoveHiddenItemsFromCachedInventory();
}
}
}

Expand All @@ -510,6 +519,16 @@ private void ResetSlotMap(IEnumerable<InventoryPanelItem> 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<int> GetOverlappingTakenSlots(int newSlot, ItemSize size, IEnumerable<(int Slot, ItemSize Size)> items)
{
var slotX = newSlot % InventoryRowSlots;
Expand Down

0 comments on commit fc858f5

Please sign in to comment.