using Robust.Client.GameObjects;
using Content.Shared.Speech.Components;
using Robust.Client.UserInterface;
namespace Content.Client.Weapons.Melee.UI;
///
/// Initializes a and updates it when new server messages are received.
///
public sealed class MeleeSpeechBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private MeleeSpeechWindow? _window;
public MeleeSpeechBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = this.CreateWindow();
_window.OnBattlecryEntered += OnBattlecryChanged;
}
private void OnBattlecryChanged(string newBattlecry)
{
SendMessage(new MeleeSpeechBattlecryChangedMessage(newBattlecry));
}
///
/// Update the UI state based on server-sent info
///
///
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_window == null || state is not MeleeSpeechBoundUserInterfaceState cast)
return;
_window.SetCurrentBattlecry(cast.CurrentBattlecry);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_window?.Dispose();
}
}