Skip to content

Commit 5696efb

Browse files
Merge pull request #364 from Zetaplx/signature
Signature Rework
2 parents f68aaad + b64db4e commit 5696efb

16 files changed

Lines changed: 314 additions & 20 deletions

File tree

Content.Client/Paper/UI/PaperBoundUserInterface.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Content.Shared.Paper;
2+
using Content.Shared.Persistence.Paper;
23
using JetBrains.Annotations;
34
using Robust.Client.UserInterface;
45
using Robust.Client.UserInterface.Controls;
@@ -24,6 +25,7 @@ protected override void Open()
2425
_window = this.CreateWindow<PaperWindow>();
2526
_window.OnSaved += InputOnTextEntered;
2627
_window.OnSignatureRequested += OnSignatureRequested;
28+
_window.OnSignatureFieldRequested += OnSignatureFieldRequested;
2729

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

5557
private void OnSignatureRequested(int signatureIndex) => SendMessage(new PaperSignatureRequestMessage(signatureIndex));
58+
private void OnSignatureFieldRequested(string field) => SendMessage(new PaperSignatureFieldRequestMessage(field));
59+
5660
}

Content.Client/Paper/UI/PaperVisualizerSystem.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,23 @@ protected override void OnAppearanceChange(EntityUid uid, PaperVisualsComponent
3838
}
3939

4040
}
41+
42+
if (AppearanceSystem.TryGetData<string>(uid, PaperVisuals.Signed, out var signedState, args.Component))
43+
{
44+
if (signedState != string.Empty)
45+
{
46+
SpriteSystem.LayerSetRsiState((uid, args.Sprite), PaperVisualLayers.Signature, signedState);
47+
SpriteSystem.LayerSetVisible((uid, args.Sprite), PaperVisualLayers.Signature, true);
48+
}
49+
else
50+
SpriteSystem.LayerSetVisible((uid, args.Sprite), PaperVisualLayers.Signature, true);
51+
}
4152
}
4253
}
4354

4455
public enum PaperVisualLayers
4556
{
4657
Stamp,
47-
Writing
58+
Writing,
59+
Signature,
4860
}

Content.Client/Paper/UI/PaperWindow.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public sealed partial class PaperWindow : BaseWindow
5757

5858
public event Action<string>? OnSaved;
5959
public event Action<int>? OnSignatureRequested;
60+
public event Action<string>? OnSignatureFieldRequested;
6061

6162
private int _maxInputLength = -1;
6263
public int MaxInputLength
@@ -414,6 +415,7 @@ public void OpenFormDialog(int formIndex)
414415
}
415416

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

Content.Client/Paper/UI/StampWidget.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public StampDisplayInfo StampInfo
2727
{
2828
set
2929
{
30-
StampedByLabel.Text = Loc.GetString(value.StampedName);
30+
StampedByLabel.Text = value.UseNameAsLoc ? Loc.GetString(value.StampedName) : value.StampedName;
3131
StampedByLabel.FontColorOverride = value.StampedColor;
3232
ModulateSelfOverride = value.StampedColor;
33+
PanelOverride = value.UseBox ? _borderTexture : null;
3334
}
3435
}
3536

Content.Client/UserInterface/RichText/SignatureTagHandler.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,46 @@ public void PopDrawContext(MarkupNode node, MarkupDrawingContext context) { }
2525

2626
public bool TryCreateControl(MarkupNode node, [NotNullWhen(true)] out Control? control)
2727
{
28+
var hasField = TryGetSignatureField(node, out var field);
29+
2830
var btn = new Button
2931
{
30-
Text = Loc.GetString("paper-signature-sign-button"),
32+
Text = hasField ? field : Loc.GetString("paper-signature-sign-button"),
3133
MinSize = new Vector2(48, PaperTagHelper.FontLineHeight + 4),
32-
MaxSize = new Vector2(48, PaperTagHelper.FontLineHeight + 4),
34+
MaxSize = new Vector2(100, PaperTagHelper.FontLineHeight + 4),
3335
Margin = new Thickness(1, 2, 1, 2),
3436
StyleClasses = { "ButtonSquare" },
3537
TextAlign = Label.AlignMode.Center,
36-
Name = $"signature_{_signatureCounter++}"
38+
Name = $"signature_{(hasField ? field : _signatureCounter++)}"
3739
};
3840

3941
btn.OnPressed += _ =>
4042
{
4143
if (PaperTagHelper.FindPaperWindow(btn) is { } paperWindow)
4244
{
43-
var buttonIndex = PaperTagHelper.CountButtonsBefore(btn, b => b.Text == Loc.GetString("paper-signature-sign-button"));
44-
paperWindow.SendSignatureRequest(buttonIndex);
45+
if (hasField)
46+
{
47+
paperWindow.SendFieldSignatureRequest(field ?? ""); // It won't be null here... but appeasing the editor.
48+
}
49+
else
50+
{
51+
var buttonIndex = PaperTagHelper.CountButtonsBefore(btn, b => b.Text == Loc.GetString("paper-signature-sign-button"));
52+
paperWindow.SendSignatureRequest(buttonIndex);
53+
}
4554
}
4655
};
4756

4857
control = btn;
4958
return true;
5059
}
60+
61+
private bool TryGetSignatureField(MarkupNode node, [NotNullWhen(true)] out string? field)
62+
{
63+
field = null;
64+
if (node.Value.TryGetString(out field))
65+
{
66+
return !string.IsNullOrWhiteSpace(field);
67+
}
68+
return false;
69+
}
5170
}

