Inventory slot enumerator rejig (#21788)
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
using Content.Client.Clothing;
|
||||
using Content.Client.Examine;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Client.Verbs.UI;
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory;
|
||||
@@ -15,14 +13,12 @@ using Robust.Client.UserInterface;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Inventory
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class ClientInventorySystem : InventorySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
||||
|
||||
@@ -89,7 +85,7 @@ namespace Content.Client.Inventory
|
||||
private void OnDidUnequip(InventorySlotsComponent component, DidUnequipEvent args)
|
||||
{
|
||||
UpdateSlot(args.Equipee, component, args.Slot);
|
||||
if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity)
|
||||
if (args.Equipee != _playerManager.LocalEntity)
|
||||
return;
|
||||
var update = new SlotSpriteUpdate(null, args.SlotGroup, args.Slot, false);
|
||||
OnSpriteUpdate?.Invoke(update);
|
||||
@@ -98,7 +94,7 @@ namespace Content.Client.Inventory
|
||||
private void OnDidEquip(InventorySlotsComponent component, DidEquipEvent args)
|
||||
{
|
||||
UpdateSlot(args.Equipee, component, args.Slot);
|
||||
if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity)
|
||||
if (args.Equipee != _playerManager.LocalEntity)
|
||||
return;
|
||||
var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot,
|
||||
HasComp<StorageComponent>(args.Equipment));
|
||||
@@ -107,10 +103,8 @@ namespace Content.Client.Inventory
|
||||
|
||||
private void OnShutdown(EntityUid uid, InventoryComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (uid != _playerManager.LocalPlayer?.ControlledEntity)
|
||||
return;
|
||||
|
||||
OnUnlinkInventory?.Invoke();
|
||||
if (uid == _playerManager.LocalEntity)
|
||||
OnUnlinkInventory?.Invoke();
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(EntityUid uid, InventorySlotsComponent component, LocalPlayerDetachedEvent args)
|
||||
@@ -151,13 +145,10 @@ namespace Content.Client.Inventory
|
||||
base.OnInit(uid, component, args);
|
||||
_clothingVisualsSystem.InitClothing(uid, component);
|
||||
|
||||
if (!_prototypeManager.TryIndex(component.TemplateId, out InventoryTemplatePrototype? invTemplate) ||
|
||||
!TryComp(uid, out InventorySlotsComponent? inventorySlots))
|
||||
{
|
||||
if (!TryComp(uid, out InventorySlotsComponent? inventorySlots))
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var slot in invTemplate.Slots)
|
||||
foreach (var slot in component.Slots)
|
||||
{
|
||||
TryAddSlotDef(uid, inventorySlots, slot);
|
||||
}
|
||||
@@ -165,7 +156,7 @@ namespace Content.Client.Inventory
|
||||
|
||||
public void ReloadInventory(InventorySlotsComponent? component = null)
|
||||
{
|
||||
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
var player = _playerManager.LocalEntity;
|
||||
if (player == null || !Resolve(player.Value, ref component, false))
|
||||
{
|
||||
return;
|
||||
@@ -179,7 +170,7 @@ namespace Content.Client.Inventory
|
||||
{
|
||||
var oldData = component.SlotData[slotName];
|
||||
var newData = component.SlotData[slotName] = new SlotData(oldData, state);
|
||||
if (owner == _playerManager.LocalPlayer?.ControlledEntity)
|
||||
if (owner == _playerManager.LocalEntity)
|
||||
EntitySlotUpdate?.Invoke(newData);
|
||||
}
|
||||
|
||||
@@ -198,7 +189,7 @@ namespace Content.Client.Inventory
|
||||
|
||||
var newData = component.SlotData[slotName] =
|
||||
new SlotData(component.SlotData[slotName], newHighlight, newBlocked);
|
||||
if (owner == _playerManager.LocalPlayer?.ControlledEntity)
|
||||
if (owner == _playerManager.LocalEntity)
|
||||
EntitySlotUpdate?.Invoke(newData);
|
||||
}
|
||||
|
||||
@@ -208,48 +199,11 @@ namespace Content.Client.Inventory
|
||||
if (!component.SlotData.TryAdd(newSlotDef.Name, newSlotData))
|
||||
return false;
|
||||
|
||||
if (owner == _playerManager.LocalPlayer?.ControlledEntity)
|
||||
if (owner == _playerManager.LocalEntity)
|
||||
OnSlotAdded?.Invoke(newSlotData);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveSlotDef(EntityUid owner, InventorySlotsComponent component, SlotData slotData)
|
||||
{
|
||||
if (component.SlotData.Remove(slotData.SlotName))
|
||||
{
|
||||
if (owner == _playerManager.LocalPlayer?.ControlledEntity)
|
||||
OnSlotRemoved?.Invoke(slotData);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveSlotDef(EntityUid owner, InventorySlotsComponent component, string slotName)
|
||||
{
|
||||
if (!component.SlotData.TryGetValue(slotName, out var slotData))
|
||||
return;
|
||||
|
||||
component.SlotData.Remove(slotName);
|
||||
|
||||
if (owner == _playerManager.LocalPlayer?.ControlledEntity)
|
||||
OnSlotRemoved?.Invoke(slotData);
|
||||
}
|
||||
|
||||
// TODO hud refactor This should also live in a UI Controller
|
||||
private void HoverInSlotButton(EntityUid uid, string slot, SlotControl control,
|
||||
InventoryComponent? inventoryComponent = null, HandsComponent? hands = null)
|
||||
{
|
||||
if (!Resolve(uid, ref inventoryComponent))
|
||||
return;
|
||||
|
||||
if (!Resolve(uid, ref hands, false))
|
||||
return;
|
||||
|
||||
if (hands.ActiveHandEntity is not EntityUid heldEntity)
|
||||
return;
|
||||
|
||||
if (!TryGetSlotContainer(uid, slot, out var containerSlot, out var slotDef, inventoryComponent))
|
||||
return;
|
||||
}
|
||||
|
||||
public void UIInventoryActivate(string slot)
|
||||
{
|
||||
EntityManager.RaisePredictiveEvent(new UseSlotNetworkMessage(slot));
|
||||
|
||||
Reference in New Issue
Block a user