Fixed redundant bar sign windows (#42960)
Fixed redundant bar signs * Fixes the extra bar sign popups bug introduced in #42364 by making BarSignBUI use CreateWindow * Fixes bar signs placed from Entity Spawn Window
This commit is contained in:
parent
662e9883a4
commit
3b9db7359b
|
|
@ -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<BarSignComponent>(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<BarSignMenu>();
|
||||
_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<BarSignComponent>(Owner, out var signComp))
|
||||
if (!EntMan.TryGetComponent<BarSignComponent>(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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,23 +8,13 @@ namespace Content.Client.BarSign.Ui;
|
|||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BarSignMenu : FancyWindow
|
||||
{
|
||||
private string? _currentId;
|
||||
|
||||
private readonly List<BarSignPrototype> _cachedPrototypes = new();
|
||||
private List<BarSignPrototype> _cachedPrototypes = new();
|
||||
|
||||
public event Action<string>? OnSignSelected;
|
||||
|
||||
public BarSignMenu(BarSignPrototype? currentSign, List<BarSignPrototype> 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<BarSignPrototype> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,12 @@ public sealed class BarSignSystem : EntitySystem
|
|||
|
||||
private void OnMapInit(Entity<BarSignComponent> 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
|
|||
/// </summary>
|
||||
public void SetBarSign(Entity<BarSignComponent> ent, BarSignPrototype newPrototype)
|
||||
{
|
||||
if (ent.Comp.Current == newPrototype.ID)
|
||||
return;
|
||||
|
||||
if (HasComp<EmpDisabledComponent>(ent))
|
||||
return;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue