2020-12-08 11:56:10 +01:00
|
|
|
using JetBrains.Annotations;
|
2024-07-21 14:48:13 +10:00
|
|
|
using Robust.Client.UserInterface;
|
2020-02-11 20:01:05 -03:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
2023-04-14 12:57:47 -07:00
|
|
|
using Robust.Shared.Utility;
|
2024-09-24 00:36:05 +01:00
|
|
|
using Content.Shared.Paper;
|
2024-08-04 21:23:23 -07:00
|
|
|
using static Content.Shared.Paper.PaperComponent;
|
2020-02-11 20:01:05 -03:00
|
|
|
|
2023-08-13 19:28:10 +01:00
|
|
|
namespace Content.Client.Paper.UI;
|
|
|
|
|
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class PaperBoundUserInterface : BoundUserInterface
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
2023-08-13 19:28:10 +01:00
|
|
|
[ViewVariables]
|
|
|
|
|
private PaperWindow? _window;
|
|
|
|
|
|
|
|
|
|
public PaperBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
2023-08-13 19:28:10 +01:00
|
|
|
}
|
2020-02-11 20:01:05 -03:00
|
|
|
|
2023-08-13 19:28:10 +01:00
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
2020-02-11 20:01:05 -03:00
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
_window = this.CreateWindow<PaperWindow>();
|
|
|
|
|
_window.OnSaved += InputOnTextEntered;
|
2023-01-17 08:32:46 +00:00
|
|
|
|
2024-09-24 00:36:05 +01:00
|
|
|
if (EntMan.TryGetComponent<PaperComponent>(Owner, out var paper))
|
|
|
|
|
{
|
|
|
|
|
_window.MaxInputLength = paper.ContentSize;
|
|
|
|
|
}
|
2023-08-13 19:28:10 +01:00
|
|
|
if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
2023-08-13 19:28:10 +01:00
|
|
|
_window.InitVisuals(Owner, visuals);
|
2020-02-11 20:01:05 -03:00
|
|
|
}
|
2023-08-13 19:28:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
_window?.Populate((PaperBoundUserInterfaceState) state);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
private void InputOnTextEntered(string text)
|
2023-08-13 19:28:10 +01:00
|
|
|
{
|
2023-12-24 09:58:00 +01:00
|
|
|
SendMessage(new PaperInputTextMessage(text));
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2023-12-24 09:58:00 +01:00
|
|
|
if (_window != null)
|
|
|
|
|
{
|
|
|
|
|
_window.Input.TextRope = Rope.Leaf.Empty;
|
|
|
|
|
_window.Input.CursorPosition = new TextEdit.CursorPos(0, TextEdit.LineBreakBias.Top);
|
2020-02-11 20:01:05 -03:00
|
|
|
}
|
2023-08-13 19:28:10 +01:00
|
|
|
}
|
2020-02-11 20:01:05 -03:00
|
|
|
}
|