From 007f4c6cbe5cf179f9e50712a748beaee05a6065 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Sat, 1 Jan 2022 14:35:30 -0800 Subject: [PATCH] Fix inventory UI not showing entities (#5981) * Update inventory UI on init * Add resolve pattern * Update Content.Client/Inventory/ClientInventorySystem.cs Co-authored-by: Paul Ritter * Fix errors Co-authored-by: Paul Ritter --- .../Inventory/ClientInventorySystem.cs | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/Content.Client/Inventory/ClientInventorySystem.cs b/Content.Client/Inventory/ClientInventorySystem.cs index 52dfb92c67..3299ead78c 100644 --- a/Content.Client/Inventory/ClientInventorySystem.cs +++ b/Content.Client/Inventory/ClientInventorySystem.cs @@ -17,6 +17,7 @@ using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Configuration; +using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Input; using Robust.Shared.Input.Binding; @@ -85,23 +86,30 @@ namespace Content.Client.Inventory private void OnDidUnequip(EntityUid uid, ClientInventoryComponent component, DidUnequipEvent args) { - if (component.SlotButtons.TryGetValue(args.Slot, out var buttons)) - { - foreach (var button in buttons) - { - _itemSlotManager.SetItemSlot(button, null); - } - } + UpdateComponentUISlot(uid, args.Slot, null, component); } private void OnDidEquip(EntityUid uid, ClientInventoryComponent component, DidEquipEvent args) { - if (component.SlotButtons.TryGetValue(args.Slot, out var buttons)) + UpdateComponentUISlot(uid, args.Slot, args.Equipment, component); + } + + private void UpdateComponentUISlot(EntityUid uid, string slot, EntityUid? item, ClientInventoryComponent? component = null) + { + if (!Resolve(uid, ref component)) + return; + + if (!component.SlotButtons.TryGetValue(slot, out var buttons)) + return; + + UpdateUISlot(buttons, item); + } + + private void UpdateUISlot(List buttons, EntityUid? entity) + { + foreach (var button in buttons) { - foreach (var button in buttons) - { - _itemSlotManager.SetItemSlot(button, args.Equipment); - } + _itemSlotManager.SetItemSlot(button, entity); } } @@ -166,6 +174,17 @@ namespace Content.Client.Inventory component)) return; + if (TryComp(uid, out var containerManager)) + { + foreach (var (slot, buttons) in component.SlotButtons) + { + if (!TryGetSlotEntity(uid, slot, out var entity, component, containerManager)) + continue; + + UpdateUISlot(buttons, entity); + } + } + component.InventoryWindow = window; component.BottomLeftButtons = bottomLeft; component.BottomRightButtons = bottomRight;