6
StarHorizon_Public/Content.Client/_DV/SmartFridge/SmartFridgeBoundUserInterface.cs
2025-11-03 10:15:18 +03:00

44 lines
1.1 KiB
C#

using Robust.Client.UserInterface;
using Robust.Shared.Input;
using Content.Client.UserInterface.Controls;
using Content.Shared._DV.SmartFridge;
namespace Content.Client._DV.SmartFridge;
public sealed class SmartFridgeBoundUserInterface : BoundUserInterface
{
private SmartFridgeMenu? _menu;
public SmartFridgeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_menu = this.CreateWindow<SmartFridgeMenu>();
_menu.OnItemSelected += OnItemSelected;
_menu.SetTitleFromEntity(EntMan, Owner); // Frontier
Refresh();
}
public void Refresh()
{
if (_menu is not {} menu || !EntMan.TryGetComponent(Owner, out SmartFridgeComponent? fridge))
return;
menu.Populate((Owner, fridge));
}
private void OnItemSelected(GUIBoundKeyEventArgs args, ListData data)
{
if (args.Function != EngineKeyFunctions.UIClick)
return;
if (data is not SmartFridgeListData entry)
return;
SendPredictedMessage(new SmartFridgeDispenseItemMessage(entry.Entry));
}
}