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:
@@ -2,6 +2,7 @@ using JetBrains.Annotations;
|
|||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using Content.Shared.Paper;
|
||||||
using static Content.Shared.Paper.PaperComponent;
|
using static Content.Shared.Paper.PaperComponent;
|
||||||
|
|
||||||
namespace Content.Client.Paper.UI;
|
namespace Content.Client.Paper.UI;
|
||||||
@@ -23,6 +24,10 @@ public sealed class PaperBoundUserInterface : BoundUserInterface
|
|||||||
_window = this.CreateWindow<PaperWindow>();
|
_window = this.CreateWindow<PaperWindow>();
|
||||||
_window.OnSaved += InputOnTextEntered;
|
_window.OnSaved += InputOnTextEntered;
|
||||||
|
|
||||||
|
if (EntMan.TryGetComponent<PaperComponent>(Owner, out var paper))
|
||||||
|
{
|
||||||
|
_window.MaxInputLength = paper.ContentSize;
|
||||||
|
}
|
||||||
if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
|
if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
|
||||||
{
|
{
|
||||||
_window.InitVisuals(Owner, visuals);
|
_window.InitVisuals(Owner, visuals);
|
||||||
|
|||||||
@@ -15,10 +15,13 @@
|
|||||||
<Control Name="TextAlignmentPadding" VerticalAlignment="Top"/>
|
<Control Name="TextAlignmentPadding" VerticalAlignment="Top"/>
|
||||||
<RichTextLabel Name="BlankPaperIndicator" StyleClasses="LabelSecondaryColor" VerticalAlignment="Top" HorizontalAlignment="Center"/>
|
<RichTextLabel Name="BlankPaperIndicator" StyleClasses="LabelSecondaryColor" VerticalAlignment="Top" HorizontalAlignment="Center"/>
|
||||||
<RichTextLabel StyleClasses="PaperWrittenText" Name="WrittenTextLabel" VerticalAlignment="Top"/>
|
<RichTextLabel StyleClasses="PaperWrittenText" Name="WrittenTextLabel" VerticalAlignment="Top"/>
|
||||||
<PanelContainer Name="InputContainer" StyleClasses="TransparentBorderedWindowPanel" MinHeight="100"
|
<BoxContainer Name="InputContainer" Orientation="Vertical" VerticalExpand="True" VerticalAlignment="Stretch">
|
||||||
VerticalAlignment="Stretch" VerticalExpand="True" HorizontalExpand="True">
|
<PanelContainer StyleClasses="TransparentBorderedWindowPanel" MinHeight="100"
|
||||||
<TextEdit Name="Input" StyleClasses="PaperLineEdit" Access="Public" />
|
VerticalAlignment="Stretch" VerticalExpand="True" HorizontalExpand="True">
|
||||||
</PanelContainer>
|
<TextEdit Name="Input" StyleClasses="PaperLineEdit" Access="Public" />
|
||||||
|
</PanelContainer>
|
||||||
|
<Label Name="FillStatus" StyleClasses="LabelSecondaryColor"/>
|
||||||
|
</BoxContainer>
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
<paper:StampCollection Name="StampDisplay" VerticalAlignment="Bottom" Margin="6"/>
|
<paper:StampCollection Name="StampDisplay" VerticalAlignment="Bottom" Margin="6"/>
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,20 @@ namespace Content.Client.Paper.UI
|
|||||||
|
|
||||||
public event Action<string>? OnSaved;
|
public event Action<string>? OnSaved;
|
||||||
|
|
||||||
|
private int _MaxInputLength = -1;
|
||||||
|
public int MaxInputLength
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _MaxInputLength;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_MaxInputLength = value;
|
||||||
|
UpdateFillState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PaperWindow()
|
public PaperWindow()
|
||||||
{
|
{
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
@@ -63,11 +77,21 @@ namespace Content.Client.Paper.UI
|
|||||||
{
|
{
|
||||||
if (args.Function == EngineKeyFunctions.MultilineTextSubmit)
|
if (args.Function == EngineKeyFunctions.MultilineTextSubmit)
|
||||||
{
|
{
|
||||||
RunOnSaved();
|
// SaveButton is disabled when we hit the max input limit. Just check
|
||||||
args.Handle();
|
// that flag instead of trying to calculate the input length again
|
||||||
|
if (!SaveButton.Disabled)
|
||||||
|
{
|
||||||
|
RunOnSaved();
|
||||||
|
args.Handle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Input.OnTextChanged += args =>
|
||||||
|
{
|
||||||
|
UpdateFillState();
|
||||||
|
};
|
||||||
|
|
||||||
SaveButton.OnPressed += _ =>
|
SaveButton.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
RunOnSaved();
|
RunOnSaved();
|
||||||
@@ -126,6 +150,7 @@ namespace Content.Client.Paper.UI
|
|||||||
|
|
||||||
PaperContent.ModulateSelfOverride = visuals.ContentImageModulate;
|
PaperContent.ModulateSelfOverride = visuals.ContentImageModulate;
|
||||||
WrittenTextLabel.ModulateSelfOverride = visuals.FontAccentColor;
|
WrittenTextLabel.ModulateSelfOverride = visuals.FontAccentColor;
|
||||||
|
FillStatus.ModulateSelfOverride = visuals.FontAccentColor;
|
||||||
|
|
||||||
var contentImage = visuals.ContentImagePath != null ? _resCache.GetResource<TextureResource>(visuals.ContentImagePath) : null;
|
var contentImage = visuals.ContentImagePath != null ? _resCache.GetResource<TextureResource>(visuals.ContentImagePath) : null;
|
||||||
if (contentImage != null)
|
if (contentImage != null)
|
||||||
@@ -296,5 +321,25 @@ namespace Content.Client.Paper.UI
|
|||||||
{
|
{
|
||||||
OnSaved?.Invoke(Rope.Collapse(Input.TextRope));
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ public sealed class PaperSystem : EntitySystem
|
|||||||
|
|
||||||
public void SetContent(Entity<PaperComponent> entity, string content)
|
public void SetContent(Entity<PaperComponent> entity, string content)
|
||||||
{
|
{
|
||||||
entity.Comp.Content = content + '\n';
|
entity.Comp.Content = content;
|
||||||
Dirty(entity);
|
Dirty(entity);
|
||||||
UpdateUserInterface(entity);
|
UpdateUserInterface(entity);
|
||||||
|
|
||||||
|
|||||||
@@ -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-other = {CAPITALIZE(THE($user))} stamps {THE($target)} with {THE($stamp)}.
|
||||||
paper-component-action-stamp-paper-self = You stamp {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-ui-save-button = Save ({$keybind})
|
||||||
|
|
||||||
paper-tamper-proof-modified-message = This page was written using tamper-proof ink.
|
paper-tamper-proof-modified-message = This page was written using tamper-proof ink.
|
||||||
|
|||||||
Reference in New Issue
Block a user