Files
Delta-v/Content.Client/_DV/SmartFridge/SmartFridgeBoundUserInterface.cs
T
Perry Fraser f488526f87 feat: Allow removing empty SmartFridge entries (#3852)
* feat: Allow removing empty SmartFridge entries

* tweak: debounce SmartFridge ejects

* tweak: address review comments

Formatting, IsFirstTimePredicted exists, don't give malf clients polite popups.
2025-05-31 00:00:58 +00:00

49 lines
1.3 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.OnRemoveButtonPressed += OnRemoveButtonPressed;
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));
}
private void OnRemoveButtonPressed(SmartFridgeListData data)
{
SendPredictedMessage(new SmartFridgeRemoveEntryMessage(data.Entry));
}
}