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;
_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);
<Control Name="TextAlignmentPadding" VerticalAlignment="Top"/>
<RichTextLabel Name="BlankPaperIndicator" StyleClasses="LabelSecondaryColor" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<RichTextLabel StyleClasses="PaperWrittenText" Name="WrittenTextLabel" VerticalAlignment="Top"/>
- <PanelContainer Name="InputContainer" StyleClasses="TransparentBorderedWindowPanel" MinHeight="100"
- VerticalAlignment="Stretch" VerticalExpand="True" HorizontalExpand="True">
- <TextEdit Name="Input" StyleClasses="PaperLineEdit" Access="Public" />
- </PanelContainer>
+ <BoxContainer Name="InputContainer" Orientation="Vertical" VerticalExpand="True" VerticalAlignment="Stretch">
+ <PanelContainer StyleClasses="TransparentBorderedWindowPanel" MinHeight="100"
+ VerticalAlignment="Stretch" VerticalExpand="True" HorizontalExpand="True">
+ <TextEdit Name="Input" StyleClasses="PaperLineEdit" Access="Public" />
+ </PanelContainer>
+ <Label Name="FillStatus" StyleClasses="LabelSecondaryColor"/>
+ </BoxContainer>
</BoxContainer>
<paper:StampCollection Name="StampDisplay" VerticalAlignment="Bottom" Margin="6"/>
public event Action<string>? OnSaved;
+ private int _MaxInputLength = -1;
+ public int MaxInputLength
+ {
+ get
+ {
+ return _MaxInputLength;
+ }
+ set
+ {
+ _MaxInputLength = value;
+ UpdateFillState();
+ }
+ }
+
public PaperWindow()
{
IoCManager.InjectDependencies(this);
{
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();
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)
{
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;
+ }
+ }
}
}
public void SetContent(Entity<PaperComponent> entity, string content)
{
- entity.Comp.Content = content + '\n';
+ entity.Comp.Content = content;
Dirty(entity);
UpdateUserInterface(entity);
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.