MeleeSpeechBoundUserInterface.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Robust.Client.GameObjects;
  2. using Content.Shared.Speech.Components;
  3. using Robust.Client.UserInterface;
  4. namespace Content.Client.Weapons.Melee.UI;
  5. /// <summary>
  6. /// Initializes a <see cref="MeleeSpeechWindow"/> and updates it when new server messages are received.
  7. /// </summary>
  8. public sealed class MeleeSpeechBoundUserInterface : BoundUserInterface
  9. {
  10. [ViewVariables]
  11. private MeleeSpeechWindow? _window;
  12. public MeleeSpeechBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  13. {
  14. }
  15. protected override void Open()
  16. {
  17. base.Open();
  18. _window = this.CreateWindow<MeleeSpeechWindow>();
  19. _window.OnBattlecryEntered += OnBattlecryChanged;
  20. }
  21. private void OnBattlecryChanged(string newBattlecry)
  22. {
  23. SendMessage(new MeleeSpeechBattlecryChangedMessage(newBattlecry));
  24. }
  25. /// <summary>
  26. /// Update the UI state based on server-sent info
  27. /// </summary>
  28. /// <param name="state"></param>
  29. protected override void UpdateState(BoundUserInterfaceState state)
  30. {
  31. base.UpdateState(state);
  32. if (_window == null || state is not MeleeSpeechBoundUserInterfaceState cast)
  33. return;
  34. _window.SetCurrentBattlecry(cast.CurrentBattlecry);
  35. }
  36. protected override void Dispose(bool disposing)
  37. {
  38. base.Dispose(disposing);
  39. if (!disposing)
  40. return;
  41. _window?.Dispose();
  42. }
  43. }