Add examine, activate, and context menu to storage buttons (#4525)
* Add examine, activate, and context menu to storage buttons * Handle UIClick
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Client.Animations;
|
using Content.Client.Animations;
|
||||||
using Content.Client.Hands;
|
using Content.Client.Hands;
|
||||||
|
using Content.Client.Items.Managers;
|
||||||
using Content.Client.Items.Components;
|
using Content.Client.Items.Components;
|
||||||
using Content.Client.UserInterface.Controls;
|
using Content.Client.UserInterface.Controls;
|
||||||
using Content.Shared.DragDrop;
|
using Content.Shared.DragDrop;
|
||||||
@@ -15,6 +16,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.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
@@ -31,6 +33,8 @@ namespace Content.Client.Storage
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class ClientStorageComponent : SharedStorageComponent, IDraggable
|
public class ClientStorageComponent : SharedStorageComponent, IDraggable
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IItemSlotManager _itemSlotManager = default!;
|
||||||
|
|
||||||
private List<IEntity> _storedEntities = new();
|
private List<IEntity> _storedEntities = new();
|
||||||
private int StorageSizeUsed;
|
private int StorageSizeUsed;
|
||||||
private int StorageCapacityMax;
|
private int StorageCapacityMax;
|
||||||
@@ -172,9 +176,17 @@ namespace Content.Client.Storage
|
|||||||
/// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity
|
/// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entityUid"></param>
|
/// <param name="entityUid"></param>
|
||||||
private void Interact(EntityUid entityUid)
|
private void Interact(BaseButton.ButtonEventArgs buttonEventArgs, EntityUid entityUid)
|
||||||
|
{
|
||||||
|
if (buttonEventArgs.Event.Function == EngineKeyFunctions.UIClick)
|
||||||
{
|
{
|
||||||
SendNetworkMessage(new RemoveEntityMessage(entityUid));
|
SendNetworkMessage(new RemoveEntityMessage(entityUid));
|
||||||
|
buttonEventArgs.Event.Handle();
|
||||||
|
}
|
||||||
|
else if (Owner.EntityManager.TryGetEntity(entityUid, out var entity))
|
||||||
|
{
|
||||||
|
_itemSlotManager.OnButtonPressed(buttonEventArgs.Event, entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Remove(IEntity entity)
|
public override bool Remove(IEntity entity)
|
||||||
@@ -191,7 +203,7 @@ namespace Content.Client.Storage
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label
|
/// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void GenerateButton(EntityUid entityUid, Control button)
|
private void GenerateButton(EntityUid entityUid, EntityContainerButton button)
|
||||||
{
|
{
|
||||||
if (!Owner.EntityManager.TryGetEntity(entityUid, out var entity))
|
if (!Owner.EntityManager.TryGetEntity(entityUid, out var entity))
|
||||||
return;
|
return;
|
||||||
@@ -226,6 +238,8 @@ namespace Content.Client.Storage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
button.EnableAllKeybinds = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ namespace Content.Client.UserInterface.Controls
|
|||||||
public const string StylePropertySeparation = "separation";
|
public const string StylePropertySeparation = "separation";
|
||||||
|
|
||||||
public int? SeparationOverride { get; set; }
|
public int? SeparationOverride { get; set; }
|
||||||
public Action<EntityUid, Control>? GenerateItem;
|
public Action<EntityUid, EntityContainerButton>? GenerateItem;
|
||||||
public Action<EntityUid>? ItemPressed;
|
public Action<BaseButton.ButtonEventArgs, EntityUid>? ItemPressed;
|
||||||
|
|
||||||
private const int DefaultSeparation = 3;
|
private const int DefaultSeparation = 3;
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ namespace Content.Client.UserInterface.Controls
|
|||||||
{
|
{
|
||||||
if (args.Button is not EntityContainerButton button)
|
if (args.Button is not EntityContainerButton button)
|
||||||
return;
|
return;
|
||||||
ItemPressed?.Invoke(button.EntityUid);
|
ItemPressed?.Invoke(args, button.EntityUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Pure]
|
[Pure]
|
||||||
|
|||||||
Reference in New Issue
Block a user