Files
tbd-station-14/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs
osjarw a4504e2fef Fix handlabeler/utility belt misprediction (#26660)
* Fix handlabeler/utility belt misprediction

* Partly moved HandLabelerSystem to shared
And cleaned up HandLabelerComponent

* WIP format the files so later commits look clearer
Doesn't change individual code lines, but may move
functions to another file

* WIP some more code movement

* Hand Labeler is now mostly predicted
Only the UI isn't

* WIP: Formatting and moved stuff

* Using componentstates for prediction correction

* review

* Update label on label change

* Don't overwrite label while editing

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2024-04-28 14:19:30 +10:00

64 lines
1.8 KiB
C#

using Content.Shared.Labels;
using Content.Shared.Labels.Components;
using Robust.Client.GameObjects;
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 = new HandLabelerWindow();
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_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);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
}
}