Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Content.Client/Paper/UI/PaperBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Paper;
using Content.Shared.Persistence.Paper;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
Expand All @@ -24,6 +25,7 @@ protected override void Open()
_window = this.CreateWindow<PaperWindow>();
_window.OnSaved += InputOnTextEntered;
_window.OnSignatureRequested += OnSignatureRequested;
_window.OnSignatureFieldRequested += OnSignatureFieldRequested;

if (EntMan.TryGetComponent<PaperComponent>(Owner, out var paper))
{
Expand Down Expand Up @@ -53,4 +55,6 @@ private void InputOnTextEntered(string text)
}

private void OnSignatureRequested(int signatureIndex) => SendMessage(new PaperSignatureRequestMessage(signatureIndex));
private void OnSignatureFieldRequested(string field) => SendMessage(new PaperSignatureFieldRequestMessage(field));

}
14 changes: 13 additions & 1 deletion Content.Client/Paper/UI/PaperVisualizerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,23 @@ protected override void OnAppearanceChange(EntityUid uid, PaperVisualsComponent
}

}

if (AppearanceSystem.TryGetData<string>(uid, PaperVisuals.Signed, out var signedState, args.Component))
{
if (signedState != string.Empty)
{
SpriteSystem.LayerSetRsiState((uid, args.Sprite), PaperVisualLayers.Signature, signedState);
SpriteSystem.LayerSetVisible((uid, args.Sprite), PaperVisualLayers.Signature, true);
}
else
SpriteSystem.LayerSetVisible((uid, args.Sprite), PaperVisualLayers.Signature, true);
}
}
}

public enum PaperVisualLayers
{
Stamp,
Writing
Writing,
Signature,
}
2 changes: 2 additions & 0 deletions Content.Client/Paper/UI/PaperWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public sealed partial class PaperWindow : BaseWindow

public event Action<string>? OnSaved;
public event Action<int>? OnSignatureRequested;
public event Action<string>? OnSignatureFieldRequested;

private int _maxInputLength = -1;
public int MaxInputLength
Expand Down Expand Up @@ -414,6 +415,7 @@ public void OpenFormDialog(int formIndex)
}

public void SendSignatureRequest(int signatureIndex) => OnSignatureRequested?.Invoke(signatureIndex);
public void SendFieldSignatureRequest(string field) => OnSignatureFieldRequested?.Invoke(field);
private Button? FindFormButton(int index) => FindNthButton(WrittenTextLabel, index, Loc.GetString("paper-form-fill-button"));
private Button? FindCheckButton(int index) => FindNthButton(WrittenTextLabel, index, PaperTagHelper.CheckSymbols);

Expand Down
3 changes: 2 additions & 1 deletion Content.Client/Paper/UI/StampWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public StampDisplayInfo StampInfo
{
set
{
StampedByLabel.Text = Loc.GetString(value.StampedName);
StampedByLabel.Text = value.UseNameAsLoc ? Loc.GetString(value.StampedName) : value.StampedName;
StampedByLabel.FontColorOverride = value.StampedColor;
ModulateSelfOverride = value.StampedColor;
PanelOverride = value.UseBox ? _borderTexture : null;
}
}

Expand Down
29 changes: 24 additions & 5 deletions Content.Client/UserInterface/RichText/SignatureTagHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,46 @@ public void PopDrawContext(MarkupNode node, MarkupDrawingContext context) { }

public bool TryCreateControl(MarkupNode node, [NotNullWhen(true)] out Control? control)
{
var hasField = TryGetSignatureField(node, out var field);

var btn = new Button
{
Text = Loc.GetString("paper-signature-sign-button"),
Text = hasField ? field : Loc.GetString("paper-signature-sign-button"),
MinSize = new Vector2(48, PaperTagHelper.FontLineHeight + 4),
MaxSize = new Vector2(48, PaperTagHelper.FontLineHeight + 4),
MaxSize = new Vector2(100, PaperTagHelper.FontLineHeight + 4),
Margin = new Thickness(1, 2, 1, 2),
StyleClasses = { "ButtonSquare" },
TextAlign = Label.AlignMode.Center,
Name = $"signature_{_signatureCounter++}"
Name = $"signature_{(hasField ? field : _signatureCounter++)}"
};

btn.OnPressed += _ =>
{
if (PaperTagHelper.FindPaperWindow(btn) is { } paperWindow)
{
var buttonIndex = PaperTagHelper.CountButtonsBefore(btn, b => b.Text == Loc.GetString("paper-signature-sign-button"));
paperWindow.SendSignatureRequest(buttonIndex);
if (hasField)
{
paperWindow.SendFieldSignatureRequest(field ?? ""); // It won't be null here... but appeasing the editor.
}
else
{
var buttonIndex = PaperTagHelper.CountButtonsBefore(btn, b => b.Text == Loc.GetString("paper-signature-sign-button"));
paperWindow.SendSignatureRequest(buttonIndex);
}
}
};

control = btn;
return true;
}

