Files
tbd-station-14/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs
Absotively f1c95bfbb1 Hand labeler UI improvements (#40318)
* Populate and select label line edit on window open

* Widen hand labeller UI

* Add reset and clear buttons to hand labeler UI

* Add window resizing fix from https://github.com/space-wizards/space-station-14/pull/40322

* xaml cleanup, button grouping
2025-10-23 15:15:42 +00:00

58 lines
1.8 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>();
if (_entManager.TryGetComponent(Owner, out HandLabelerComponent? labeler))
{
_window.SetMaxLabelLength(labeler!.MaxLabelChars);
}
_window.OnLabelChanged += OnLabelChanged;
Reload();
_window.SetInitialLabelState(); // Must be after Reload() has set the label text
}
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);
}
}
}