]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
feat: allow removing empty smart fridge entries (#39195)
authorPerry Fraser <perryprog@users.noreply.github.com>
Fri, 9 Jan 2026 14:48:38 +0000 (09:48 -0500)
committerGitHub <noreply@github.com>
Fri, 9 Jan 2026 14:48:38 +0000 (14:48 +0000)
* feat: allow removing empty smart fridge entries

* review

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Client/SmartFridge/SmartFridgeBoundUserInterface.cs
Content.Client/SmartFridge/SmartFridgeItem.xaml
Content.Client/SmartFridge/SmartFridgeItem.xaml.cs
Content.Client/SmartFridge/SmartFridgeMenu.xaml.cs
Content.Shared/SmartFridge/SharedSmartFridgeSystem.cs
Content.Shared/SmartFridge/SmartFridgeComponent.cs

index 60d8ea413a5585cd4b6486ea35093a6e27d2234d..a364c8e6b9fae67b1588883530ca31cfec572d91 100644 (file)
@@ -19,12 +19,13 @@ public sealed class SmartFridgeBoundUserInterface : BoundUserInterface
 
         _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))
+        if (_menu is not { } menu || !EntMan.TryGetComponent(Owner, out SmartFridgeComponent? fridge))
             return;
 
         menu.SetFlavorText(Loc.GetString(fridge.FlavorText));
index 3960d7ce420073770714ae4fa01f8370a8f3d95e..17eb89801ee94d39ae238cf7ae0495d7fcbfadf0 100644 (file)
             SizeFlagsStretchRatio="3"
             HorizontalExpand="True"
             ClipText="True"/>
+    <TextureButton Name="RemoveButton"
+                   StyleClasses="CrossButtonRed"
+                   VerticalAlignment="Center"
+                   Margin="0 0 10 0"
+                   Scale="0.75 0.75"
+                   Visible="True" />
 </BoxContainer>
index c69d2e7de23726ff09e45b4a7d1033cfcabd3a98..1d1403878d057425a576a5b7310a363aae02ab76 100644 (file)
@@ -8,11 +8,18 @@ namespace Content.Client.SmartFridge;
 [GenerateTypedNameReferences]
 public sealed partial class SmartFridgeItem : BoxContainer
 {
+    public Action? RemoveButtonPressed;
+
     public SmartFridgeItem(EntityUid uid, string text)
     {
         RobustXamlLoader.Load(this);
 
         EntityView.SetEntity(uid);
         NameLabel.Text = text;
+
+        RemoveButton.OnPressed += _ => RemoveButtonPressed?.Invoke();
+
+        if (uid.IsValid())
+            RemoveButton.Visible = false;
     }
 }
index c896e7fada11396eaf1cd9e6822ac806361c4637..ee3b3a8e7a9747f50ca35a9c56c91fa4d23b8678 100644 (file)
@@ -17,6 +17,7 @@ public sealed partial class SmartFridgeMenu : FancyWindow
     [Dependency] private readonly IEntityManager _entityManager = default!;
 
     public event Action<GUIBoundKeyEventArgs, ListData>? OnItemSelected;
+    public event Action<SmartFridgeListData>? OnRemoveButtonPressed;
 
     private readonly StyleBoxFlat _styleBox = new() { BackgroundColor = new Color(70, 73, 102) };
 
@@ -48,8 +49,10 @@ public sealed partial class SmartFridgeMenu : FancyWindow
             return;
 
         var label = Loc.GetString("smart-fridge-list-item", ("item", entry.Entry.Name), ("amount", entry.Amount));
-        button.AddChild(new SmartFridgeItem(entry.Representative, label));
+        var item = new SmartFridgeItem(entry.Representative, label);
+        item.RemoveButtonPressed += () => OnRemoveButtonPressed?.Invoke(entry);
 
+        button.AddChild(item);
         button.ToolTip = label;
         button.StyleBoxOverride = _styleBox;
     }
index a331c3104d30dd5a15fda5994d1f7a99b867b428..7ad6cf9c28ecf36b48e37c20e54de410a77b6958 100644 (file)
@@ -41,6 +41,7 @@ public abstract class SharedSmartFridgeSystem : EntitySystem
             sub =>
             {
                 sub.Event<SmartFridgeDispenseItemMessage>(OnDispenseItem);
+                sub.Event<SmartFridgeRemoveEntryMessage>(OnRemoveEntry);
             });
     }
 
@@ -168,6 +169,22 @@ public abstract class SharedSmartFridgeSystem : EntitySystem
         });
     }
 
+    private void OnRemoveEntry(Entity<SmartFridgeComponent> ent, ref SmartFridgeRemoveEntryMessage args)
+    {
+        if (!Allowed(ent, args.Actor))
+            return;
+
+        if (!ent.Comp.ContainedEntries.TryGetValue(args.Entry, out var contained)
+            || contained.Count > 0
+            || !ent.Comp.Entries.Contains(args.Entry))
+            return;
+
+        ent.Comp.Entries.Remove(args.Entry);
+        ent.Comp.ContainedEntries.Remove(args.Entry);
+        Dirty(ent);
+        UpdateUI(ent);
+    }
+
     private void OnGetDumpableVerb(Entity<SmartFridgeComponent> ent, ref GetDumpableVerbEvent args)
     {
         if (_accessReader.IsAllowed(args.User, ent))
index 5bbd58b75d845c6be49734caa18142a50fbba682..552b50607bf361b6822d3d703040b2c59239b2d1 100644 (file)
@@ -75,6 +75,10 @@ public sealed partial class SmartFridgeComponent : Component
     public SoundSpecifier SoundDeny = new SoundCollectionSpecifier("VendingDeny");
 }
 
+/// <summary>
+/// A single entry in the smart fridge UI.
+/// May contain multiple items of the same type.
+/// </summary>
 [Serializable, NetSerializable, DataRecord]
 public partial record struct SmartFridgeEntry
 {
@@ -92,8 +96,20 @@ public enum SmartFridgeUiKey : byte
     Key,
 }
 
+/// <summary>
+/// Send by the client when trying to dispense an item inside the fridge.
+/// </summary>
 [Serializable, NetSerializable]
 public sealed class SmartFridgeDispenseItemMessage(SmartFridgeEntry entry) : BoundUserInterfaceMessage
 {
     public SmartFridgeEntry Entry = entry;
 }
+
+/// <summary>
+/// Send by the client when trying to remove an empty smart fridge entry from the list of items in the UI.
+/// </summary>
+[Serializable, NetSerializable]
+public sealed class SmartFridgeRemoveEntryMessage(SmartFridgeEntry entry) : BoundUserInterfaceMessage
+{
+    public SmartFridgeEntry Entry = entry;
+}