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 <ritter.paul1@googlemail.com> * Fix errors Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
This commit is contained in:
@@ -17,6 +17,7 @@ using Robust.Client.UserInterface;
|
|||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Input;
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.Input.Binding;
|
using Robust.Shared.Input.Binding;
|
||||||
@@ -85,23 +86,30 @@ namespace Content.Client.Inventory
|
|||||||
|
|
||||||
private void OnDidUnequip(EntityUid uid, ClientInventoryComponent component, DidUnequipEvent args)
|
private void OnDidUnequip(EntityUid uid, ClientInventoryComponent component, DidUnequipEvent args)
|
||||||
{
|
{
|
||||||
if (component.SlotButtons.TryGetValue(args.Slot, out var buttons))
|
UpdateComponentUISlot(uid, args.Slot, null, component);
|
||||||
{
|
|
||||||
foreach (var button in buttons)
|
|
||||||
{
|
|
||||||
_itemSlotManager.SetItemSlot(button, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDidEquip(EntityUid uid, ClientInventoryComponent component, DidEquipEvent args)
|
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<ItemSlotButton> 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))
|
component))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (TryComp<ContainerManagerComponent>(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.InventoryWindow = window;
|
||||||
component.BottomLeftButtons = bottomLeft;
|
component.BottomLeftButtons = bottomLeft;
|
||||||
component.BottomRightButtons = bottomRight;
|
component.BottomRightButtons = bottomRight;
|
||||||
|
|||||||
Reference in New Issue
Block a user