Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paper signatures #1172

Merged
merged 3 commits into from
May 14, 2024
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
103 changes: 103 additions & 0 deletions Content.Server/DeltaV/Paper/SignatureSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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 AudioSystem _audio = default!;
[Dependency] private readonly IdCardSystem _idCard = default!;
[Dependency] private readonly PaperSystem _paper = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;

// The sprite used to visualize "signatures" on paper entities.
private const string SignatureStampState = "paper_stamp-signature";

public override void Initialize()
{
SubscribeLocalEvent<PaperComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs);
}

private void OnGetAltVerbs(EntityUid uid, PaperComponent component, GetVerbsEvent<AlternativeVerb> 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, component), args.User);
},
Text = Loc.GetString("paper-sign-verb"),
DoContactInteraction = true,
Priority = 10
};
args.Verbs.Add(verb);
}

/// <summary>
/// Tries add add a signature to the paper with signer's name.
/// </summary>
public bool TrySignPaper(Entity<PaperComponent?> paper, EntityUid signer)
{
var paperComp = paper.Comp;
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);
}
}
5 changes: 5 additions & 0 deletions Resources/Locale/en-US/deltav/paper/signature.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
paper-sign-verb = Sign

paper-signed-other = {CAPITALIZE(THE($user))} signs {THE($target)}.
paper-signed-self = You sign {THE($target)}.
paper-signed-failure = You cannot sign {THE($target)}
5 changes: 4 additions & 1 deletion Resources/Textures/Objects/Misc/bureaucracy.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -259,6 +259,9 @@
},
{
"name": "paper_stamp-psychologist"
},
{
"name": "paper_stamp-signature"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading