Improve paper stamping experience (#17135)

This commit is contained in:
eoineoineoin
2023-08-13 19:28:10 +01:00
committed by GitHub
parent ae2dcc8aba
commit 4ccc8a04be
28 changed files with 629 additions and 202 deletions

View File

@@ -1,9 +1,10 @@
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Components;
using Content.Server.EUI;
using Content.Server.Ghost.Components;
using Content.Shared.Eui;
using Content.Shared.Fax;
using Content.Shared.Follower;
using Content.Shared.Paper;
namespace Content.Server.Fax.AdminUI;
@@ -53,7 +54,8 @@ public sealed class AdminFaxEui : BaseEui
}
case AdminFaxEuiMsg.Send sendData:
{
var printout = new FaxPrintout(sendData.Content, sendData.Title, null, sendData.StampState, new() { sendData.From });
var printout = new FaxPrintout(sendData.Content, sendData.Title, null, sendData.StampState,
new() { new StampDisplayInfo { StampedName = sendData.From, StampedColor = sendData.StampColor } });
_faxSystem.Receive(sendData.Target, printout);
break;
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Paper;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
@@ -136,18 +137,18 @@ public sealed class FaxPrintout
public string? StampState { get; }
[DataField("stampedBy")]
public List<string> StampedBy { get; } = new();
public List<StampDisplayInfo> StampedBy { get; } = new();
private FaxPrintout()
{
}
public FaxPrintout(string content, string name, string? prototypeId = null, string? stampState = null, List<string>? stampedBy = null)
public FaxPrintout(string content, string name, string? prototypeId = null, string? stampState = null, List<StampDisplayInfo>? stampedBy = null)
{
Content = content;
Name = name;
PrototypeId = prototypeId ?? "";
StampState = stampState;
StampedBy = stampedBy ?? new List<string>();
StampedBy = stampedBy ?? new List<StampDisplayInfo>();
}
}

View File

@@ -16,6 +16,7 @@ using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Fax;
using Content.Shared.Interaction;
using Content.Shared.Paper;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
@@ -272,7 +273,7 @@ public sealed class FaxSystem : EntitySystem
return;
args.Data.TryGetValue(FaxConstants.FaxPaperStampStateData, out string? stampState);
args.Data.TryGetValue(FaxConstants.FaxPaperStampedByData, out List<string>? stampedBy);
args.Data.TryGetValue(FaxConstants.FaxPaperStampedByData, out List<StampDisplayInfo>? stampedBy);
args.Data.TryGetValue(FaxConstants.FaxPaperPrototypeData, out string? prototypeId);
var printout = new FaxPrintout(content, name, prototypeId, stampState, stampedBy);
@@ -461,9 +462,9 @@ public sealed class FaxSystem : EntitySystem
// Apply stamps
if (printout.StampState != null)
{
foreach (var stampedBy in printout.StampedBy)
foreach (var stamp in printout.StampedBy)
{
_paperSystem.TryStamp(printed, stampedBy, printout.StampState);
_paperSystem.TryStamp(printed, stamp, printout.StampState);
}
}
}

View File

@@ -5,6 +5,7 @@ using Content.Server.Fax;
using Content.Server.Paper;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Paper;
using Robust.Shared.Random;
using Robust.Shared.Utility;
@@ -66,7 +67,11 @@ namespace Content.Server.Nuke
Loc.GetString("nuke-codes-fax-paper-name"),
null,
"paper_stamp-centcom",
new() { Loc.GetString("stamp-component-stamped-name-centcom") });
new List<StampDisplayInfo>
{
new StampDisplayInfo { StampedName = Loc.GetString("stamp-component-stamped-name-centcom"), StampedColor = Color.FromHex("#BB3232") },
}
);
_faxSystem.Receive(faxEnt, printout, null, fax);
wasSent = true;

View File

