Files
ss14-wega/Content.Client/_Wega/ItemSelector/ItemSelectorBoundUserInterface.cs
T
2026-06-01 23:58:02 +03:00

40 lines
1.1 KiB
C#

using Content.Shared.Item.Selector.UI;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Shared.Player;
namespace Content.Client._Wega.Item.Selector.UI;
[UsedImplicitly]
public sealed class ItemSelectorBoundUserInterface : BoundUserInterface
{
[Dependency] private ISharedPlayerManager _playerManager = default!;
[ViewVariables]
private ItemSelectorWindow? _window;
public ItemSelectorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { }
protected override void Open()
{
base.Open();
_window = this.CreateWindow<ItemSelectorWindow>();
_window.OnItemSelected += (selectedId) =>
{
var netEntity = EntMan.GetNetEntity(_playerManager.LocalSession?.AttachedEntity ?? EntityUid.Invalid);
SendMessage(new ItemSelectorSelectionMessage(netEntity, selectedId));
_window.Close();
};
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
if (_window == null || message is not ItemSelectorUserMessage msg)
return;
_window.Populate(msg);
}
}