Cargo: pizza & bureaucracy (#5123)
* add paper label component * git mv * rename namespace * add cargo printouts * more crates * directly attach paper * comment typo
This commit is contained in:
60
Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs
Normal file
60
Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Content.Shared.Labels;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Labels.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="HandLabelerWindow"/> and updates it when new server messages are received.
|
||||
/// </summary>
|
||||
public class HandLabelerBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private HandLabelerWindow? _window;
|
||||
|
||||
public HandLabelerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new HandLabelerWindow();
|
||||
if (State != null)
|
||||
UpdateState(State);
|
||||
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.OnLabelEntered += OnLabelChanged;
|
||||
|
||||
}
|
||||
|
||||
private void OnLabelChanged(string newLabel)
|
||||
{
|
||||
SendMessage(new HandLabelerLabelChangedMessage(newLabel));
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the UI state based on server-sent info
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
if (_window == null || state is not HandLabelerBoundUserInterfaceState cast)
|
||||
return;
|
||||
|
||||
_window.SetCurrentLabel(cast.CurrentLabel);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing) return;
|
||||
_window?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user