Files
tbd-station-14/Content.Client/Paper/UI/PaperBoundUserInterface.cs
eoineoineoin 594aad0fa9 Paper QOL improvements (#32418)
* Don't add newlines (fixes #32357)

* Improve UI around max paper length (Fixes #32344)

* Display a "fill progress" indicator so users know how close they are to filling it
* Don't allow users to save a paper which went over the limit, to avoid them losing data they want to keep.

---------

Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es>
2024-09-24 09:36:05 +10:00

54 lines
1.4 KiB
C#

using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Utility;
using Content.Shared.Paper;
using static Content.Shared.Paper.PaperComponent;
namespace Content.Client.Paper.UI;
[UsedImplicitly]
public sealed class PaperBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private PaperWindow? _window;
public PaperBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = this.CreateWindow<PaperWindow>();
_window.OnSaved += InputOnTextEntered;
if (EntMan.TryGetComponent<PaperComponent>(Owner, out var paper))
{
_window.MaxInputLength = paper.ContentSize;
}
if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
{
_window.InitVisuals(Owner, visuals);
}
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
_window?.Populate((PaperBoundUserInterfaceState) state);
}
private void InputOnTextEntered(string text)
{
SendMessage(new PaperInputTextMessage(text));
if (_window != null)
{
_window.Input.TextRope = Rope.Leaf.Empty;
_window.Input.CursorPosition = new TextEdit.CursorPos(0, TextEdit.LineBreakBias.Top);
}
}
}