diff --git a/Content.Client/BarSign/Ui/BarSignBoundUserInterface.cs b/Content.Client/BarSign/Ui/BarSignBoundUserInterface.cs index 8265877edf..62af75b929 100644 --- a/Content.Client/BarSign/Ui/BarSignBoundUserInterface.cs +++ b/Content.Client/BarSign/Ui/BarSignBoundUserInterface.cs @@ -1,6 +1,7 @@ using System.Linq; using Content.Shared.BarSign; using JetBrains.Annotations; +using Robust.Client.UserInterface; using Robust.Shared.Prototypes; namespace Content.Client.BarSign.Ui; @@ -16,13 +17,12 @@ public sealed class BarSignBoundUserInterface(EntityUid owner, Enum uiKey) : Bou { base.Open(); - var sign = EntMan.GetComponentOrNull(Owner)?.Current is { } current - ? _prototype.Index(current) - : null; var allSigns = BarSignSystem.GetAllBarSigns(_prototype) .OrderBy(p => Loc.GetString(p.Name)) .ToList(); - _menu = new(sign, allSigns); + + _menu = this.CreateWindow(); + _menu.LoadSigns(allSigns); _menu.OnSignSelected += id => { @@ -30,16 +30,17 @@ public sealed class BarSignBoundUserInterface(EntityUid owner, Enum uiKey) : Bou }; _menu.OnClose += Close; - _menu.OpenCentered(); + _menu.OpenToLeft(); } public override void Update() { - if (!EntMan.TryGetComponent(Owner, out var signComp)) + if (!EntMan.TryGetComponent(Owner, out var signComp) + || !_prototype.Resolve(signComp.Current, out var signPrototype)) return; - if (_prototype.Resolve(signComp.Current, out var signPrototype)) - _menu?.UpdateState(signPrototype); + _menu?.UpdateState(signPrototype); } + } diff --git a/Content.Client/BarSign/Ui/BarSignMenu.xaml.cs b/Content.Client/BarSign/Ui/BarSignMenu.xaml.cs index a9333339b7..0fbd282da8 100644 --- a/Content.Client/BarSign/Ui/BarSignMenu.xaml.cs +++ b/Content.Client/BarSign/Ui/BarSignMenu.xaml.cs @@ -8,23 +8,13 @@ namespace Content.Client.BarSign.Ui; [GenerateTypedNameReferences] public sealed partial class BarSignMenu : FancyWindow { - private string? _currentId; - - private readonly List _cachedPrototypes = new(); + private List _cachedPrototypes = new(); public event Action? OnSignSelected; - public BarSignMenu(BarSignPrototype? currentSign, List signs) + public BarSignMenu() { RobustXamlLoader.Load(this); - _currentId = currentSign?.ID; - - _cachedPrototypes.Clear(); - _cachedPrototypes = signs; - foreach (var proto in _cachedPrototypes) - { - SignOptions.AddItem(Loc.GetString(proto.Name)); - } SignOptions.OnItemSelected += idx => { @@ -32,18 +22,21 @@ public sealed partial class BarSignMenu : FancyWindow SignOptions.SelectId(idx.Id); }; - if (currentSign != null) + } + + public void LoadSigns(List signs) + { + _cachedPrototypes.Clear(); + _cachedPrototypes = signs; + + foreach (var proto in _cachedPrototypes) { - var idx = _cachedPrototypes.IndexOf(currentSign); - SignOptions.TrySelectId(idx); + SignOptions.AddItem(Loc.GetString(proto.Name)); } } public void UpdateState(BarSignPrototype newSign) { - if (_currentId != null && newSign.ID == _currentId) - return; - _currentId = newSign.ID; var idx = _cachedPrototypes.IndexOf(newSign); SignOptions.TrySelectId(idx); } diff --git a/Content.Shared/BarSign/BarSignSystem.cs b/Content.Shared/BarSign/BarSignSystem.cs index a5d1ab7221..042120663e 100644 --- a/Content.Shared/BarSign/BarSignSystem.cs +++ b/Content.Shared/BarSign/BarSignSystem.cs @@ -31,10 +31,12 @@ public sealed class BarSignSystem : EntitySystem private void OnMapInit(Entity ent, ref MapInitEvent args) { - if (ent.Comp.Current != null) + BarSignPrototype? newPrototype; + if (ent.Comp.Current is null) + newPrototype = _random.Pick(GetAllBarSigns(_prototypeManager)); + else if (!_prototypeManager.Resolve(ent.Comp.Current, out newPrototype)) return; - var newPrototype = _random.Pick(GetAllBarSigns(_prototypeManager)); SetBarSign(ent, newPrototype); } @@ -77,9 +79,6 @@ public sealed class BarSignSystem : EntitySystem /// public void SetBarSign(Entity ent, BarSignPrototype newPrototype) { - if (ent.Comp.Current == newPrototype.ID) - return; - if (HasComp(ent)) return;