2021-11-11 02:15:23 +13:00
|
|
|
using Content.Shared.Labels;
|
2024-04-28 07:19:30 +03:00
|
|
|
using Content.Shared.Labels.Components;
|
2021-10-16 21:34:05 +01:00
|
|
|
using Robust.Client.GameObjects;
|
2024-07-21 14:48:13 +10:00
|
|
|
using Robust.Client.UserInterface;
|
2021-10-16 21:34:05 +01:00
|
|
|
|
2021-11-11 02:15:23 +13:00
|
|
|
namespace Content.Client.Labels.UI
|
2021-10-16 21:34:05 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a <see cref="HandLabelerWindow"/> and updates it when new server messages are received.
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class HandLabelerBoundUserInterface : BoundUserInterface
|
2021-10-16 21:34:05 +01:00
|
|
|
{
|
2024-04-28 07:19:30 +03:00
|
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
[ViewVariables]
|
2021-10-16 21:34:05 +01:00
|
|
|
private HandLabelerWindow? _window;
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
public HandLabelerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2021-10-16 21:34:05 +01:00
|
|
|
{
|
2024-04-28 07:19:30 +03:00
|
|
|
IoCManager.InjectDependencies(this);
|
2021-10-16 21:34:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
_window = this.CreateWindow<HandLabelerWindow>();
|
2021-10-16 21:34:05 +01:00
|
|
|
|
2024-09-04 15:20:00 +01:00
|
|
|
if (_entManager.TryGetComponent(Owner, out HandLabelerComponent? labeler))
|
|
|
|
|
{
|
|
|
|
|
_window.SetMaxLabelLength(labeler!.MaxLabelChars);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 00:52:03 -04:00
|
|
|
_window.OnLabelChanged += OnLabelChanged;
|
2024-04-28 07:19:30 +03:00
|
|
|
Reload();
|
2021-10-16 21:34:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLabelChanged(string newLabel)
|
|
|
|
|
{
|
2024-04-28 07:19:30 +03:00
|
|
|
// Focus moment
|
|
|
|
|
if (_entManager.TryGetComponent(Owner, out HandLabelerComponent? labeler) &&
|
|
|
|
|
labeler.AssignedLabel.Equals(newLabel))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SendPredictedMessage(new HandLabelerLabelChangedMessage(newLabel));
|
2021-10-16 21:34:05 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-28 07:19:30 +03:00
|
|
|
public void Reload()
|
2021-10-16 21:34:05 +01:00
|
|
|
{
|
2024-04-28 07:19:30 +03:00
|
|
|
if (_window == null || !_entManager.TryGetComponent(Owner, out HandLabelerComponent? component))
|
2021-10-16 21:34:05 +01:00
|
|
|
return;
|
|
|
|
|
|
2024-04-28 07:19:30 +03:00
|
|
|
_window.SetCurrentLabel(component.AssignedLabel);
|
2021-10-16 21:34:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|