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>
This commit is contained in:
eoineoineoin
2024-09-24 00:36:05 +01:00
committed by GitHub
parent d0bb408678
commit 594aad0fa9
5 changed files with 63 additions and 7 deletions

View File

@@ -48,6 +48,20 @@ namespace Content.Client.Paper.UI
public event Action<string>? OnSaved;
private int _MaxInputLength = -1;
public int MaxInputLength
{
get
{
return _MaxInputLength;
}
set
{
_MaxInputLength = value;
UpdateFillState();
}
}
public PaperWindow()
{
IoCManager.InjectDependencies(this);
@@ -63,11 +77,21 @@ namespace Content.Client.Paper.UI
{
if (args.Function == EngineKeyFunctions.MultilineTextSubmit)
{
RunOnSaved();
args.Handle();
// SaveButton is disabled when we hit the max input limit. Just check
// that flag instead of trying to calculate the input length again
if (!SaveButton.Disabled)
{
RunOnSaved();
args.Handle();
}
}
};
Input.OnTextChanged += args =>
{
UpdateFillState();
};
SaveButton.OnPressed += _ =>
{
RunOnSaved();
@@ -126,6 +150,7 @@ namespace Content.Client.Paper.UI
PaperContent.ModulateSelfOverride = visuals.ContentImageModulate;
WrittenTextLabel.ModulateSelfOverride = visuals.FontAccentColor;
FillStatus.ModulateSelfOverride = visuals.FontAccentColor;
var contentImage = visuals.ContentImagePath != null ? _resCache.GetResource<TextureResource>(visuals.ContentImagePath) : null;
if (contentImage != null)
@@ -296,5 +321,25 @@ namespace Content.Client.Paper.UI
{
OnSaved?.Invoke(Rope.Collapse(Input.TextRope));
}
private void UpdateFillState()
{
if (MaxInputLength != -1)
{
var inputLength = Input.TextLength;
FillStatus.Text = Loc.GetString("paper-ui-fill-level",
("currentLength", inputLength),
("maxLength", MaxInputLength));
// Disable the save button if we've gone over the limit
SaveButton.Disabled = inputLength > MaxInputLength;
}
else
{
FillStatus.Text = "";
SaveButton.Disabled = false;
}
}
}
}