]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Move PaperSystem to Shared (#30592)
authorPlykiya <58439124+Plykiya@users.noreply.github.com>
Mon, 5 Aug 2024 04:23:23 +0000 (21:23 -0700)
committerGitHub <noreply@github.com>
Mon, 5 Aug 2024 04:23:23 +0000 (14:23 +1000)
* Fix paper system late localization

* IS THIS WHAT YOU WANT

* well I guess this is happening now

* fix the BUI

* did that even do anything before?

* again with the escapeformatting...

* Dirtying

* Move dirty to function

* Rename PaperSystem to PaperVisualizerSystem

* Fix namespace

* how many namespace changes must I suffer through

* SetContent is for Setting Content

* minor shuffling

* review

---------

Co-authored-by: plykiya <plykiya@protonmail.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
22 files changed:
Content.Client/Paper/PaperComponent.cs [deleted file]
Content.Client/Paper/UI/PaperBoundUserInterface.cs
Content.Client/Paper/UI/PaperVisualizerSystem.cs [moved from Content.Client/Paper/UI/PaperSystem.cs with 82% similarity]
Content.Client/Paper/UI/PaperVisualsComponent.cs
Content.Client/Paper/UI/PaperWindow.xaml.cs
Content.Client/Tips/TippyUI.xaml.cs
Content.Client/Tips/TippyUIController.cs
Content.Server/Cargo/Systems/CargoSystem.Bounty.cs
Content.Server/Cargo/Systems/CargoSystem.Orders.cs
Content.Server/Cargo/Systems/CargoSystem.cs
Content.Server/Fax/FaxSystem.cs
Content.Server/Forensics/Systems/ForensicScannerSystem.cs
Content.Server/Labels/Label/LabelSystem.cs
Content.Server/Nuke/NukeCodePaperSystem.cs
Content.Server/Paper/PaperComponent.cs [deleted file]
Content.Server/Paper/PaperRandomStorySystem.cs
Content.Server/Paper/PaperSystem.cs [deleted file]
Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs
Content.Shared/Paper/ActivateOnPaperOpenedComponent.cs [moved from Content.Server/Paper/ActivateOnPaperOpenedComponent.cs with 78% similarity]
Content.Shared/Paper/PaperComponent.cs [moved from Content.Shared/Paper/SharedPaperComponent.cs with 68% similarity]
Content.Shared/Paper/PaperSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Misc/paper.yml

diff --git a/Content.Client/Paper/PaperComponent.cs b/Content.Client/Paper/PaperComponent.cs
deleted file mode 100644 (file)
index 1dc827b..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-using Content.Shared.Paper;
-
-namespace Content.Client.Paper;
-
-[RegisterComponent]
-public sealed partial class PaperComponent : SharedPaperComponent;
index f3ad1e347e76dc4a0b886073bbd20eeab721731c..63645bc01e910d4ce8359261c167e9b5291c701a 100644 (file)
@@ -2,7 +2,7 @@ using JetBrains.Annotations;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controls;
 using Robust.Shared.Utility;
-using static Content.Shared.Paper.SharedPaperComponent;
+using static Content.Shared.Paper.PaperComponent;
 
 namespace Content.Client.Paper.UI;
 
similarity index 82%
rename from Content.Client/Paper/UI/PaperSystem.cs
rename to Content.Client/Paper/UI/PaperVisualizerSystem.cs
index f75d04a26bd3dba6862e5f0ae036b151de0b0575..a0d05736adbbf8e0ed1cd567849924b81821c24a 100644 (file)
@@ -1,10 +1,10 @@
 using Robust.Client.GameObjects;
 
-using static Content.Shared.Paper.SharedPaperComponent;
+using static Content.Shared.Paper.PaperComponent;
 
-namespace Content.Client.Paper;
+namespace Content.Client.Paper.UI;
 
-public sealed class PaperSystem : VisualizerSystem<PaperVisualsComponent>
+public sealed class PaperVisualizerSystem : VisualizerSystem<PaperVisualsComponent>
 {
     protected override void OnAppearanceChange(EntityUid uid, PaperVisualsComponent component, ref AppearanceChangeEvent args)
     {
index 95040e77e65005182fed81808064cfad771552e1..f0dee3cf907f11d70cbb2148bfb242e163bdeeff 100644 (file)
@@ -1,6 +1,6 @@
 using System.Numerics;
 
-namespace Content.Client.Paper;
+namespace Content.Client.Paper.UI;
 
 [RegisterComponent]
 public sealed partial class PaperVisualsComponent : Component
index f7cace642ce5ae311603c9c05ff8adf856f54a91..81b831068c39298790919d52b99e5b54e0e1819c 100644 (file)
@@ -215,9 +215,9 @@ namespace Content.Client.Paper.UI
         ///     Initialize the paper contents, i.e. the text typed by the
         ///     user and any stamps that have peen put on the page.
         /// </summary>
-        public void Populate(SharedPaperComponent.PaperBoundUserInterfaceState state)
+        public void Populate(PaperComponent.PaperBoundUserInterfaceState state)
         {
-            bool isEditing = state.Mode == SharedPaperComponent.PaperAction.Write;
+            bool isEditing = state.Mode == PaperComponent.PaperAction.Write;
             bool wasEditing = InputContainer.Visible;
             InputContainer.Visible = isEditing;
             EditButtons.Visible = isEditing;
index de3eaf4f51b95f41608b6f1208b2c1050e8c08bd..4a2c4bfe2f22bdbf68265d020a29c3cb2e52d89d 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Client.Paper;
+using Content.Client.Paper.UI;
 using Robust.Client.AutoGenerated;
 using Robust.Client.Graphics;
 using Robust.Client.ResourceManagement;
index 2cc694d97d469e593af8a71d9a8dae9245385e8f..7737a3d6982e20616a6bd4242aa6fe8de711285f 100644 (file)
@@ -1,21 +1,17 @@
-using Content.Client.Gameplay;
 using System.Numerics;
 using Content.Client.Message;
-using Content.Client.Paper;
+using Content.Client.Paper.UI;
 using Content.Shared.CCVar;
 using Content.Shared.Movement.Components;
 using Content.Shared.Tips;
 using Robust.Client.GameObjects;
 using Robust.Client.ResourceManagement;
-using Robust.Client.State;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controllers;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.Audio;
 using Robust.Shared.Configuration;
-using Robust.Shared.Console;
 using Robust.Shared.Map;
-using Robust.Shared.Prototypes;
 using Robust.Shared.Timing;
 using static Content.Client.Tips.TippyUI;
 
index 89c4635b0c8d265980d53cc6c85b63119e732820..e118f4936392f45d5d1c31077af1392b17dbc914 100644 (file)
@@ -3,13 +3,13 @@ using System.Linq;
 using Content.Server.Cargo.Components;
 using Content.Server.Labels;
 using Content.Server.NameIdentifier;
-using Content.Server.Paper;
 using Content.Shared.Access.Components;
 using Content.Shared.Cargo;
 using Content.Shared.Cargo.Components;
 using Content.Shared.Cargo.Prototypes;
 using Content.Shared.Database;
 using Content.Shared.NameIdentifier;
+using Content.Shared.Paper;
 using Content.Shared.Stacks;
 using Content.Shared.Whitelist;
 using JetBrains.Annotations;
@@ -125,7 +125,7 @@ public sealed partial class CargoSystem
             msg.PushNewline();
         }
         msg.AddMarkup(Loc.GetString("bounty-console-manifest-reward", ("reward", prototype.Reward)));
-        _paperSystem.SetContent(uid, msg.ToMarkup(), paper);
+        _paperSystem.SetContent((uid, paper), msg.ToMarkup());
     }
 
     /// <summary>
index 7a2a3d474aa85596077a9843658a87c349b6f076..f68fe0fa63a22d451df2333b8307b15389c9fe0b 100644 (file)
@@ -1,7 +1,6 @@
 using System.Diagnostics.CodeAnalysis;
 using Content.Server.Cargo.Components;
 using Content.Server.Labels.Components;
-using Content.Server.Paper;
 using Content.Server.Station.Components;
 using Content.Shared.Cargo;
 using Content.Shared.Cargo.BUI;
@@ -10,10 +9,9 @@ using Content.Shared.Cargo.Events;
 using Content.Shared.Cargo.Prototypes;
 using Content.Shared.Database;
 using Content.Shared.Interaction;
+using Content.Shared.Paper;
 using Robust.Shared.Map;
-using Robust.Shared.Player;
 using Robust.Shared.Prototypes;
-using Robust.Shared.Random;
 using Robust.Shared.Utility;
 
 namespace Content.Server.Cargo.Systems
@@ -512,15 +510,14 @@ namespace Content.Server.Cargo.Systems
                 var val = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", order.OrderId));
                 _metaSystem.SetEntityName(printed, val);
 
-                _paperSystem.SetContent(printed, Loc.GetString(
+                _paperSystem.SetContent((printed, paper), Loc.GetString(
                         "cargo-console-paper-print-text",
                         ("orderNumber", order.OrderId),
                         ("itemName", MetaData(item).EntityName),
                         ("orderQuantity", order.OrderQuantity),
                         ("requester", order.Requester),
                         ("reason", order.Reason),
-                        ("approver", order.Approver ?? string.Empty)),
-                    paper);
+                        ("approver", order.Approver ?? string.Empty)));
 
                 // attempt to attach the label to the item
                 if (TryComp<PaperLabelComponent>(item, out var label))
index 1b33404e355574a42fc9c3dec70ea7c6ae2c55a4..0d205d762bcb0c9aa6cfd1713697a8fdae9938f5 100644 (file)
@@ -1,7 +1,6 @@
 using Content.Server.Access.Systems;
 using Content.Server.Cargo.Components;
 using Content.Server.DeviceLinking.Systems;
-using Content.Server.Paper;
 using Content.Server.Popups;
 using Content.Server.Shuttles.Systems;
 using Content.Server.Stack;
@@ -13,6 +12,7 @@ using Content.Shared.Cargo;
 using Content.Shared.Cargo.Components;
 using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Mobs.Components;
+using Content.Shared.Paper;
 using JetBrains.Annotations;
 using Robust.Server.GameObjects;
 using Robust.Shared.Audio.Systems;
index 2b059b4b802f6eb6c8bfb99e91cacff587bf249f..3f10e180fe955dad44d06da4c2c45b7e984d704f 100644 (file)
@@ -5,7 +5,6 @@ using Content.Server.DeviceNetwork;
 using Content.Server.DeviceNetwork.Components;
 using Content.Server.DeviceNetwork.Systems;
 using Content.Server.Labels;
-using Content.Server.Paper;
 using Content.Server.Popups;
 using Content.Server.Power.Components;
 using Content.Server.Tools;
@@ -591,14 +590,14 @@ public sealed class FaxSystem : EntitySystem
 
         if (TryComp<PaperComponent>(printed, out var paper))
         {
-            _paperSystem.SetContent(printed, printout.Content);
+            _paperSystem.SetContent((printed, paper), printout.Content);
 
             // Apply stamps
             if (printout.StampState != null)
             {
                 foreach (var stamp in printout.StampedBy)
                 {
-                    _paperSystem.TryStamp(printed, stamp, printout.StampState);
+                    _paperSystem.TryStamp((printed, paper), stamp, printout.StampState);
                 }
             }
 
index 5e2a562577d96fd9c0006a59f32bab3c3e670a3d..80062569b85466fd9326466f90858cde598fe084 100644 (file)
@@ -1,12 +1,12 @@
 using System.Linq;
 using System.Text;
-using Content.Server.Paper;
 using Content.Server.Popups;
 using Content.Shared.UserInterface;
 using Content.Shared.DoAfter;
 using Content.Shared.Forensics;
 using Content.Shared.Hands.EntitySystems;
 using Content.Shared.Interaction;
+using Content.Shared.Paper;
 using Content.Shared.Verbs;
 using Robust.Shared.Audio.Systems;
 using Robust.Server.GameObjects;
@@ -183,7 +183,7 @@ namespace Content.Server.Forensics
             var printed = EntityManager.SpawnEntity(component.MachineOutput, Transform(uid).Coordinates);
             _handsSystem.PickupOrDrop(args.Actor, printed, checkActionBlocker: false);
 
-            if (!HasComp<PaperComponent>(printed))
+            if (!TryComp<PaperComponent>(printed, out var paperComp))
             {
                 Log.Error("Printed paper did not have PaperComponent.");
                 return;
@@ -217,7 +217,7 @@ namespace Content.Server.Forensics
                 text.AppendLine(residue);
             }
 
-            _paperSystem.SetContent(printed, text.ToString());
+            _paperSystem.SetContent((printed, paperComp), text.ToString());
             _audioSystem.PlayPvs(component.SoundPrint, uid,
                 AudioParams.Default
                 .WithVariation(0.25f)
index cbf29e16a2661e417565c01aafab3eecaea54749..b70c004123a45da825cab5fc7562fc9958afd237 100644 (file)
@@ -1,10 +1,10 @@
 using Content.Server.Labels.Components;
-using Content.Server.Paper;
 using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Examine;
 using Content.Shared.Labels;
 using Content.Shared.Labels.Components;
 using Content.Shared.Labels.EntitySystems;
+using Content.Shared.Paper;
 using JetBrains.Annotations;
 using Robust.Shared.Containers;
 
index 8025e2bbd51ad0fdf5efcbdf863ad9b21e120793..e890aa0845f80ef16a3423661da1c50484292593 100644 (file)
@@ -2,7 +2,6 @@ using System.Diagnostics.CodeAnalysis;
 using Content.Server.Chat.Systems;
 using Content.Server.Fax;
 using Content.Shared.Fax.Components;
-using Content.Server.Paper;
 using Content.Server.Station.Components;
 using Content.Server.Station.Systems;
 using Content.Shared.Paper;
@@ -38,7 +37,8 @@ namespace Content.Server.Nuke
 
             if (TryGetRelativeNukeCode(uid, out var paperContent, station, onlyCurrentStation: component.AllNukesAvailable))
             {
-                _paper.SetContent(uid, paperContent);
+                if (TryComp<PaperComponent>(uid, out var paperComp))
+                    _paper.SetContent((uid, paperComp), paperContent);
             }
         }
 
diff --git a/Content.Server/Paper/PaperComponent.cs b/Content.Server/Paper/PaperComponent.cs
deleted file mode 100644 (file)
index 7b04a77..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-using Content.Shared.Paper;
-
-namespace Content.Server.Paper;
-
-[RegisterComponent]
-public sealed partial class PaperComponent : SharedPaperComponent
-{
-    public PaperAction Mode;
-    [DataField("content")]
-    public string Content { get; set; } = "";
-
-    [DataField("contentSize")]
-    public int ContentSize { get; set; } = 6000;
-
-    [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; }
-
-    [DataField]
-    public bool EditingDisabled = false;
-}
index 156718f54500fefb06fb98f4568a6f47be20c225..2e43058197b4d6c1fbc1be86478cf43f45fc4b0a 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Shared.Paper;
 using Content.Shared.StoryGen;
 
 namespace Content.Server.Paper;
@@ -11,10 +12,10 @@ public sealed class PaperRandomStorySystem : EntitySystem
     {
         base.Initialize();
 
-        SubscribeLocalEvent<PaperRandomStoryComponent, MapInitEvent>(OnMapinit);
+        SubscribeLocalEvent<PaperRandomStoryComponent, MapInitEvent>(OnMapInit);
     }
 
-    private void OnMapinit(Entity<PaperRandomStoryComponent> paperStory, ref MapInitEvent ev)
+    private void OnMapInit(Entity<PaperRandomStoryComponent> paperStory, ref MapInitEvent ev)
     {
         if (!TryComp<PaperComponent>(paperStory, out var paper))
             return;
@@ -22,6 +23,6 @@ public sealed class PaperRandomStorySystem : EntitySystem
         if (!_storyGen.TryGenerateStoryFromTemplate(paperStory.Comp.Template, out var story))
             return;
 
-        _paper.SetContent(paperStory.Owner, story, paper);
+        _paper.SetContent((paperStory.Owner, paper), story);
     }
 }
diff --git a/Content.Server/Paper/PaperSystem.cs b/Content.Server/Paper/PaperSystem.cs
deleted file mode 100644 (file)
index 3935df8..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-using System.Linq;
-using Content.Server.Administration.Logs;
-using Content.Server.Popups;
-using Content.Shared.UserInterface;
-using Content.Shared.Database;
-using Content.Shared.Examine;
-using Content.Shared.Interaction;
-using Content.Shared.Paper;
-using Content.Shared.Tag;
-using Robust.Server.GameObjects;
-using Robust.Shared.Player;
-using Robust.Shared.Audio.Systems;
-using static Content.Shared.Paper.SharedPaperComponent;
-
-namespace Content.Server.Paper
-{
-    public sealed class PaperSystem : EntitySystem
-    {
-        [Dependency] private readonly IAdminLogManager _adminLogger = default!;
-        [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
-        [Dependency] private readonly SharedInteractionSystem _interaction = default!;
-        [Dependency] private readonly PopupSystem _popupSystem = default!;
-        [Dependency] private readonly TagSystem _tagSystem = default!;
-        [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
-        [Dependency] private readonly MetaDataSystem _metaSystem = default!;
-        [Dependency] private readonly SharedAudioSystem _audio = default!;
-
-        public override void Initialize()
-        {
-            base.Initialize();
-
-            SubscribeLocalEvent<PaperComponent, ComponentInit>(OnInit);
-            SubscribeLocalEvent<PaperComponent, BeforeActivatableUIOpenEvent>(BeforeUIOpen);
-            SubscribeLocalEvent<PaperComponent, ExaminedEvent>(OnExamined);
-            SubscribeLocalEvent<PaperComponent, InteractUsingEvent>(OnInteractUsing);
-            SubscribeLocalEvent<PaperComponent, PaperInputTextMessage>(OnInputTextMessage);
-
-            SubscribeLocalEvent<ActivateOnPaperOpenedComponent, PaperWriteEvent>(OnPaperWrite);
-
-            SubscribeLocalEvent<PaperComponent, MapInitEvent>(OnMapInit);
-        }
-
-        private void OnMapInit(EntityUid uid, PaperComponent paperComp, MapInitEvent args)
-        {
-            if (!string.IsNullOrEmpty(paperComp.Content))
-            {
-                paperComp.Content = Loc.GetString(paperComp.Content);
-            }
-        }
-
-        private void OnInit(EntityUid uid, PaperComponent paperComp, ComponentInit args)
-        {
-            paperComp.Mode = PaperAction.Read;
-            UpdateUserInterface(uid, paperComp);
-
-            if (TryComp<AppearanceComponent>(uid, out var appearance))
-            {
-                if (paperComp.Content != "")
-                    _appearance.SetData(uid, PaperVisuals.Status, PaperStatus.Written, appearance);
-
-                if (paperComp.StampState != null)
-                    _appearance.SetData(uid, PaperVisuals.Stamp, paperComp.StampState, appearance);
-            }
-
-        }
-
-        private void BeforeUIOpen(EntityUid uid, PaperComponent paperComp, BeforeActivatableUIOpenEvent args)
-        {
-            paperComp.Mode = PaperAction.Read;
-            UpdateUserInterface(uid, paperComp);
-        }
-
-        private void OnExamined(EntityUid uid, PaperComponent paperComp, ExaminedEvent args)
-        {
-            if (!args.IsInDetailsRange)
-                return;
-
-            using (args.PushGroup(nameof(PaperComponent)))
-            {
-                if (paperComp.Content != "")
-                    args.PushMarkup(
-                        Loc.GetString(
-                            "paper-component-examine-detail-has-words", ("paper", uid)
-                        )
-                    );
-
-                if (paperComp.StampedBy.Count > 0)
-                {
-                    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))
-                    );
-                }
-            }
-        }
-
-        private void OnInteractUsing(EntityUid uid, PaperComponent paperComp, InteractUsingEvent args)
-        {
-            // only allow editing if there are no stamps or when using a cyberpen
-            var editable = paperComp.StampedBy.Count == 0 || _tagSystem.HasTag(args.Used, "WriteIgnoreStamps");
-            if (_tagSystem.HasTag(args.Used, "Write") && editable)
-            {
-                if (paperComp.EditingDisabled)
-                {
-                    var paperEditingDisabledMessage = Loc.GetString("paper-tamper-proof-modified-message");
-                    _popupSystem.PopupEntity(paperEditingDisabledMessage, uid, args.User);
-
-                    args.Handled = true;
-                    return;
-                }
-                var writeEvent = new PaperWriteEvent(uid, args.User);
-                RaiseLocalEvent(args.Used, ref writeEvent);
-
-                paperComp.Mode = PaperAction.Write;
-                _uiSystem.OpenUi(uid, PaperUiKey.Key, args.User);
-                UpdateUserInterface(uid, paperComp);
-                args.Handled = true;
-                return;
-            }
-
-            // If a stamp, attempt to stamp paper
-            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", args.User), ("target", args.Target), ("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);
-
-                UpdateUserInterface(uid, paperComp);
-            }
-        }
-
-        private static StampDisplayInfo GetStampInfo(StampComponent stamp)
-        {
-            return new StampDisplayInfo
-            {
-                StampedName = stamp.StampedName,
-                StampedColor = stamp.StampedColor
-            };
-        }
-
-        private void OnInputTextMessage(EntityUid uid, PaperComponent paperComp, PaperInputTextMessage args)
-        {
-            if (args.Text.Length <= paperComp.ContentSize)
-            {
-                paperComp.Content = args.Text;
-
-                if (TryComp<AppearanceComponent>(uid, out var appearance))
-                    _appearance.SetData(uid, PaperVisuals.Status, PaperStatus.Written, appearance);
-
-                if (TryComp(uid, out MetaDataComponent? meta))
-                    _metaSystem.SetEntityDescription(uid, "", meta);
-
-                _adminLogger.Add(LogType.Chat, LogImpact.Low,
-                    $"{ToPrettyString(args.Actor):player} has written on {ToPrettyString(uid):entity} the following text: {args.Text}");
-
-                _audio.PlayPvs(paperComp.Sound, uid);
-            }
-
-            paperComp.Mode = PaperAction.Read;
-            UpdateUserInterface(uid, paperComp);
-        }
-
-        private void OnPaperWrite(EntityUid uid, ActivateOnPaperOpenedComponent comp, ref PaperWriteEvent args)
-        {
-            _interaction.UseInHandInteraction(args.User, uid);
-        }
-
-        /// <summary>
-        ///     Accepts the name and state to be stamped onto the paper, returns true if successful.
-        /// </summary>
-        public bool TryStamp(EntityUid uid, StampDisplayInfo stampInfo, string spriteStampState, PaperComponent? paperComp = null)
-        {
-            if (!Resolve(uid, ref paperComp))
-                return false;
-
-            if (!paperComp.StampedBy.Contains(stampInfo))
-            {
-                paperComp.StampedBy.Add(stampInfo);
-                if (paperComp.StampState == null && TryComp<AppearanceComponent>(uid, out var appearance))
-                {
-                    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);
-                }
-            }
-            return true;
-        }
-
-        public void SetContent(EntityUid uid, string content, PaperComponent? paperComp = null)
-        {
-            if (!Resolve(uid, ref paperComp))
-                return;
-
-            paperComp.Content = content + '\n';
-            UpdateUserInterface(uid, paperComp);
-
-            if (!TryComp<AppearanceComponent>(uid, out var appearance))
-                return;
-
-            var status = string.IsNullOrWhiteSpace(content)
-                ? PaperStatus.Blank
-                : PaperStatus.Written;
-
-            _appearance.SetData(uid, PaperVisuals.Status, status, appearance);
-        }
-
-        public void UpdateUserInterface(EntityUid uid, PaperComponent? paperComp = null)
-        {
-            if (!Resolve(uid, ref paperComp))
-                return;
-
-            _uiSystem.SetUiState(uid, PaperUiKey.Key, new PaperBoundUserInterfaceState(paperComp.Content, paperComp.StampedBy, paperComp.Mode));
-        }
-    }
-
-    /// <summary>
-    /// Event fired when using a pen on paper, opening the UI.
-    /// </summary>
-    [ByRefEvent]
-    public record struct PaperWriteEvent(EntityUid User, EntityUid Paper);
-}
index 59ca913a3984aa148125ec68e8c6b6dd7bc03fd5..8fc2f26fa635a24247e7f1135e2258f35ba23a44 100644 (file)
@@ -1,5 +1,4 @@
 using System.Linq;
