Fix unlabeled jugs in ChemVend (#29178)
* Spawn dummy entities on client for vending machine UI * Asked sloth, and we kinda need this pr --------- Co-authored-by: Vasilis <vasilis@pikachu.systems>
This commit is contained in:
@@ -4,10 +4,11 @@ using Robust.Client.AutoGenerated;
|
|||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Content.Client.Stylesheets;
|
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow;
|
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow;
|
||||||
|
using Content.Shared.IdentityManagement;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Client.VendingMachines.UI
|
namespace Content.Client.VendingMachines.UI
|
||||||
{
|
{
|
||||||
@@ -15,6 +16,10 @@ 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!;
|
||||||
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
|
|
||||||
|
private readonly Dictionary<EntProtoId, EntityUid> _dummies = [];
|
||||||
|
|
||||||
public event Action<ItemList.ItemListSelectedEventArgs>? OnItemSelected;
|
public event Action<ItemList.ItemListSelectedEventArgs>? OnItemSelected;
|
||||||
public event Action<string>? OnSearchChanged;
|
public event Action<string>? OnSearchChanged;
|
||||||
@@ -36,6 +41,22 @@ namespace Content.Client.VendingMachines.UI
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Populates the list of available items on the vending machine interface
|
/// Populates the list of available items on the vending machine interface
|
||||||
/// and sets icons based on their prototypes
|
/// and sets icons based on their prototypes
|
||||||
@@ -72,11 +93,16 @@ namespace Content.Client.VendingMachines.UI
|
|||||||
vendingItem.Text = string.Empty;
|
vendingItem.Text = string.Empty;
|
||||||
vendingItem.Icon = null;
|
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;
|
Texture? icon = null;
|
||||||
if (_prototypeManager.TryIndex<EntityPrototype>(entry.ID, out var prototype))
|
if (_prototypeManager.TryIndex<EntityPrototype>(entry.ID, out var prototype))
|
||||||
{
|
{
|
||||||
itemName = prototype.Name;
|
|
||||||
icon = spriteSystem.GetPrototypeIcon(prototype).Default;
|
icon = spriteSystem.GetPrototypeIcon(prototype).Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ using Content.Shared.Examine;
|
|||||||
using Content.Shared.Labels;
|
using Content.Shared.Labels;
|
||||||
using Content.Shared.Labels.Components;
|
using Content.Shared.Labels.Components;
|
||||||
using Content.Shared.Labels.EntitySystems;
|
using Content.Shared.Labels.EntitySystems;
|
||||||
using Content.Shared.NameModifier.EntitySystems;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
|
|
||||||
@@ -19,7 +18,6 @@ namespace Content.Server.Labels
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
[Dependency] private readonly NameModifierSystem _nameMod = default!;
|
|
||||||
|
|
||||||
public const string ContainerName = "paper_label";
|
public const string ContainerName = "paper_label";
|
||||||
|
|
||||||
@@ -27,7 +25,6 @@ namespace Content.Server.Labels
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<LabelComponent, MapInitEvent>(OnLabelCompMapInit);
|
|
||||||
SubscribeLocalEvent<PaperLabelComponent, ComponentInit>(OnComponentInit);
|
SubscribeLocalEvent<PaperLabelComponent, ComponentInit>(OnComponentInit);
|
||||||
SubscribeLocalEvent<PaperLabelComponent, ComponentRemove>(OnComponentRemove);
|
SubscribeLocalEvent<PaperLabelComponent, ComponentRemove>(OnComponentRemove);
|
||||||
SubscribeLocalEvent<PaperLabelComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
|
SubscribeLocalEvent<PaperLabelComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
|
||||||
@@ -35,17 +32,6 @@ namespace Content.Server.Labels
|
|||||||
SubscribeLocalEvent<PaperLabelComponent, ExaminedEvent>(OnExamined);
|
SubscribeLocalEvent<PaperLabelComponent, ExaminedEvent>(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply or remove a label on an entity.
|
/// Apply or remove a label on an entity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -59,7 +45,7 @@ namespace Content.Server.Labels
|
|||||||
label = EnsureComp<LabelComponent>(uid);
|
label = EnsureComp<LabelComponent>(uid);
|
||||||
|
|
||||||
label.CurrentLabel = text;
|
label.CurrentLabel = text;
|
||||||
_nameMod.RefreshNameModifiers(uid);
|
NameMod.RefreshNameModifiers(uid);
|
||||||
|
|
||||||
Dirty(uid, label);
|
Dirty(uid, label);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,27 @@ namespace Content.Shared.Labels.EntitySystems;
|
|||||||
|
|
||||||
public abstract partial class SharedLabelSystem : EntitySystem
|
public abstract partial class SharedLabelSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] protected readonly NameModifierSystem NameMod = default!;
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<LabelComponent, MapInitEvent>(OnLabelCompMapInit);
|
||||||
SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
|
SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
|
||||||
SubscribeLocalEvent<LabelComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
|
SubscribeLocalEvent<LabelComponent, RefreshNameModifiersEvent>(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){}
|
public virtual void Label(EntityUid uid, string? text, MetaDataComponent? metadata = null, LabelComponent? label = null){}
|
||||||
|
|
||||||
private void OnExamine(EntityUid uid, LabelComponent? label, ExaminedEvent args)
|
private void OnExamine(EntityUid uid, LabelComponent? label, ExaminedEvent args)
|
||||||
|
|||||||
Reference in New Issue
Block a user