Skip to content

Commit

Permalink
Merge pull request #1313 from Darkmajia/signatures
Browse files Browse the repository at this point in the history
robust signatures (plus syndicate recruiter fixes)
  • Loading branch information
formlessnameless authored Jan 13, 2025
2 parents 8a303f5 + 17a7843 commit a4918ce
Show file tree
Hide file tree
Showing 55 changed files with 1,306 additions and 89 deletions.
4 changes: 4 additions & 0 deletions Content.Client/Paper/UI/StampLabel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public sealed partial class StampLabel : Label
/// this control.
public float Orientation = 0.0f;

/// Determines whether stamp noise is applied on the shader
public bool StampNoise = true; // imp

public StampLabel()
{
RobustXamlLoader.Load(this);
Expand All @@ -45,6 +48,7 @@ protected override void Draw(DrawingHandleScreen handle)
PixelPosition.Y * MathF.Cos(Orientation) + PixelPosition.X * MathF.Sin(Orientation));

_stampShader?.SetParameter("objCoord", GlobalPosition * UIScale * new Vector2(1, -1));
_stampShader?.SetParameter("useStampNoise", StampNoise); // imp
handle.UseShader(_stampShader);
handle.SetTransform(GlobalPixelPosition - PixelPosition + offset, Orientation, _textScaling);
base.Draw(handle);
Expand Down
57 changes: 36 additions & 21 deletions Content.Client/Paper/UI/StampWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public sealed partial class StampWidget : PanelContainer
private StyleBoxTexture? _borderTexture;
private ShaderInstance? _stampShader;

/// Imp edit, determines whether stamp noise is applied on the shader
public bool StampNoise = true;

public float Orientation
{
get => StampedByLabel.Orientation;
Expand All @@ -23,51 +26,63 @@ public float Orientation

public StampDisplayInfo StampInfo {
set {
// pretty much this whole thing is an imp edit

var resCache = IoCManager.Resolve<IResourceCache>();
var prototypes = IoCManager.Resolve<IPrototypeManager>();
var icon = value.StampLargeIcon;
if (icon != null)
var hasIcon = value.HasIcon;

if (hasIcon)
{
var resCache = IoCManager.Resolve<IResourceCache>();
var borderImage = resCache.GetResource<TextureResource>(
"/Textures/_Impstation/Interface/Paper/Stamps/" + icon + ".png");
"/Textures/Interface/Paper/paper_stamp_border.svg.96dpi.png");

if (icon != null)
{
borderImage = resCache.GetResource<TextureResource>(
"/Textures/_Impstation/Interface/Paper/Stamps/" + icon + ".png");

// make stamps 50% larger to better match the original stamp sizes
var width = (int)(borderImage.Texture.Width * 1.5);
var height = (int)(borderImage.Texture.Height * 1.5);
SetSize = new Vector2(width, height);
}

_borderTexture = new StyleBoxTexture { Texture = borderImage };
_borderTexture.SetPatchMargin(StyleBoxTexture.Margin.All, 7.0f);
PanelOverride = _borderTexture;

// make stamps 50% larger to better match the original stamp sizes
var width = (int)(borderImage.Texture.Width * 1.5);
var height = (int)(borderImage.Texture.Height * 1.5);
SetSize = new Vector2(width, height);
}

else
{
StampNoise = false;
StampedByLabel.StampNoise = false;
}

if (icon == null)
{
StampedByLabel.Text = Loc.GetString(value.StampedName);
StampedByLabel.FontColorOverride = value.StampedColor;
ModulateSelfOverride = value.StampedColor;

var font = value.StampFont;
if (font != null)
StampedByLabel.FontOverride = new VectorFont(resCache.GetResource<FontResource>(font), 40);
}

_stampShader = prototypes.Index<ShaderPrototype>("PaperStamp").InstanceUnique();
}
}

public StampWidget()
{
RobustXamlLoader.Load(this);
var prototypes = IoCManager.Resolve<IPrototypeManager>();
_stampShader = prototypes.Index<ShaderPrototype>("PaperStamp").InstanceUnique();

if (PanelOverride != null)
return;

var resCache = IoCManager.Resolve<IResourceCache>();
var borderImage = resCache.GetResource<TextureResource>(
"/Textures/Interface/Paper/paper_stamp_border.svg.96dpi.png");
_borderTexture = new StyleBoxTexture { Texture = borderImage };
_borderTexture.SetPatchMargin(StyleBoxTexture.Margin.All, 7.0f);
PanelOverride = _borderTexture;
}

protected override void Draw(DrawingHandleScreen handle)
{
_stampShader?.SetParameter("objCoord", GlobalPosition * UIScale * new Vector2(1, -1));
_stampShader?.SetParameter("useStampNoise", StampNoise); // imp
handle.UseShader(_stampShader);
handle.SetTransform(GlobalPosition * UIScale, Orientation, Vector2.One);
base.Draw(handle);
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Nuke/NukeCodePaperSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public bool SendNukeCodes(EntityUid station)
"paper_stamp-centcom",
new List<StampDisplayInfo>
{
new StampDisplayInfo { StampedName = Loc.GetString("stamp-component-stamped-name-centcom"), StampedColor = Color.FromHex("#BB3232"), StampLargeIcon = "large_stamp-centcom" },
new StampDisplayInfo { StampedName = Loc.GetString("stamp-component-stamped-name-centcom"), StampedColor = Color.FromHex("#BB3232"), StampLargeIcon = "large_stamp-centcom" }, // imp edit
}
);
_faxSystem.Receive(faxEnt, printout, null, fax);
Expand Down
79 changes: 79 additions & 0 deletions Content.Server/_DV/Paper/SignatureSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Content.Server.Crayon;
using Content.Shared.DV.Paper;
using Content.Shared.DV.Traits;
using Content.Shared.Paper;
using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
using Robust.Shared.ContentPack;
using Robust.Shared.Player;

namespace Content.Server.DV.Paper;

public sealed class SignatureSystem : SharedSignatureSystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly PaperSystem _paper = default!;
[Dependency] private readonly IResourceManager _resourceManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SignatureWriterComponent, SignAttemptEvent>(OnSignAttempt);
}

private void OnSignAttempt(Entity<SignatureWriterComponent> ent, ref SignAttemptEvent args)
{
if (args.Cancelled)
return;

var paper = args.Paper;
var signer = args.User;
var pen = args.Pen;
var paperComp = args.Paper.Comp;
var signatureComp = ent.Comp;

var signatureName = DetermineEntitySignature(signer);
var signatureColor = signatureComp.Color;
var signatureFont = "/Fonts/NotoSans/NotoSans-Regular.ttf"; // Noto Sans as fallback

if (signatureComp.Font is { } penFont)
signatureFont = penFont;
else if (TryComp<SignatureFontComponent>(signer, out var signerComp) && signerComp.Font is { } signerFont)
signatureFont = signerFont;

if (!_resourceManager.TryContentFileRead(signatureFont, out _))
signatureFont = "/Fonts/NotoSans/NotoSans-Regular.ttf"; // The font failed to read, so reset to Noto Sans

if (TryComp<CrayonComponent>(pen, out var crayon))
signatureColor = crayon.Color;

var stampInfo = new StampDisplayInfo()
{
StampedName = signatureName,
StampedColor = signatureColor,
HasIcon = false,
StampFont = signatureFont
};

// TODO: remove redunant contains check when TryStamp isnt a meme
if (paperComp.StampedBy.Contains(stampInfo) || !_paper.TryStamp(paper, stampInfo, SignatureStampState))
{
// Show an error popup.
_popup.PopupEntity(Loc.GetString("paper-signed-failure", ("target", paper.Owner)), signer, signer, PopupType.SmallCaution);

args.Cancelled = true;
return;
}

// 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.PlayEntity(paperComp.Sound, Filter.Pvs(signer), signer, true);
}
}
13 changes: 13 additions & 0 deletions Content.Server/_DV/Recruiter/RecruiterPenSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using Content.Server.Objectives.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.DV.Paper;
using Content.Shared.DV.Recruiter;
using Content.Shared.Popups;
using Robust.Shared.Prototypes;

namespace Content.Server.DV.Recruiter;