private bool TryGetSignatureField(MarkupNode node, [NotNullWhen(true)] out string? field)
{
field = null;
if (node.Value.TryGetString(out field))
{
return !string.IsNullOrWhiteSpace(field);
}
return false;
}
}
12 changes: 5 additions & 7 deletions Content.Shared/Paper/PaperComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public sealed partial class PaperComponent : Component
[DataField("stampedBy"), AutoNetworkedField]
public List<StampDisplayInfo> StampedBy { get; set; } = new();

[DataField("signedBy"), AutoNetworkedField]
public HashSet<string> SignedBy { get; set; } = new();

/// <summary>
/// Stamp to be displayed on the paper, state from bureaucracy.rsi
/// </summary>
Expand Down Expand Up @@ -58,12 +61,6 @@ public PaperInputTextMessage(string text)
}
}

[Serializable, NetSerializable]
public sealed class PaperSignatureRequestMessage(int signatureIndex) : BoundUserInterfaceMessage
{
public readonly int SignatureIndex = signatureIndex;
}

[Serializable, NetSerializable]
public enum PaperUiKey
{
Expand All @@ -82,7 +79,8 @@ public enum PaperVisuals : byte
{
Status,
Stamp,
Invoice
Invoice,
Signed,
}

[Serializable, NetSerializable]
Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/Paper/PaperSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Linq;
using Content.Shared.Persistence.Paper;
using static Content.Shared.Paper.PaperComponent;

namespace Content.Shared.Paper;
Expand Down Expand Up @@ -50,7 +51,7 @@ public override void Initialize()
SubscribeLocalEvent<RandomPaperContentComponent, MapInitEvent>(OnRandomPaperContentMapInit);

SubscribeLocalEvent<ActivateOnPaperOpenedComponent, PaperWriteEvent>(OnPaperWrite);
SubscribeLocalEvent<PaperComponent, PaperSignatureRequestMessage>(OnSignatureRequest);
//SubscribeLocalEvent<PaperComponent, PaperSignatureRequestMessage>(OnSignatureRequest);

_paperQuery = GetEntityQuery<PaperComponent>();
}
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Paper/PaperTagUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public static string ReplaceNthTag(string text, string tag, int index, string re
return text;
}

/// <summary>
/// Replaces all instances of a tag in the text with a given string.
/// </summary>
public static string ReplaceAllTag(string text, string tag, string replacement)
{
return text.Replace(tag, replacement); // This proved far simpler than I thought it would be...
}

/// <summary>
/// Removes any unfilled [form] and [signature] tags, and converts [check] tags to ☐.
/// Called when the paper is stamped to finalize the document.
Expand Down
25 changes: 20 additions & 5 deletions Content.Shared/Paper/StampComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,31 @@ namespace Content.Shared.Paper;
[DataDefinition, Serializable, NetSerializable]
public partial struct StampDisplayInfo
{
StampDisplayInfo(string s)
{
StampedName = s;
}

/// <summary>
/// Localization name / stamp to be contained in the stamp.
/// </summary>
[DataField("stampedName")]
public string StampedName;

/// <summary>
/// Color of the stamp
/// </summary>

[DataField("stampedColor")]
public Color StampedColor;

/// <summary>
/// Determines if the stamp should use the border box
/// </summary>

[DataField("useBox")]
public bool UseBox = true;

/// <summary>
/// Determines if StampName should be considered a Loc name or raw text.
/// </summary>
[DataField]
public bool UseNameAsLoc = true;
};

[RegisterComponent]
Expand Down
Loading
Loading