Files
tbd-station-14/Content.Client/Storage/StorageBoundUserInterface.cs
Jacob Tong 09c6a5b252 Add Context Menu to Bwoink Window (#9374)
* Clean up EntityListDisplay

* Rename EntityListDisplay to ListContainer

* Rename stuff

* Rework ListContainer

* Add tests

* Replace IControlData with record ListData

* Make _data non-nullable

* Fix test record items being duplicates

* Split filter method from populate

* Rename UpdateList to DirtyList

* Replace _count with _data.Count

* Clarify local variable toRemove

* Cleanup

* Add data selection to ListContainer

* Add selection test

* Fix comments and test name

* Fix ListContainer layout hiding items when scaled

* Add test for ListContainer top item

* Toggle fix

* Ensure buttons are re-generated

* Update unread count on select

* a

* Fix toggle test

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2022-09-14 19:03:13 -05:00

92 lines
2.9 KiB
C#

using Content.Client.Storage.UI;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Content.Client.Items.Managers;
using Content.Client.UserInterface.Controls;
using JetBrains.Annotations;
using static Content.Shared.Storage.SharedStorageComponent;
namespace Content.Client.Storage
{
[UsedImplicitly]
public sealed class StorageBoundUserInterface : BoundUserInterface
{
[ViewVariables] private StorageWindow? _window;
public StorageBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
if (_window == null)
{
var entMan = IoCManager.Resolve<IEntityManager>();
_window = new StorageWindow(entMan) {Title = entMan.GetComponent<MetaDataComponent>(Owner.Owner).EntityName};
_window.EntityList.GenerateItem += _window.GenerateButton;
_window.EntityList.ItemPressed += InteractWithItem;
_window.StorageContainerButton.OnPressed += TouchedContainerButton;
_window.OnClose += Close;
_window.OpenCenteredLeft();
}
else
{
_window.Open();
}
}
public void InteractWithItem(BaseButton.ButtonEventArgs args, ListData cData)
{
if (cData is not EntityListData {Uid: var entity})
return;
if (args.Event.Function == EngineKeyFunctions.UIClick)
{
SendMessage(new StorageInteractWithItemEvent(entity));
}
else if (IoCManager.Resolve<IEntityManager>().EntityExists(entity))
{
IoCManager.Resolve<IItemSlotManager>().OnButtonPressed(args.Event, entity);
}
}
public void TouchedContainerButton(BaseButton.ButtonEventArgs args)
{
SendMessage(new StorageInsertItemMessage());
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_window == null || state is not StorageBoundUserInterfaceState cast)
return;
_window?.BuildEntityList(cast);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
if (_window != null)
{
_window.EntityList.GenerateItem -= _window.GenerateButton;
_window.EntityList.ItemPressed -= InteractWithItem;
_window.StorageContainerButton.OnPressed -= TouchedContainerButton;
_window.OnClose -= Close;
}
_window?.Dispose();
_window = null;
}
}
}