mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-02-14 23:14:45 +01:00
* feat: allow removing empty smart fridge entries * review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.SmartFridge;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Shared.Input;
|
|
|
|
namespace Content.Client.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.OnRemoveButtonPressed += data => SendPredictedMessage(new SmartFridgeRemoveEntryMessage(data.Entry));
|
|
Refresh();
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if (_menu is not { } menu || !EntMan.TryGetComponent(Owner, out SmartFridgeComponent? fridge))
|
|
return;
|
|
|
|
menu.SetFlavorText(Loc.GetString(fridge.FlavorText));
|
|
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));
|
|
}
|
|
}
|