Content.Shared/Paper/PaperComponent.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public sealed partial class PaperComponent : Component
1717
[DataField("stampedBy"), AutoNetworkedField]
1818
public List<StampDisplayInfo> StampedBy { get; set; } = new();
1919

20+
[DataField("signedBy"), AutoNetworkedField]
21+
public HashSet<string> SignedBy { get; set; } = new();
22+
2023
/// <summary>
2124
/// Stamp to be displayed on the paper, state from bureaucracy.rsi
2225
/// </summary>
@@ -58,12 +61,6 @@ public PaperInputTextMessage(string text)
5861
}
5962
}
6063

61-
[Serializable, NetSerializable]
62-
public sealed class PaperSignatureRequestMessage(int signatureIndex) : BoundUserInterfaceMessage
63-
{
64-
public readonly int SignatureIndex = signatureIndex;
65-
}
66-
6764
[Serializable, NetSerializable]
6865
public enum PaperUiKey
6966
{
@@ -82,7 +79,8 @@ public enum PaperVisuals : byte
8279
{
8380
Status,
8481
Stamp,
85-
Invoice
82+
Invoice,
83+
Signed,
8684
}
8785

8886
[Serializable, NetSerializable]

Content.Shared/Paper/PaperSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Robust.Shared.Prototypes;
1515
using Robust.Shared.Random;
1616
using System.Linq;
17+
using Content.Shared.Persistence.Paper;
1718
using static Content.Shared.Paper.PaperComponent;
1819

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

5253
SubscribeLocalEvent<ActivateOnPaperOpenedComponent, PaperWriteEvent>(OnPaperWrite);
53-
SubscribeLocalEvent<PaperComponent, PaperSignatureRequestMessage>(OnSignatureRequest);
54+
//SubscribeLocalEvent<PaperComponent, PaperSignatureRequestMessage>(OnSignatureRequest);
5455

5556
_paperQuery = GetEntityQuery<PaperComponent>();
5657
}

Content.Shared/Paper/PaperTagUtility.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public static string ReplaceNthTag(string text, string tag, int index, string re
2929
return text;
3030
}
3131

32+
/// <summary>
33+
/// Replaces all instances of a tag in the text with a given string.
34+
/// </summary>
35+
public static string ReplaceAllTag(string text, string tag, string replacement)
36+
{
37+
return text.Replace(tag, replacement); // This proved far simpler than I thought it would be...
38+
}
39+
3240
/// <summary>
3341
/// Removes any unfilled [form] and [signature] tags, and converts [check] tags to ☐.
3442
/// Called when the paper is stamped to finalize the document.

Content.Shared/Paper/StampComponent.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,31 @@ namespace Content.Shared.Paper;
1212
[DataDefinition, Serializable, NetSerializable]
1313
public partial struct StampDisplayInfo
1414
{
15-
StampDisplayInfo(string s)
16-
{
17-
StampedName = s;
18-
}
19-
15+
/// <summary>
16+
/// Localization name / stamp to be contained in the stamp.
17+
/// </summary>
2018
[DataField("stampedName")]
2119
public string StampedName;
2220

21+
/// <summary>
22+
/// Color of the stamp
23+
/// </summary>
24+
2325
[DataField("stampedColor")]
2426
public Color StampedColor;
27+
28+
/// <summary>
29+
/// Determines if the stamp should use the border box
30+
/// </summary>
31+
32+
[DataField("useBox")]
33+
public bool UseBox = true;
34+
35+
/// <summary>
36+
/// Determines if StampName should be considered a Loc name or raw text.
37+
/// </summary>
38+
[DataField]
39+
public bool UseNameAsLoc = true;
2540
};
2641

2742
[RegisterComponent]

0 commit comments

Comments
 (0)