Files
wwdpublic/Content.Server/DeltaV/Paper/SignatureSystem.cs
Mnemotechnican 476e6ded46 Port Paper Signatures (#456)
# Description
Ports delta-v paper signatures implemented by me in
https://github.com/DeltaV-Station/Delta-v/pull/1172, including the
changes later introduced by deltanedas in
https://github.com/DeltaV-Station/Delta-v/pull/1345.

Everything should be pretty self-explanatory, see the original PR for
details.

---

<!--
This is default collapsed, readers click to expand it and see all your
media
The PR media section can get very large at times, so this is a good way
to keep it clean
The title is written using HTML tags
The title must be within the <summary> tags or you won't see it
-->

<details><summary><h1>Media</h1></summary>
<p>


![image](https://github.com/Simple-Station/Einstein-Engines/assets/69920617/50737402-a60d-425a-8938-f6e47427b22b)

(see the original PR for a video demonstation)

</p>
</details>

---

# Changelog

🆑
- add: You can now sign paper by alt-clicking it while holding a pen.

---------

Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com>
Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
2024-07-05 13:33:39 -04:00

105 lines
3.5 KiB
C#

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 _tags = 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(Entity<PaperComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;
if (args.Using is not {} pen || !_tags.HasTag(pen, "Write"))
return;
var user = args.User;
AlternativeVerb verb = new()
{
Act = () =>
{
TrySignPaper(ent, user, pen);
},
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, EntityUid pen)
{
var comp = paper.Comp;
var ev = new SignAttemptEvent(paper, signer);
RaiseLocalEvent(pen, ref ev);
if (ev.Cancelled)
return false;
var signatureName = DetermineEntitySignature(signer);
var stampInfo = new StampDisplayInfo()
{
StampedName = signatureName,
StampedColor = Color.DarkSlateGray, //TODO Make this configurable depending on the pen.
};
if (!comp.StampedBy.Contains(stampInfo) && _paper.TryStamp(paper, stampInfo, SignatureStampState, comp))
{
// Show popups and play a paper writing sound
var signedOtherMessage = Loc.GetString("paper-signed-other", ("user", signer), ("target", paper.Owner));
_popup.PopupEntity(signedOtherMessage, signer, Filter.PvsExcept(signer, entityManager: EntityManager), true);
var signedSelfMessage = Loc.GetString("paper-signed-self", ("target", paper.Owner));
_popup.PopupEntity(signedSelfMessage, signer, signer);
_audio.PlayPvs(comp.Sound, signer);
_paper.UpdateUserInterface(paper, comp);
return true;
}
else
{
// Show an error popup
_popup.PopupEntity(Loc.GetString("paper-signed-failure", ("target", paper.Owner)), 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);
}
}