diff --git a/Content.Client/UserInterface/Controls/SlotButton.cs b/Content.Client/UserInterface/Controls/SlotButton.cs index eaf1372349..4ec6861606 100644 --- a/Content.Client/UserInterface/Controls/SlotButton.cs +++ b/Content.Client/UserInterface/Controls/SlotButton.cs @@ -1,12 +1,12 @@ -using Content.Client.Inventory; +using static Content.Client.Inventory.ClientInventorySystem; namespace Content.Client.UserInterface.Controls { public sealed class SlotButton : SlotControl { - public SlotButton(){} + public SlotButton() { } - public SlotButton(ClientInventorySystem.SlotData slotData) + public SlotButton(SlotData slotData) { ButtonTexturePath = slotData.TextureName; Blocked = slotData.Blocked; diff --git a/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs b/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs index 85698354d2..65e690c803 100644 --- a/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs +++ b/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs @@ -1,4 +1,5 @@ using Content.Client.Gameplay; +using Content.Client.Hands; using Content.Client.Inventory; using Content.Client.Storage; using Content.Client.UserInterface.Controls; @@ -11,6 +12,7 @@ using Robust.Client.UserInterface.Controllers; using Robust.Client.UserInterface.Controls; using Robust.Shared.Input; using Robust.Shared.Input.Binding; +using Robust.Shared.Map; using Robust.Shared.Utility; using static Content.Client.Inventory.ClientInventorySystem; using static Robust.Client.UserInterface.Controls.BaseButton; @@ -68,6 +70,16 @@ public sealed class InventoryUIController : UIController, IOnStateEntered(); } + private SlotButton CreateSlotButton(SlotData data) + { + var button = new SlotButton(data); + button.Pressed += ItemPressed; + button.StoragePressed += StoragePressed; + button.Hover += SlotButtonHovered; + + return button; + } + public void RegisterInventoryBarContainer(ItemSlotButtonContainer inventoryHotbar) { _inventoryHotbar = inventoryHotbar; @@ -93,9 +105,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered(player, out var hands) || + hands.ActiveHandEntity is not { } held || + !_entities.TryGetComponent(held, out SpriteComponent? sprite) || + !_inventorySystem.TryGetSlotContainer(player.Value, control.SlotName, out var container, out var slotDef, _playerInventory)) + { + control.ClearHover(); + return; + } + + // Set green / red overlay at 50% transparency + var hoverEntity = _entities.SpawnEntity("hoverentity", MapCoordinates.Nullspace); + var hoverSprite = _entities.GetComponent(hoverEntity); + var fits = _inventorySystem.CanEquip(player.Value, held, control.SlotName, out _, slotDef, _playerInventory) && + container.CanInsert(held, _entities); + + hoverSprite.CopyFrom(sprite); + hoverSprite.Color = fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127); + + control.HoverSpriteView.Sprite = hoverSprite; + } + private void AddSlot(SlotData data) { if (!_slotGroups.TryGetValue(data.SlotGroup, out var slotGroup)) return; - var button = new SlotButton(data); - button.Pressed += ItemPressed; - button.StoragePressed += StoragePressed; + var button = CreateSlotButton(data); slotGroup.AddButton(button); }