1
0

PaperBoundUserInterface.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using JetBrains.Annotations;
  2. using Robust.Client.UserInterface;
  3. using Robust.Client.UserInterface.Controls;
  4. using Robust.Shared.Utility;
  5. using Content.Shared.Paper;
  6. using static Content.Shared.Paper.PaperComponent;
  7. namespace Content.Client.Paper.UI;
  8. [UsedImplicitly]
  9. public sealed class PaperBoundUserInterface : BoundUserInterface
  10. {
  11. [ViewVariables]
  12. private PaperWindow? _window;
  13. public PaperBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  14. {
  15. }
  16. protected override void Open()
  17. {
  18. base.Open();
  19. _window = this.CreateWindow<PaperWindow>();
  20. _window.OnSaved += InputOnTextEntered;
  21. if (EntMan.TryGetComponent<PaperComponent>(Owner, out var paper))
  22. {
  23. _window.MaxInputLength = paper.ContentSize;
  24. }
  25. if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
  26. {
  27. _window.InitVisuals(Owner, visuals);
  28. }
  29. }
  30. protected override void UpdateState(BoundUserInterfaceState state)
  31. {
  32. base.UpdateState(state);
  33. _window?.Populate((PaperBoundUserInterfaceState) state);
  34. }
  35. private void InputOnTextEntered(string text)
  36. {
  37. SendMessage(new PaperInputTextMessage(text));
  38. if (_window != null)
  39. {
  40. _window.Input.TextRope = Rope.Leaf.Empty;
  41. _window.Input.CursorPosition = new TextEdit.CursorPos(0, TextEdit.LineBreakBias.Top);
  42. }
  43. }
  44. }