-using Content.Server.Paper;
 using Content.Server.Power.Components;
 using Content.Server.Research.Systems;
 using Content.Shared.UserInterface;
@@ -9,6 +8,7 @@ using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
 using Content.Shared.Audio;
 using Content.Shared.DeviceLinking;
 using Content.Shared.DeviceLinking.Events;
+using Content.Shared.Paper;
 using Content.Shared.Placeable;
 using Content.Shared.Popups;
 using Content.Shared.Research.Components;
@@ -290,7 +290,8 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
             return;
 
         _popup.PopupEntity(Loc.GetString("analysis-console-print-popup"), uid);
-        _paper.SetContent(report, msg.ToMarkup());
+        if (TryComp<PaperComponent>(report, out var paperComp))
+            _paper.SetContent((report, paperComp), msg.ToMarkup());
         UpdateUserInterface(uid, component);
     }
 
similarity index 78%
rename from Content.Server/Paper/ActivateOnPaperOpenedComponent.cs
rename to Content.Shared/Paper/ActivateOnPaperOpenedComponent.cs
index 0d0f72b61261cf7635b03c06b3fd2acb3a55ce8a..82b366decd8f286e5c5595db66eca036c0e6561a 100644 (file)
@@ -1,4 +1,6 @@
-namespace Content.Server.Paper;
+using Content.Shared.Paper;
+
+namespace Content.Shared.Paper;
 
 /// <summary>
 /// Activates the item when used to write on paper, as if Z was pressed.
