From 594aad0fa978fb9a625f41f537a866348ee019ed Mon Sep 17 00:00:00 2001 From: eoineoineoin Date: Tue, 24 Sep 2024 00:36:05 +0100 Subject: [PATCH] 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 --- .../Paper/UI/PaperBoundUserInterface.cs | 5 ++ Content.Client/Paper/UI/PaperWindow.xaml | 11 +++-- Content.Client/Paper/UI/PaperWindow.xaml.cs | 49 ++++++++++++++++++- Content.Shared/Paper/PaperSystem.cs | 2 +- .../Locale/en-US/paper/paper-component.ftl | 3 ++ 5 files changed, 63 insertions(+), 7 deletions(-) diff --git a/Content.Client/Paper/UI/PaperBoundUserInterface.cs b/Content.Client/Paper/UI/PaperBoundUserInterface.cs index 63645bc01e910d..ec417f749b9bb4 100644 --- a/Content.Client/Paper/UI/PaperBoundUserInterface.cs +++ b/Content.Client/Paper/UI/PaperBoundUserInterface.cs @@ -2,6 +2,7 @@ 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; @@ -23,6 +24,10 @@ protected override void Open() _window = this.CreateWindow(); _window.OnSaved += InputOnTextEntered; + if (EntMan.TryGetComponent(Owner, out var paper)) + { + _window.MaxInputLength = paper.ContentSize; + } if (EntMan.TryGetComponent(Owner, out var visuals)) { _window.InitVisuals(Owner, visuals); diff --git a/Content.Client/Paper/UI/PaperWindow.xaml b/Content.Client/Paper/UI/PaperWindow.xaml index 2344afd5ef708b..503ae928a3ed14 100644 --- a/Content.Client/Paper/UI/PaperWindow.xaml +++ b/Content.Client/Paper/UI/PaperWindow.xaml @@ -15,10 +15,13 @@ - - - + + + + + diff --git a/Content.Client/Paper/UI/PaperWindow.xaml.cs b/Content.Client/Paper/UI/PaperWindow.xaml.cs index 81b831068c3929..02c4ed64c359f0 100644 --- a/Content.Client/Paper/UI/PaperWindow.xaml.cs +++ b/Content.Client/Paper/UI/PaperWindow.xaml.cs @@ -48,6 +48,20 @@ public sealed partial class PaperWindow : BaseWindow public event Action? OnSaved; + private int _MaxInputLength = -1; + public int MaxInputLength + { + get + { + return _MaxInputLength; + } + set + { + _MaxInputLength = value; + UpdateFillState(); + } + } + public PaperWindow() { IoCManager.InjectDependencies(this); @@ -63,11 +77,21 @@ public PaperWindow() { 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 @@ public void InitVisuals(EntityUid entity, PaperVisualsComponent visuals) PaperContent.ModulateSelfOverride = visuals.ContentImageModulate; WrittenTextLabel.ModulateSelfOverride = visuals.FontAccentColor; + FillStatus.ModulateSelfOverride = visuals.FontAccentColor; var contentImage = visuals.ContentImagePath != null ? _resCache.GetResource(visuals.ContentImagePath) : null; if (contentImage != null) @@ -296,5 +321,25 @@ private void RunOnSaved() { 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; + } + } } } diff --git a/Content.Shared/Paper/PaperSystem.cs b/Content.Shared/Paper/PaperSystem.cs index 0f4bfef983dc39..211eb7eba814a4 100644 --- a/Content.Shared/Paper/PaperSystem.cs +++ b/Content.Shared/Paper/PaperSystem.cs @@ -201,7 +201,7 @@ public bool TryStamp(Entity entity, StampDisplayInfo stampInfo, public void SetContent(Entity entity, string content) { - entity.Comp.Content = content + '\n'; + entity.Comp.Content = content; Dirty(entity); UpdateUserInterface(entity); diff --git a/Resources/Locale/en-US/paper/paper-component.ftl b/Resources/Locale/en-US/paper/paper-component.ftl index c2d9d5712bf67e..7425ea2da16478 100644 --- a/Resources/Locale/en-US/paper/paper-component.ftl +++ b/Resources/Locale/en-US/paper/paper-component.ftl @@ -11,6 +11,9 @@ paper-component-examine-detail-stamped-by = {CAPITALIZE(THE($paper))} {CONJUGATE paper-component-action-stamp-paper-other = {CAPITALIZE(THE($user))} stamps {THE($target)} with {THE($stamp)}. paper-component-action-stamp-paper-self = You stamp {THE($target)} with {THE($stamp)}. +# Indicator to show how full a paper is +paper-ui-fill-level = {$currentLength}/{$maxLength} + paper-ui-save-button = Save ({$keybind}) paper-tamper-proof-modified-message = This page was written using tamper-proof ink.