@@ -1,24 +1,24 @@
using Content.Shared.Paper;
using Robust.Shared.GameStates;
namespace Content.Server.Paper
namespace Content.Server.Paper;
[NetworkedComponent, RegisterComponent]
public sealed class PaperComponent : SharedPaperComponent
{
[NetworkedComponent, RegisterComponent]
public sealed class PaperComponent : SharedPaperComponent
{
public PaperAction Mode;
[DataField("content")]
public string Content { get; set; } = "";
public PaperAction Mode;
[DataField("content")]
public string Content { get; set; } = "";
[DataField("contentSize")]
public int ContentSize { get; set; } = 6000;
[DataField("contentSize")]
public int ContentSize { get; set; } = 6000;
[DataField("stampedBy")]
public List<string> StampedBy { get; set; } = new();
/// <summary>
/// Stamp to be displayed on the paper, state from beauracracy.rsi
/// </summary>
[DataField("stampState")]
public string? StampState { get; set; }
}
[DataField("stampedBy")]
public List<StampDisplayInfo> StampedBy { get; set; } = new();
/// <summary>
/// Stamp to be displayed on the paper, state from beauracracy.rsi
/// </summary>
[DataField("stampState")]
public string? StampState { get; set; }
}

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Popups;
using Content.Server.UserInterface;
@@ -90,7 +91,7 @@ namespace Content.Server.Paper
if (paperComp.StampedBy.Count > 0)
{
var commaSeparated = string.Join(", ", paperComp.StampedBy);
var commaSeparated = string.Join(", ", paperComp.StampedBy.Select(s => Loc.GetString(s.StampedName)));
args.PushMarkup(
Loc.GetString(
"paper-component-examine-detail-stamped-by", ("paper", uid), ("stamps", commaSeparated))
@@ -114,13 +115,15 @@ namespace Content.Server.Paper
}
// If a stamp, attempt to stamp paper
if (TryComp<StampComponent>(args.Used, out var stampComp) && TryStamp(uid, stampComp.StampedName, stampComp.StampState, paperComp))
if (TryComp<StampComponent>(args.Used, out var stampComp) && TryStamp(uid, GetStampInfo(stampComp), stampComp.StampState, paperComp))
{
// successfully stamped, play popup
var stampPaperOtherMessage = Loc.GetString("paper-component-action-stamp-paper-other", ("user", Identity.Entity(args.User, EntityManager)), ("target", Identity.Entity(args.Target, EntityManager)), ("stamp", args.Used));
_popupSystem.PopupEntity(stampPaperOtherMessage, args.User, Filter.PvsExcept(args.User, entityManager: EntityManager), true);
var stampPaperOtherMessage = Loc.GetString("paper-component-action-stamp-paper-other",
("user", args.User), ("target", args.Target), ("stamp", args.Used));
var stampPaperSelfMessage = Loc.GetString("paper-component-action-stamp-paper-self", ("target", Identity.Entity(args.Target, EntityManager)), ("stamp", args.Used));
_popupSystem.PopupEntity(stampPaperOtherMessage, args.User, Filter.PvsExcept(args.User, entityManager: EntityManager), true);
var stampPaperSelfMessage = Loc.GetString("paper-component-action-stamp-paper-self",
("target", args.Target), ("stamp", args.Used));
_popupSystem.PopupEntity(stampPaperSelfMessage, args.User, args.User);
_audio.PlayPvs(stampComp.Sound, uid);
@@ -129,6 +132,14 @@ namespace Content.Server.Paper
}
}
private StampDisplayInfo GetStampInfo(StampComponent stamp)
{
return new StampDisplayInfo {
StampedName = stamp.StampedName,
StampedColor = stamp.StampedColor
};
}
private void OnInputTextMessage(EntityUid uid, PaperComponent paperComp, PaperInputTextMessage args)
{
if (string.IsNullOrEmpty(args.Text))
@@ -161,17 +172,19 @@ namespace Content.Server.Paper
/// <summary>
/// Accepts the name and state to be stamped onto the paper, returns true if successful.
/// </summary>
public bool TryStamp(EntityUid uid, string stampName, string stampState, PaperComponent? paperComp = null)
public bool TryStamp(EntityUid uid, StampDisplayInfo stampInfo, string spriteStampState, PaperComponent? paperComp = null)
{
if (!Resolve(uid, ref paperComp))
return false;
if (!paperComp.StampedBy.Contains(Loc.GetString(stampName)))
if (!paperComp.StampedBy.Contains(stampInfo))
{
paperComp.StampedBy.Add(Loc.GetString(stampName));
paperComp.StampedBy.Add(stampInfo);
if (paperComp.StampState == null && TryComp<AppearanceComponent>(uid, out var appearance))
{
paperComp.StampState = stampState;
paperComp.StampState = spriteStampState;
// Would be nice to be able to display multiple sprites on the paper
// but most of the existing images overlap
_appearance.SetData(uid, PaperVisuals.Stamp, paperComp.StampState, appearance);
}
}