similarity index 68%
rename from Content.Shared/Paper/SharedPaperComponent.cs
rename to Content.Shared/Paper/PaperComponent.cs
index f65a599e539f873b113292b8c97f54631488693e..cd0758589db9727a37ba9eb52be4b722a957eea4 100644 (file)
@@ -4,9 +4,28 @@ using Robust.Shared.Serialization;
 
 namespace Content.Shared.Paper;
 
-[NetworkedComponent]
-public abstract partial class SharedPaperComponent : Component
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class PaperComponent : Component
 {
+    public PaperAction Mode;
+    [DataField("content"), AutoNetworkedField]
+    public string Content { get; set; } = "";
+
+    [DataField("contentSize")]
+    public int ContentSize { get; set; } = 6000;
+
+    [DataField("stampedBy"), AutoNetworkedField]
+    public List<StampDisplayInfo> StampedBy { get; set; } = new();
+
+    /// <summary>
+    ///     Stamp to be displayed on the paper, state from bureaucracy.rsi
+    /// </summary>
+    [DataField("stampState"), AutoNetworkedField]
+    public string? StampState { get; set; }
+
+    [DataField, AutoNetworkedField]
+    public bool EditingDisabled;
+
     /// <summary>
     /// Sound played after writing to the paper.
     /// </summary>
diff --git a/Content.Shared/Paper/PaperSystem.cs b/Content.Shared/Paper/PaperSystem.cs
new file mode 100644 (file)
index 0000000..0f4bfef
--- /dev/null
@@ -0,0 +1,228 @@
+using System.Linq;
+using Content.Shared.Administration.Logs;
+using Content.Shared.UserInterface;
+using Content.Shared.Database;
+using Content.Shared.Examine;
+using Content.Shared.Interaction;
+using Content.Shared.Popups;
+using Content.Shared.Tag;
+using Robust.Shared.Player;
+using Robust.Shared.Audio.Systems;
+using static Content.Shared.Paper.PaperComponent;
+
+namespace Content.Shared.Paper;
+
+public sealed class PaperSystem : EntitySystem
+{
+    [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
+    [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+    [Dependency] private readonly SharedInteractionSystem _interaction = default!;
+    [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
+    [Dependency] private readonly TagSystem _tagSystem = default!;
+    [Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
+    [Dependency] private readonly MetaDataSystem _metaSystem = default!;
+    [Dependency] private readonly SharedAudioSystem _audio = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<PaperComponent, MapInitEvent>(OnMapInit);
+        SubscribeLocalEvent<PaperComponent, ComponentInit>(OnInit);
+        SubscribeLocalEvent<PaperComponent, BeforeActivatableUIOpenEvent>(BeforeUIOpen);
+        SubscribeLocalEvent<PaperComponent, ExaminedEvent>(OnExamined);
+        SubscribeLocalEvent<PaperComponent, InteractUsingEvent>(OnInteractUsing);
+        SubscribeLocalEvent<PaperComponent, PaperInputTextMessage>(OnInputTextMessage);
+
+        SubscribeLocalEvent<ActivateOnPaperOpenedComponent, PaperWriteEvent>(OnPaperWrite);
+    }
+
+    private void OnMapInit(Entity<PaperComponent> entity, ref MapInitEvent args)
+    {
+        if (!string.IsNullOrEmpty(entity.Comp.Content))
+        {
+            SetContent(entity, Loc.GetString(entity.Comp.Content));
+        }
+    }
+
+    private void OnInit(Entity<PaperComponent> entity, ref ComponentInit args)
+    {
+        entity.Comp.Mode = PaperAction.Read;
+        UpdateUserInterface(entity);
+
+        if (TryComp<AppearanceComponent>(entity, out var appearance))
+        {
+            if (entity.Comp.Content != "")
+                _appearance.SetData(entity, PaperVisuals.Status, PaperStatus.Written, appearance);
+
+            if (entity.Comp.StampState != null)
+                _appearance.SetData(entity, PaperVisuals.Stamp, entity.Comp.StampState, appearance);
+        }
+    }
+
+    private void BeforeUIOpen(Entity<PaperComponent> entity, ref BeforeActivatableUIOpenEvent args)
+    {
+        entity.Comp.Mode = PaperAction.Read;
+        UpdateUserInterface(entity);
+    }
+
+    private void OnExamined(Entity<PaperComponent> entity, ref ExaminedEvent args)
+    {
+        if (!args.IsInDetailsRange)
+            return;
+
+        using (args.PushGroup(nameof(PaperComponent)))
+        {
+            if (entity.Comp.Content != "")
+            {
+                args.PushMarkup(
+                    Loc.GetString(
+                        "paper-component-examine-detail-has-words",
+                        ("paper", entity)
+                    )
+                );
+            }
+
+            if (entity.Comp.StampedBy.Count > 0)
+            {
+                var commaSeparated =
+                    string.Join(", ", entity.Comp.StampedBy.Select(s => Loc.GetString(s.StampedName)));
+                args.PushMarkup(
+                    Loc.GetString(
+                        "paper-component-examine-detail-stamped-by",
+                        ("paper", entity),
+                        ("stamps", commaSeparated))
+                );
+            }
+        }
+    }
+
+    private void OnInteractUsing(Entity<PaperComponent> entity, ref InteractUsingEvent args)
+    {
+        // only allow editing if there are no stamps or when using a cyberpen
+        var editable = entity.Comp.StampedBy.Count == 0 || _tagSystem.HasTag(args.Used, "WriteIgnoreStamps");
+        if (_tagSystem.HasTag(args.Used, "Write") && editable)
+        {
+            if (entity.Comp.EditingDisabled)
+            {
+                var paperEditingDisabledMessage = Loc.GetString("paper-tamper-proof-modified-message");
+                _popupSystem.PopupEntity(paperEditingDisabledMessage, entity, args.User);
+
+                args.Handled = true;
+                return;
+            }
+            var writeEvent = new PaperWriteEvent(entity, args.User);
+            RaiseLocalEvent(args.Used, ref writeEvent);
+
+            entity.Comp.Mode = PaperAction.Write;
+            _uiSystem.OpenUi(entity.Owner, PaperUiKey.Key, args.User);
+            UpdateUserInterface(entity);
+            args.Handled = true;
+            return;
+        }
+
+        // If a stamp, attempt to stamp paper
+        if (TryComp<StampComponent>(args.Used, out var stampComp) && TryStamp(entity, GetStampInfo(stampComp), stampComp.StampState))
+        {
+            // successfully stamped, play popup
+            var stampPaperOtherMessage = Loc.GetString("paper-component-action-stamp-paper-other",
+                    ("user", args.User),
+                    ("target", args.Target),
+                    ("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.PopupClient(stampPaperSelfMessage, args.User, args.User);
+
+            _audio.PlayPredicted(stampComp.Sound, entity, args.User);
+
+            UpdateUserInterface(entity);
+        }
+    }
+
+    private static StampDisplayInfo GetStampInfo(StampComponent stamp)
+    {
+        return new StampDisplayInfo
+        {
+            StampedName = stamp.StampedName,
+            StampedColor = stamp.StampedColor
+        };
+    }
+
+    private void OnInputTextMessage(Entity<PaperComponent> entity, ref PaperInputTextMessage args)
+    {
+        if (args.Text.Length <= entity.Comp.ContentSize)
+        {
+            SetContent(entity, args.Text);
+
+            if (TryComp<AppearanceComponent>(entity, out var appearance))
+                _appearance.SetData(entity, PaperVisuals.Status, PaperStatus.Written, appearance);
+
+            if (TryComp(entity, out MetaDataComponent? meta))
+                _metaSystem.SetEntityDescription(entity, "", meta);
+
+            _adminLogger.Add(LogType.Chat,
+                LogImpact.Low,
+                $"{ToPrettyString(args.Actor):player} has written on {ToPrettyString(entity):entity} the following text: {args.Text}");
+
+            _audio.PlayPvs(entity.Comp.Sound, entity);
+        }
+
+        entity.Comp.Mode = PaperAction.Read;
+        UpdateUserInterface(entity);
+    }
+
+    private void OnPaperWrite(Entity<ActivateOnPaperOpenedComponent> entity, ref PaperWriteEvent args)
+    {
+        _interaction.UseInHandInteraction(args.User, entity);
+    }
+
+    /// <summary>
+    ///     Accepts the name and state to be stamped onto the paper, returns true if successful.
+    /// </summary>
+    public bool TryStamp(Entity<PaperComponent> entity, StampDisplayInfo stampInfo, string spriteStampState)
+    {
+        if (!entity.Comp.StampedBy.Contains(stampInfo))
+        {
+            entity.Comp.StampedBy.Add(stampInfo);
+            Dirty(entity);
+            if (entity.Comp.StampState == null && TryComp<AppearanceComponent>(entity, out var appearance))
+            {
+                entity.Comp.StampState = spriteStampState;
+                // Would be nice to be able to display multiple sprites on the paper
+                // but most of the existing images overlap
+                _appearance.SetData(entity, PaperVisuals.Stamp, entity.Comp.StampState, appearance);
+            }
+        }
+        return true;
+    }
+
+    public void SetContent(Entity<PaperComponent> entity, string content)
+    {
+        entity.Comp.Content = content + '\n';
+        Dirty(entity);
+        UpdateUserInterface(entity);
+
+        if (!TryComp<AppearanceComponent>(entity, out var appearance))
+            return;
+
+        var status = string.IsNullOrWhiteSpace(content)
+            ? PaperStatus.Blank
+            : PaperStatus.Written;
+
+        _appearance.SetData(entity, PaperVisuals.Status, status, appearance);
+    }
+
+    private void UpdateUserInterface(Entity<PaperComponent> entity)
+    {
+        _uiSystem.SetUiState(entity.Owner, PaperUiKey.Key, new PaperBoundUserInterfaceState(entity.Comp.Content, entity.Comp.StampedBy, entity.Comp.Mode));
+    }
+}
+
+/// <summary>
+/// Event fired when using a pen on paper, opening the UI.
+/// </summary>
+[ByRefEvent]
+public record struct PaperWriteEvent(EntityUid User, EntityUid Paper);
index 37776f5ba281dc051f7b4219716044229e39da41..edd4aee3ba67ed430d0b864dda7b1b52067f0721 100644 (file)
   components:
   - type: Paper
     contentSize: 10000
-    escapeFormatting: false
     content: book-cnc-sheet
   - type: Sprite
     layers:
       map: ["enum.PaperVisualLayers.Stamp"]
       visible: false
   - type: Paper
-    escapeFormatting: false
     content: envelope-default-message
   - type: PaperVisuals
     headerImagePath: "/Textures/Interface/Paper/paper_heading_postage_stamp.svg.96dpi.png"
       behaviors:
       - !type:EmptyAllContainersBehaviour
       - !type:DoActsBehavior
-        acts: [ "Destruction" ]
\ No newline at end of file
+        acts: [ "Destruction" ]