From a13c0a91dfca8433bf99a85e5e2aadaf989d29cf Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 18 Jun 2024 16:27:21 -0400 Subject: [PATCH 1/2] Spawn dummy entities on client for vending machine UI --- .../UI/VendingMachineMenu.xaml.cs | 32 +++++++++++++++++-- Content.Server/Labels/Label/LabelSystem.cs | 16 +--------- .../Labels/EntitySystems/SharedLabelSystem.cs | 13 ++++++++ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs b/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs index 8b53290f7fb8..86353c6ae48b 100644 --- a/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs +++ b/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs @@ -4,10 +4,11 @@ using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.UserInterface.Controls; -using Content.Client.Stylesheets; using Robust.Client.UserInterface.XAML; using Robust.Shared.Prototypes; using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow; +using Content.Shared.IdentityManagement; +using Robust.Shared.Timing; namespace Content.Client.VendingMachines.UI { @@ -15,6 +16,10 @@ namespace Content.Client.VendingMachines.UI public sealed partial class VendingMachineMenu : FancyWindow { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IGameTiming _timing = default!; + + private readonly Dictionary _dummies = []; public event Action? OnItemSelected; public event Action? OnSearchChanged; @@ -36,6 +41,22 @@ public VendingMachineMenu() }; } + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + // Don't clean up dummies during prediction or we'll just have to spawn them again + if (!disposing || !_timing.IsFirstTimePredicted) + return; + + // Delete any dummy items we spawned + foreach (var entity in _dummies.Values) + { + _entityManager.QueueDeleteEntity(entity); + } + _dummies.Clear(); + } + /// /// Populates the list of available items on the vending machine interface /// and sets icons based on their prototypes @@ -72,11 +93,16 @@ public void Populate(List inventory, out List vendingItem.Text = string.Empty; vendingItem.Icon = null; - var itemName = entry.ID; + if (!_dummies.TryGetValue(entry.ID, out var dummy)) + { + dummy = _entityManager.Spawn(entry.ID); + _dummies.Add(entry.ID, dummy); + } + + var itemName = Identity.Name(dummy, _entityManager); Texture? icon = null; if (_prototypeManager.TryIndex(entry.ID, out var prototype)) { - itemName = prototype.Name; icon = spriteSystem.GetPrototypeIcon(prototype).Default; } diff --git a/Content.Server/Labels/Label/LabelSystem.cs b/Content.Server/Labels/Label/LabelSystem.cs index 17d18918fea2..cbf29e16a266 100644 --- a/Content.Server/Labels/Label/LabelSystem.cs +++ b/Content.Server/Labels/Label/LabelSystem.cs @@ -5,7 +5,6 @@ using Content.Shared.Labels; using Content.Shared.Labels.Components; using Content.Shared.Labels.EntitySystems; -using Content.Shared.NameModifier.EntitySystems; using JetBrains.Annotations; using Robust.Shared.Containers; @@ -19,7 +18,6 @@ public sealed class LabelSystem : SharedLabelSystem { [Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; - [Dependency] private readonly NameModifierSystem _nameMod = default!; public const string ContainerName = "paper_label"; @@ -27,7 +25,6 @@ public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnLabelCompMapInit); SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnComponentRemove); SubscribeLocalEvent(OnContainerModified); @@ -35,17 +32,6 @@ public override void Initialize() SubscribeLocalEvent(OnExamined); } - private void OnLabelCompMapInit(EntityUid uid, LabelComponent component, MapInitEvent args) - { - if (!string.IsNullOrEmpty(component.CurrentLabel)) - { - component.CurrentLabel = Loc.GetString(component.CurrentLabel); - Dirty(uid, component); - } - - _nameMod.RefreshNameModifiers(uid); - } - /// /// Apply or remove a label on an entity. /// @@ -59,7 +45,7 @@ public override void Label(EntityUid uid, string? text, MetaDataComponent? metad label = EnsureComp(uid); label.CurrentLabel = text; - _nameMod.RefreshNameModifiers(uid); + NameMod.RefreshNameModifiers(uid); Dirty(uid, label); } diff --git a/Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs b/Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs index f1998e524d90..eb3a0f185b9b 100644 --- a/Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs +++ b/Content.Shared/Labels/EntitySystems/SharedLabelSystem.cs @@ -7,14 +7,27 @@ namespace Content.Shared.Labels.EntitySystems; public abstract partial class SharedLabelSystem : EntitySystem { + [Dependency] protected readonly NameModifierSystem NameMod = default!; public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnLabelCompMapInit); SubscribeLocalEvent(OnExamine); SubscribeLocalEvent(OnRefreshNameModifiers); } + private void OnLabelCompMapInit(EntityUid uid, LabelComponent component, MapInitEvent args) + { + if (!string.IsNullOrEmpty(component.CurrentLabel)) + { + component.CurrentLabel = Loc.GetString(component.CurrentLabel); + Dirty(uid, component); + } + + NameMod.RefreshNameModifiers(uid); + } + public virtual void Label(EntityUid uid, string? text, MetaDataComponent? metadata = null, LabelComponent? label = null){} private void OnExamine(EntityUid uid, LabelComponent? label, ExaminedEvent args) From facfeac0f478306cf432fcf5fd2601c332d1236d Mon Sep 17 00:00:00 2001 From: Vasilis Date: Sun, 23 Jun 2024 19:19:03 +0200 Subject: [PATCH 2/2] Asked sloth, and we kinda need this pr --- Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs b/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs index 86353c6ae48b..2c71fa8c40ef 100644 --- a/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs +++ b/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs @@ -45,8 +45,8 @@ protected override void Dispose(bool disposing) { base.Dispose(disposing); - // Don't clean up dummies during prediction or we'll just have to spawn them again - if (!disposing || !_timing.IsFirstTimePredicted) + // 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