Expand All @@ -15,6 +17,7 @@ public sealed class RecruiterPenSystem : SharedRecruiterPenSystem
{
[Dependency] private readonly ForensicsSystem _forensics = default!;
[Dependency] private readonly SolutionTransferSystem _transfer = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;

protected override void DrawBlood(EntityUid uid, Entity<SolutionComponent> dest, EntityUid user)
{
Expand All @@ -36,6 +39,12 @@ protected override void DrawBlood(EntityUid uid, Entity<SolutionComponent> dest,
// this is why you have to keep the pen safe, it has the dna of everyone you recruited!
_forensics.TransferDna(uid, user, canDnaBeCleaned: false);

if (TryComp<SignatureWriterComponent>(uid, out var signatureComp))
{
var bloodColor = blood.Comp.Solution.GetColor(_proto);
signatureComp.Color = bloodColor;
}

Popup.PopupEntity(Loc.GetString("recruiter-pen-pricked", ("pen", uid)), user, user, PopupType.LargeCaution);
}

Expand All @@ -45,7 +54,11 @@ protected override void Recruit(Entity<RecruiterPenComponent> ent, EntityUid use
if (!ent.Comp.Recruited.Add(user))
return;

if (!Mind.TryGetMind(user, out var userMindId, out _))
return;

if (ent.Comp.RecruiterMind is {} mindId &&
mindId != userMindId &&
Mind.TryGetObjectiveComp<RecruitingConditionComponent>(mindId, out var obj, null))
{
obj.Recruited++;
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Crayon/SharedCrayonSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Content.Shared.Crayon;
namespace Content.Shared.Crayon;

[Virtual]
public abstract class SharedCrayonSystem : EntitySystem { }
4 changes: 2 additions & 2 deletions Content.Shared/Paper/PaperSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private static StampDisplayInfo GetStampInfo(StampComponent stamp)
{
StampedName = stamp.StampedName,
StampedColor = stamp.StampedColor,
StampLargeIcon = stamp.StampLargeIcon
StampLargeIcon = stamp.StampLargeIcon // imp
};
}

Expand Down Expand Up @@ -216,7 +216,7 @@ public void SetContent(Entity<PaperComponent> entity, string content)
_appearance.SetData(entity, PaperVisuals.Status, status, appearance);
}

private void UpdateUserInterface(Entity<PaperComponent> entity)
public void UpdateUserInterface(Entity<PaperComponent> entity)
{
_uiSystem.SetUiState(entity.Owner, PaperUiKey.Key, new PaperBoundUserInterfaceState(entity.Comp.Content, entity.Comp.StampedBy, entity.Comp.Mode));
}
Expand Down
10 changes: 8 additions & 2 deletions Content.Shared/Paper/StampComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ public partial struct StampDisplayInfo
public Color StampedColor;

[DataField("stampLargeIcon")]
public string? StampLargeIcon;
public string? StampLargeIcon; // imp

[DataField("stampFont")]
public string? StampFont; // imp

[DataField("hasIcon")]
public bool HasIcon = true; // imp
};

[RegisterComponent]
Expand All @@ -46,7 +52,7 @@ public sealed partial class StampComponent : Component
/// The sprite state of the stamp to display on the paper when read from stamp Sprite path.
/// </summary>
[DataField("stampLargeIcon")]
public string? StampLargeIcon = null;
public string? StampLargeIcon = null; // imp

/// <summary>
/// The color of the ink used by the stamp in UIs
Expand Down
53 changes: 53 additions & 0 deletions Content.Shared/_DV/Paper/ItemToggleSignatureWriterComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace Content.Shared.DV.Paper;

[RegisterComponent]
public sealed partial class ItemToggleSignatureWriterComponent : Component
{
/// <summary>
/// The font used when this item is activated.
/// </summary>
[DataField("activatedFont")]
public string? ActivatedFont;

/// <summary>
/// The list of fonts used when this item is activated.
/// </summary>
[DataField("activatedFontList")]
public Dictionary<string, string> ActivatedFontList = new();

/// <summary>
/// The color used when this item is activated.
/// </summary>
[DataField("activatedColor")]
public Color? ActivatedColor;

/// <summary>
/// The list of colors used when this item is activated.
/// </summary>
[DataField("activatedColorList")]
public Dictionary<string, Color> ActivatedColorList = new();

/// <summary>
/// The font used when this item is deactivated.
/// </summary>
[DataField("deactivatedFont")]
public string? DeactivatedFont;

/// <summary>
/// The list of fonts used when this item is deactivated.
/// </summary>
[DataField("deactivatedFontList")]
public Dictionary<string, string> DeactivatedFontList = new();

/// <summary>
/// The color used when this item is deactivated.
/// </summary>
[DataField("deactivatedColor")]
public Color? DeactivatedColor;

/// <summary>
/// The list of colors used when this item is deactivated.
/// </summary>
[DataField("deactivatedColorList")]
public Dictionary<string, Color> DeactivatedColorList = new();
}
Loading

0 comments on commit a4918ce

Please sign in to comment.