Fix ChemVend jugs again (#31398)

This re-introduces the dummy entity naming code, originally introduced in #29178 and randomly removed by #30064 with no technical justification given.

Fixes #31373
This commit is contained in:
Pieter-Jan Briers
2024-08-25 04:02:33 +02:00
committed by GitHub
parent b0375f115c
commit d15869f600

View 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;