Files
tbd-station-14/Content.Client/Weapons/Melee/UI/MeleeSpeechBoundUserInterface.cs
metalgearsloth cbf329a82d Remove some BUI boilerplate (#28399)
* Remove some BUI boilerplate

- The disposals overrides got removed due to the helper method handling it.
- Replace window creation with CreateWindow helper.
- Fixed some stinky code which would cause exceptions.

* More

* moar

* weh

* done

* More BUIs

* More updates

* weh

* moar

* look who it is

* weh

* merge

* weh

* fixes
2024-07-20 15:40:16 +10:00

54 lines
1.4 KiB
C#

using Robust.Client.GameObjects;
using Content.Shared.Speech.Components;
using Robust.Client.UserInterface;
namespace Content.Client.Weapons.Melee.UI;
/// <summary>
/// Initializes a <see cref="MeleeSpeechWindow"/> and updates it when new server messages are received.
/// </summary>
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<MeleeSpeechWindow>();
_window.OnBattlecryEntered += OnBattlecryChanged;
}
private void OnBattlecryChanged(string newBattlecry)
{
SendMessage(new MeleeSpeechBattlecryChangedMessage(newBattlecry));
}
/// <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 MeleeSpeechBoundUserInterfaceState cast)
return;
_window.SetCurrentBattlecry(cast.CurrentBattlecry);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_window?.Dispose();
}
}