Move PaperSystem to Shared (#30592)

* 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>
This commit is contained in:
Plykiya
2024-08-04 21:23:23 -07:00
committed by GitHub
parent 0ef5f668e2
commit 01e1624567
22 changed files with 283 additions and 305 deletions

View File

@@ -1,6 +0,0 @@
using Content.Shared.Paper;
namespace Content.Client.Paper;
[RegisterComponent]
public sealed partial class PaperComponent : SharedPaperComponent;

View 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;

View 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)
{

View File

@@ -1,6 +1,6 @@
using System.Numerics;
namespace Content.Client.Paper;
namespace Content.Client.Paper.UI;
[RegisterComponent]
public sealed partial class PaperVisualsComponent : Component

View 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;

View 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;

View 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;

View 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>

View 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))

View 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;

View 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);
}
}

View 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)

View 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;

View 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);
}
}

View File

@@ -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;
}

View 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);
}
}

View File

@@ -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);
}

View 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);
}

View 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.

View 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>

View File

@@ -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);

View File

@@ -229,7 +229,6 @@
components:
- type: Paper
contentSize: 10000
escapeFormatting: false
content: book-cnc-sheet
- type: Sprite
layers:
@@ -587,7 +586,6 @@
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"