Files
Delta-v/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs
T
03347ed416 Inverse Labels and Handlabeler menu (#6432)
Merge pull request #1120 from oooielp/label-invert (#783)

Co-authored-by: Khaomi <46065349+Khaomi@users.noreply.github.com>
Co-authored-by: Superlagg <sprambersonson@gmail.com>
2026-08-27 14:26:07 -05:00

68 lines
2.2 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;
_window.OnLabelSelected += OnLabelSelected; // Starlight
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));
}
// Starlight start
private void OnLabelSelected(string label)
{
// Update UI and send message to sync with server
if (_window != null)
{
_window.SetCurrentLabel(label);
}
SendPredictedMessage(new HandLabelerLabelChangedMessage(label));
}
// Starlight End
public void Reload()
{
if (_window == null || !_entManager.TryGetComponent(Owner, out HandLabelerComponent? component))
return;
_window.SetCurrentLabel(component.AssignedLabel);
}
}
}