From 82eca1d0607c26b1ca90ceaa21672ae3ca61c379 Mon Sep 17 00:00:00 2001 From: fox Date: Tue, 7 May 2024 20:20:54 +0300 Subject: [PATCH 1/3] Signatures! --- .../DeltaV/Paper/SignatureSystem.cs | 104 ++++++++++++++++++ .../Locale/en-US/deltav/paper/signature.ftl | 5 + .../Objects/Misc/bureaucracy.rsi/meta.json | 5 +- .../bureaucracy.rsi/paper_stamp-signature.png | Bin 0 -> 955 bytes 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 Content.Server/DeltaV/Paper/SignatureSystem.cs create mode 100644 Resources/Locale/en-US/deltav/paper/signature.ftl create mode 100644 Resources/Textures/Objects/Misc/bureaucracy.rsi/paper_stamp-signature.png diff --git a/Content.Server/DeltaV/Paper/SignatureSystem.cs b/Content.Server/DeltaV/Paper/SignatureSystem.cs new file mode 100644 index 00000000000..cc788219f48 --- /dev/null +++ b/Content.Server/DeltaV/Paper/SignatureSystem.cs @@ -0,0 +1,104 @@ +using Content.Server.Access.Systems; +using Content.Server.Paper; +using Content.Server.Popups; +using Content.Shared.Paper; +using Content.Shared.Popups; +using Content.Shared.Tag; +using Content.Shared.Verbs; +using Robust.Server.Audio; +using Robust.Shared.Player; + +namespace Content.Server.DeltaV.Paper; + +public sealed class SignatureSystem : EntitySystem +{ + [Dependency] private readonly TagSystem _tagSystem = default!; + [Dependency] private readonly PaperSystem _paper = default!; + [Dependency] private readonly IdCardSystem _idCard = default!; + [Dependency] private readonly PopupSystem _popup = default!; + [Dependency] private readonly AudioSystem _audio = default!; + + // The sprite used to visualize "signatures" on paper entities. + private static readonly string SignatureStampState = "paper_stamp-signature"; + + public override void Initialize() + { + SubscribeLocalEvent>(OnGetAltVerbs); + } + + private void OnGetAltVerbs(EntityUid uid, PaperComponent component, GetVerbsEvent args) + { + if (!args.CanAccess || !args.CanInteract) + return; + + var pen = args.Using; + if (pen == null || !_tagSystem.HasTag(pen.Value, "Write")) + return; + + AlternativeVerb verb = new() + { + Act = () => + { + TrySignPaper(uid, args.User, component); + }, + Text = Loc.GetString("paper-sign-verb"), + DoContactInteraction = true, + Priority = 10 + }; + args.Verbs.Add(verb); + } + + /// + /// Tries add add a signature to the paper with signer's name. + /// + /// Whether to avoid showing a popup if the paper cannot be signed. + public bool TrySignPaper(EntityUid paper, EntityUid signer, PaperComponent? paperComp = null) + { + if (!Resolve(paper, ref paperComp)) + return false; + + var signatureName = DetermineEntitySignature(signer); + + var stampInfo = new StampDisplayInfo() + { + StampedName = signatureName, + StampedColor = Color.DarkSlateGray, // TODO: make configurable? Perhaps it should depend on the pen. + + }; + + if (!paperComp.StampedBy.Contains(stampInfo) && _paper.TryStamp(paper, stampInfo, SignatureStampState, paperComp)) + { + // Show popups and play a paper writing sound + var signedOtherMessage = Loc.GetString("paper-signed-other", ("user", signer), ("target", paper)); + _popup.PopupEntity(signedOtherMessage, signer, Filter.PvsExcept(signer, entityManager: EntityManager), true); + + var signedSelfMessage = Loc.GetString("paper-signed-self", ("target", paper)); + _popup.PopupEntity(signedSelfMessage, signer, signer); + + _audio.PlayPvs(paperComp.Sound, signer); + + _paper.UpdateUserInterface(paper, paperComp); + + return true; + } + else + { + // Show an error popup + _popup.PopupEntity(Loc.GetString("paper-signed-failure", ("target", paper)), signer, signer, PopupType.SmallCaution); + + return false; + } + } + + private string DetermineEntitySignature(EntityUid uid) + { + // If the entity has an ID, use the name on it. + if (_idCard.TryFindIdCard(uid, out var id) && !string.IsNullOrWhiteSpace(id.Comp.FullName)) + { + return id.Comp.FullName; + } + + // Alternatively, return the entity name + return Name(uid); + } +} diff --git a/Resources/Locale/en-US/deltav/paper/signature.ftl b/Resources/Locale/en-US/deltav/paper/signature.ftl new file mode 100644 index 00000000000..a2941bd797e --- /dev/null +++ b/Resources/Locale/en-US/deltav/paper/signature.ftl @@ -0,0 +1,5 @@ +paper-sign-verb = Sign + +paper-signed-other = {CAPITALIZE(THE($user))} places their signature on {THE($target)}. +paper-signed-self = You place you signature on {THE($target)}. +paper-signed-failure = You cannot place your signature on {THE($target)} diff --git a/Resources/Textures/Objects/Misc/bureaucracy.rsi/meta.json b/Resources/Textures/Objects/Misc/bureaucracy.rsi/meta.json index 1239eca0a69..3fb207a87d3 100644 --- a/Resources/Textures/Objects/Misc/bureaucracy.rsi/meta.json +++ b/Resources/Textures/Objects/Misc/bureaucracy.rsi/meta.json @@ -1,7 +1,7 @@ { "version": 1, "license": "CC-BY-SA-3.0", - "copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/e1142f20f5e4661cb6845cfcf2dd69f864d67432. paper_stamp-syndicate by Veritius. paper_receipt, paper_receipt_horizontal by eoineoineoin. pen_centcom is a resprited version of pen_cap by PuroSlavKing (Github). Luxury pen is drawn by Ubaser. psychologist paper stamp resprited by Guess-My-Name", + "copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/e1142f20f5e4661cb6845cfcf2dd69f864d67432. paper_stamp-syndicate by Veritius. paper_receipt, paper_receipt_horizontal by eoineoineoin. pen_centcom is a resprited version of pen_cap by PuroSlavKing (Github). Luxury pen is drawn by Ubaser. psychologist paper stamp resprited by Guess-My-Name. paper_stamp-signature by Mnemotechnician.", "size": { "x": 32, "y": 32 @@ -259,6 +259,9 @@ }, { "name": "paper_stamp-psychologist" + }, + { + "name": "paper_stamp-signature" } ] } diff --git a/Resources/Textures/Objects/Misc/bureaucracy.rsi/paper_stamp-signature.png b/Resources/Textures/Objects/Misc/bureaucracy.rsi/paper_stamp-signature.png new file mode 100644 index 0000000000000000000000000000000000000000..6a7aa083ee597521958a77c2e68c9adf01ef78f5 GIT binary patch literal 955 zcmZvaziU)M5XXmHV#09&3l%jYK?aEy62VrC-o<1vgcwpNq&TpiN)S9Hkf`8^)fWq| zR2wS`!2v53Erm1|!UXg`h=ri2IL>>4a6f#oyR(m-{e0&;+g@6n8?PR&64AKKH|rk4>Jc$6(Y(UfUBAaGFEjF%Rt0)PO0JM27^LHg@r8)4mA}B zDql8GyU1Yrj~-7{6X^~%pGQ#D5`k^?rJ7L#_FE; zXCUr5a}1~t3x}H;1e$sgu5Mz;Iy79|vOWpVx{K^ySUS_qO9OY2+1wp!N=a~uA8?L( zoy%=^DMgb5<_Z%9ixPXE*OWrL>?Squ%Me&7Tr_(CV(l%rcq0f?hgfz_NVCq~*C5o} zpA<LPcuJrImEY#cq2UZ}NaOsR literal 0 HcmV?d00001 From c311e3215f125269c19d8e5c547b1294c1e6b9ab Mon Sep 17 00:00:00 2001 From: fox Date: Tue, 7 May 2024 20:47:22 +0300 Subject: [PATCH 2/3] Fix typo --- Content.Server/DeltaV/Paper/SignatureSystem.cs | 1 - Resources/Locale/en-US/deltav/paper/signature.ftl | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Content.Server/DeltaV/Paper/SignatureSystem.cs b/Content.Server/DeltaV/Paper/SignatureSystem.cs index cc788219f48..7250ebf47d6 100644 --- a/Content.Server/DeltaV/Paper/SignatureSystem.cs +++ b/Content.Server/DeltaV/Paper/SignatureSystem.cs @@ -63,7 +63,6 @@ public bool TrySignPaper(EntityUid paper, EntityUid signer, PaperComponent? pape { StampedName = signatureName, StampedColor = Color.DarkSlateGray, // TODO: make configurable? Perhaps it should depend on the pen. - }; if (!paperComp.StampedBy.Contains(stampInfo) && _paper.TryStamp(paper, stampInfo, SignatureStampState, paperComp)) diff --git a/Resources/Locale/en-US/deltav/paper/signature.ftl b/Resources/Locale/en-US/deltav/paper/signature.ftl index a2941bd797e..e69263a0a8a 100644 --- a/Resources/Locale/en-US/deltav/paper/signature.ftl +++ b/Resources/Locale/en-US/deltav/paper/signature.ftl @@ -1,5 +1,5 @@ paper-sign-verb = Sign paper-signed-other = {CAPITALIZE(THE($user))} places their signature on {THE($target)}. -paper-signed-self = You place you signature on {THE($target)}. +paper-signed-self = You place your signature on {THE($target)}. paper-signed-failure = You cannot place your signature on {THE($target)} From e346a830b539620a8b39396ab917881c04241ed8 Mon Sep 17 00:00:00 2001 From: fox Date: Wed, 8 May 2024 17:13:05 +0300 Subject: [PATCH 3/3] Suggestions implemented --- Content.Server/DeltaV/Paper/SignatureSystem.cs | 14 +++++++------- Resources/Locale/en-US/deltav/paper/signature.ftl | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Content.Server/DeltaV/Paper/SignatureSystem.cs b/Content.Server/DeltaV/Paper/SignatureSystem.cs index 7250ebf47d6..a5877fd0aba 100644 --- a/Content.Server/DeltaV/Paper/SignatureSystem.cs +++ b/Content.Server/DeltaV/Paper/SignatureSystem.cs @@ -12,14 +12,14 @@ namespace Content.Server.DeltaV.Paper; public sealed class SignatureSystem : EntitySystem { - [Dependency] private readonly TagSystem _tagSystem = default!; - [Dependency] private readonly PaperSystem _paper = default!; + [Dependency] private readonly AudioSystem _audio = default!; [Dependency] private readonly IdCardSystem _idCard = default!; + [Dependency] private readonly PaperSystem _paper = default!; [Dependency] private readonly PopupSystem _popup = default!; - [Dependency] private readonly AudioSystem _audio = default!; + [Dependency] private readonly TagSystem _tagSystem = default!; // The sprite used to visualize "signatures" on paper entities. - private static readonly string SignatureStampState = "paper_stamp-signature"; + private const string SignatureStampState = "paper_stamp-signature"; public override void Initialize() { @@ -39,7 +39,7 @@ private void OnGetAltVerbs(EntityUid uid, PaperComponent component, GetVerbsEven { Act = () => { - TrySignPaper(uid, args.User, component); + TrySignPaper((uid, component), args.User); }, Text = Loc.GetString("paper-sign-verb"), DoContactInteraction = true, @@ -51,9 +51,9 @@ private void OnGetAltVerbs(EntityUid uid, PaperComponent component, GetVerbsEven /// /// Tries add add a signature to the paper with signer's name. /// - /// Whether to avoid showing a popup if the paper cannot be signed. - public bool TrySignPaper(EntityUid paper, EntityUid signer, PaperComponent? paperComp = null) + public bool TrySignPaper(Entity paper, EntityUid signer) { + var paperComp = paper.Comp; if (!Resolve(paper, ref paperComp)) return false; diff --git a/Resources/Locale/en-US/deltav/paper/signature.ftl b/Resources/Locale/en-US/deltav/paper/signature.ftl index e69263a0a8a..87741c962c0 100644 --- a/Resources/Locale/en-US/deltav/paper/signature.ftl +++ b/Resources/Locale/en-US/deltav/paper/signature.ftl @@ -1,5 +1,5 @@ paper-sign-verb = Sign -paper-signed-other = {CAPITALIZE(THE($user))} places their signature on {THE($target)}. -paper-signed-self = You place your signature on {THE($target)}. -paper-signed-failure = You cannot place your signature on {THE($target)} +paper-signed-other = {CAPITALIZE(THE($user))} signs {THE($target)}. +paper-signed-self = You sign {THE($target)}. +paper-signed-failure = You cannot sign {THE($target)}