* Remove some BUI boilerplate - The disposals overrides got removed due to the helper method handling it. - Replace window creation with CreateWindow helper. - Fixed some stinky code which would cause exceptions. * More * moar * weh * done * More BUIs * More updates * weh * moar * look who it is * weh * merge * weh * fixes
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using Content.Shared.Labels;
|
|
using Content.Shared.Labels.Components;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.UserInterface;
|
|
|
|
namespace Content.Client.Labels.UI
|
|
{
|
|
/// <summary>
|
|
/// Initializes a <see cref="HandLabelerWindow"/> and updates it when new server messages are received.
|
|
/// </summary>
|
|
public sealed class HandLabelerBoundUserInterface : BoundUserInterface
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
|
|
[ViewVariables]
|
|
private HandLabelerWindow? _window;
|
|
|
|
public HandLabelerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
}
|
|
|
|
protected override void Open()
|
|
{
|
|
base.Open();
|
|
|
|
_window = this.CreateWindow<HandLabelerWindow>();
|
|
|
|
_window.OnLabelChanged += OnLabelChanged;
|
|
Reload();
|
|
}
|
|
|
|
private void OnLabelChanged(string newLabel)
|
|
{
|
|
// Focus moment
|
|
if (_entManager.TryGetComponent(Owner, out HandLabelerComponent? labeler) &&
|
|
labeler.AssignedLabel.Equals(newLabel))
|
|
return;
|
|
|
|
SendPredictedMessage(new HandLabelerLabelChangedMessage(newLabel));
|
|
}
|
|
|
|
public void Reload()
|
|
{
|
|
if (_window == null || !_entManager.TryGetComponent(Owner, out HandLabelerComponent? component))
|
|
return;
|
|
|
|
_window.SetCurrentLabel(component.AssignedLabel);
|
|
}
|
|
}
|
|
}
|