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:
ShadowCommander
2021-10-23 22:42:47 -07:00
committed by GitHub
parent 7de1ebbd77
commit d568664702
2 changed files with 24 additions and 10 deletions

View File

@@ -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)
{ {
SendNetworkMessage(new RemoveEntityMessage(entityUid)); if (buttonEventArgs.Event.Function == EngineKeyFunctions.UIClick)
{
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>

View File

@@ -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]
@@ -136,7 +136,7 @@ namespace Content.Client.UserInterface.Controls
#region Rebuild Children #region Rebuild Children
/* /*
* Example: * Example:
* *
* var _itemHeight = 32; * var _itemHeight = 32;
* var separation = 3; * var separation = 3;
* 32 | 32 | Control.Size.Y 0 * 32 | 32 | Control.Size.Y 0
@@ -146,13 +146,13 @@ namespace Content.Client.UserInterface.Controls
* 102 | 32 | Control.Size.Y 2 * 102 | 32 | Control.Size.Y 2
* 105 | 3 | Padding * 105 | 3 | Padding
* 137 | 32 | Control.Size.Y 3 * 137 | 32 | Control.Size.Y 3
* *
* If viewport height is 60 * If viewport height is 60
* visible should be 2 items (start = 0, end = 1) * visible should be 2 items (start = 0, end = 1)
* *
* scroll.Y = 11 * scroll.Y = 11
* visible should be 3 items (start = 0, end = 2) * visible should be 3 items (start = 0, end = 2)
* *
* start expected: 11 (item: 0) * start expected: 11 (item: 0)
* var start = (int) (scroll.Y * var start = (int) (scroll.Y
* *