using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
using Content.Shared.NameIdentifier;
+using Content.Shared.NameModifier.EntitySystems;
using Content.Shared.Preferences;
using Content.Shared.Silicons.Borgs;
using Content.Shared.Silicons.Borgs.Components;
public sealed partial class BorgMenu : FancyWindow
{
[Dependency] private readonly IEntityManager _entity = default!;
+ private readonly NameModifierSystem _nameModifier;
public Action? BrainButtonPressed;
public Action? EjectBatteryButtonPressed;
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
+ _nameModifier = _entity.System<NameModifierSystem>();
+
_lastValidName = NameLineEdit.Text;
EjectBatteryButton.OnPressed += _ => EjectBatteryButtonPressed?.Invoke();
NameIdentifierLabel.Visible = true;
NameIdentifierLabel.Text = nameIdentifierComponent.FullIdentifier;
- var fullName = _entity.GetComponent<MetaDataComponent>(Entity).EntityName;
- var name = fullName.Substring(0, fullName.Length - nameIdentifierComponent.FullIdentifier.Length - 1);
- NameLineEdit.Text = name;
+ NameLineEdit.Text = _nameModifier.GetBaseName(entity);
}
else
{
using Content.Shared.GameTicking;
using Content.Shared.NameIdentifier;
+using Content.Shared.NameModifier.EntitySystems;
using Robust.Shared.Collections;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
- [Dependency] private readonly MetaDataSystem _metaData = default!;
+ [Dependency] private readonly NameModifierSystem _nameModifier = default!;
/// <summary>
/// Free IDs available per <see cref="NameIdentifierGroupPrototype"/>.
SubscribeLocalEvent<NameIdentifierComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<NameIdentifierComponent, ComponentShutdown>(OnComponentShutdown);
+ SubscribeLocalEvent<NameIdentifierComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
SubscribeLocalEvent<RoundRestartCleanupEvent>(CleanupIds);
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnReloadPrototypes);
ids[randomIndex] = component.Identifier;
ids.Add(random);
}
+ _nameModifier.RefreshNameModifiers(uid);
}
/// <summary>
? uniqueName
: $"({uniqueName})";
- var meta = MetaData(uid);
- // "DR-1234" as opposed to "drone (DR-1234)"
- _metaData.SetEntityName(uid, group.FullName
- ? uniqueName
- : $"{meta.EntityName} ({uniqueName})", meta);
Dirty(uid, component);
+ _nameModifier.RefreshNameModifiers(uid);
+ }
+
+ private void OnRefreshNameModifiers(Entity<NameIdentifierComponent> ent, ref RefreshNameModifiersEvent args)
+ {
+ // Don't apply the modifier if the component is being removed
+ if (ent.Comp.LifeStage > ComponentLifeStage.Running)
+ return;
+
+ if (!_prototypeManager.TryIndex<NameIdentifierGroupPrototype>(ent.Comp.Group, out var group))
+ return;
+ var format = group.FullName ? "name-identifier-format-full" : "name-identifier-format-append";
+ // We apply the modifier with a low priority to keep it near the base name
+ // "Beep (Si-4562) the zombie" instead of "Beep the zombie (Si-4562)"
+ args.AddModifier(format, -10, ("identifier", ent.Comp.FullIdentifier));
}
private void InitialSetupPrototypes()