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:
committed by
GitHub
parent
b0375f115c
commit
d15869f600
@@ -7,6 +7,7 @@ using Robust.Shared.Prototypes;
|
|||||||
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow;
|
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Content.Client.UserInterface.Controls;
|
using Content.Client.UserInterface.Controls;
|
||||||
|
using Content.Shared.IdentityManagement;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
|
|
||||||
namespace Content.Client.VendingMachines.UI
|
namespace Content.Client.VendingMachines.UI
|
||||||
@@ -15,6 +16,9 @@ namespace Content.Client.VendingMachines.UI
|
|||||||
public sealed partial class VendingMachineMenu : FancyWindow
|
public sealed partial class VendingMachineMenu : FancyWindow
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
|
|
||||||
|
private readonly Dictionary<EntProtoId, EntityUid> _dummies = [];
|
||||||
|
|
||||||
public event Action<GUIBoundKeyEventArgs, ListData>? OnItemSelected;
|
public event Action<GUIBoundKeyEventArgs, ListData>? OnItemSelected;
|
||||||
|
|
||||||
@@ -32,6 +36,22 @@ namespace Content.Client.VendingMachines.UI
|
|||||||
VendingContents.ItemKeyBindDown += (args, data) => OnItemSelected?.Invoke(args, data);
|
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)
|
private bool DataFilterCondition(string filter, ListData data)
|
||||||
{
|
{
|
||||||
if (data is not VendorItemsListData { ItemText: var text })
|
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))
|
if (!_prototypeManager.TryIndex(entry.ID, out var prototype))
|
||||||
continue;
|
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)
|
if (itemText.Length > longestEntry.Length)
|
||||||
longestEntry = itemText;
|
longestEntry = itemText;
|
||||||
|
|||||||
Reference in New Issue
Block a user