]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix ChemVend jugs again (#31398)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Sun, 25 Aug 2024 02:02:33 +0000 (04:02 +0200)
committerGitHub <noreply@github.com>
Sun, 25 Aug 2024 02:02:33 +0000 (12:02 +1000)
This re-introduces the dummy entity naming code, originally introduced in #29178 and randomly removed by #30064 with no technical justification given.

Fixes #31373

Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs

index efe6ef8e9ab35df6e94af35b1afd5abf312922cf..ee7a0e41faec7899eda373f9c62be46b68301408 100644 (file)
@@ -7,6 +7,7 @@ using Robust.Shared.Prototypes;
 using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow;
 using Robust.Client.UserInterface;
 using Content.Client.UserInterface.Controls;
+using Content.Shared.IdentityManagement;
 using Robust.Client.Graphics;
 
 namespace Content.Client.VendingMachines.UI
@@ -15,6 +16,9 @@ namespace Content.Client.VendingMachines.UI
     public sealed partial class VendingMachineMenu : FancyWindow
     {
         [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+        [Dependency] private readonly IEntityManager _entityManager = default!;
+
+        private readonly Dictionary<EntProtoId, EntityUid> _dummies = [];
 
         public event Action<GUIBoundKeyEventArgs, ListData>? OnItemSelected;
 
@@ -32,6 +36,22 @@ namespace Content.Client.VendingMachines.UI
             VendingContents.ItemKeyBindDown += (args, data) => OnItemSelected?.Invoke(args, data);
         }
 
+        protected override void Dispose(bool disposing)
+        {
+            base.Dispose(disposing);
+
+            // Don't clean up dummies during disposal or we'll just have to spawn them again
+            if (!disposing)
+                return;
+
+            // Delete any dummy items we spawned
+            foreach (var entity in _dummies.Values)
+            {
+                _entityManager.QueueDeleteEntity(entity);
+            }
+            _dummies.Clear();
+        }
+
         private bool DataFilterCondition(string filter, ListData data)
         {
             if (data is not VendorItemsListData { ItemText: var text })
@@ -91,7 +111,14 @@ namespace Content.Client.VendingMachines.UI
                 if (!_prototypeManager.TryIndex(entry.ID, out var prototype))
                     continue;
 
-                var itemText = $"{prototype.Name} [{entry.Amount}]";
+                if (!_dummies.TryGetValue(entry.ID, out var dummy))
+                {
+                    dummy = _entityManager.Spawn(entry.ID);
+                    _dummies.Add(entry.ID, dummy);
+                }
+
+                var itemName = Identity.Name(dummy, _entityManager);
+                var itemText = $"{itemName} [{entry.Amount}]";
 
                 if (itemText.Length > longestEntry.Length)
                     longestEntry = itemText;