Fix inventory button hover indicators not appearing anymore (#11880)
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
using Content.Client.Inventory;
|
using static Content.Client.Inventory.ClientInventorySystem;
|
||||||
|
|
||||||
namespace Content.Client.UserInterface.Controls
|
namespace Content.Client.UserInterface.Controls
|
||||||
{
|
{
|
||||||
public sealed class SlotButton : SlotControl
|
public sealed class SlotButton : SlotControl
|
||||||
{
|
{
|
||||||
public SlotButton(){}
|
public SlotButton() { }
|
||||||
|
|
||||||
public SlotButton(ClientInventorySystem.SlotData slotData)
|
public SlotButton(SlotData slotData)
|
||||||
{
|
{
|
||||||
ButtonTexturePath = slotData.TextureName;
|
ButtonTexturePath = slotData.TextureName;
|
||||||
Blocked = slotData.Blocked;
|
Blocked = slotData.Blocked;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Client.Gameplay;
|
using Content.Client.Gameplay;
|
||||||
|
using Content.Client.Hands;
|
||||||
using Content.Client.Inventory;
|
using Content.Client.Inventory;
|
||||||
using Content.Client.Storage;
|
using Content.Client.Storage;
|
||||||
using Content.Client.UserInterface.Controls;
|
using Content.Client.UserInterface.Controls;
|
||||||
@@ -11,6 +12,7 @@ using Robust.Client.UserInterface.Controllers;
|
|||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Shared.Input;
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.Input.Binding;
|
using Robust.Shared.Input.Binding;
|
||||||
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using static Content.Client.Inventory.ClientInventorySystem;
|
using static Content.Client.Inventory.ClientInventorySystem;
|
||||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||||
@@ -68,6 +70,16 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
|||||||
CommandBinds.Unregister<ClientInventorySystem>();
|
CommandBinds.Unregister<ClientInventorySystem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
public void RegisterInventoryBarContainer(ItemSlotButtonContainer inventoryHotbar)
|
||||||
{
|
{
|
||||||
_inventoryHotbar = inventoryHotbar;
|
_inventoryHotbar = inventoryHotbar;
|
||||||
@@ -93,9 +105,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
|||||||
|
|
||||||
if (!container.TryGetButton(data.SlotName, out var button))
|
if (!container.TryGetButton(data.SlotName, out var button))
|
||||||
{
|
{
|
||||||
button = new SlotButton(data);
|
button = CreateSlotButton(data);
|
||||||
button.Pressed += ItemPressed;
|
|
||||||
button.StoragePressed += StoragePressed;
|
|
||||||
container.AddButton(button);
|
container.AddButton(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,9 +131,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
|||||||
|
|
||||||
if (!_strippingWindow!.InventoryButtons.TryGetButton(data.SlotName, out var button))
|
if (!_strippingWindow!.InventoryButtons.TryGetButton(data.SlotName, out var button))
|
||||||
{
|
{
|
||||||
button = new SlotButton(data);
|
button = CreateSlotButton(data);
|
||||||
button.Pressed += ItemPressed;
|
|
||||||
button.StoragePressed += StoragePressed;
|
|
||||||
_strippingWindow!.InventoryButtons.AddButton(button, data.ButtonOffset);
|
_strippingWindow!.InventoryButtons.AddButton(button, data.ButtonOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,6 +207,12 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.Function == ContentKeyFunctions.ActivateItemInWorld)
|
||||||
|
{
|
||||||
|
_inventorySystem.UIInventoryStorageActivate(control.SlotName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_playerInventory == null)
|
if (_playerInventory == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -227,14 +241,39 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
|||||||
_inventorySystem.UIInventoryStorageActivate(control.SlotName);
|
_inventorySystem.UIInventoryStorageActivate(control.SlotName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SlotButtonHovered(GUIMouseHoverEventArgs args, SlotControl control)
|
||||||
|
{
|
||||||
|
var player = _playerInventory?.Owner;
|
||||||
|
|
||||||
|
if (!control.MouseIsHovering ||
|
||||||
|
_playerInventory == null ||
|
||||||
|
!_entities.TryGetComponent<HandsComponent>(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<SpriteComponent>(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)
|
private void AddSlot(SlotData data)
|
||||||
{
|
{
|
||||||
if (!_slotGroups.TryGetValue(data.SlotGroup, out var slotGroup))
|
if (!_slotGroups.TryGetValue(data.SlotGroup, out var slotGroup))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var button = new SlotButton(data);
|
var button = CreateSlotButton(data);
|
||||||
button.Pressed += ItemPressed;
|
|
||||||
button.StoragePressed += StoragePressed;
|
|
||||||
slotGroup.AddButton(button);
|
slotGroup.AddButton(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user