using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Player;
+using Robust.Shared.Prototypes;
namespace Content.Server.Fax;
private const string PaperSlotId = "Paper";
+ /// <summary>
+ /// The prototype ID to use for faxed or copied entities if we can't get one from
+ /// the paper entity for whatever reason.
+ /// </summary>
+ [ValidatePrototypeId<EntityPrototype>]
+ private const string DefaultPaperPrototypeId = "Paper";
+
public override void Initialize()
{
base.Initialize();
// UI
SubscribeLocalEvent<FaxMachineComponent, AfterActivatableUIOpenEvent>(OnToggleInterface);
+ SubscribeLocalEvent<FaxMachineComponent, FaxCopyMessage>(OnCopyButtonPressed);
SubscribeLocalEvent<FaxMachineComponent, FaxSendMessage>(OnSendButtonPressed);
SubscribeLocalEvent<FaxMachineComponent, FaxRefreshMessage>(OnRefreshButtonPressed);
SubscribeLocalEvent<FaxMachineComponent, FaxDestinationMessage>(OnDestinationSelected);
UpdateUserInterface(uid, component);
}
+ private void OnCopyButtonPressed(EntityUid uid, FaxMachineComponent component, FaxCopyMessage args)
+ {
+ Copy(uid, component);
+ }
+
private void OnSendButtonPressed(EntityUid uid, FaxMachineComponent component, FaxSendMessage args)
{
Send(uid, component, args.Session.AttachedEntity);
component.DestinationFaxAddress != null &&
component.SendTimeoutRemaining <= 0 &&
component.InsertingTimeRemaining <= 0;
- var state = new FaxUiState(component.FaxName, component.KnownFaxes, canSend, isPaperInserted, component.DestinationFaxAddress);
+ var canCopy = isPaperInserted &&
+ component.SendTimeoutRemaining <= 0 &&
+ component.InsertingTimeRemaining <= 0;
+ var state = new FaxUiState(component.FaxName, component.KnownFaxes, canSend, canCopy, isPaperInserted, component.DestinationFaxAddress);
_userInterface.TrySetUiState(uid, FaxUiKey.Key, state);
}
_deviceNetworkSystem.QueuePacket(uid, null, payload);
}
+ /// <summary>
+ /// Copies the paper in the fax. A timeout is set after copying,
+ /// which is shared by the send button.
+ /// </summary>
+ public void Copy(EntityUid uid, FaxMachineComponent? component = null)
+ {
+ if (!Resolve(uid, ref component))
+ return;
+
+ var sendEntity = component.PaperSlot.Item;
+ if (sendEntity == null)
+ return;
+
+ if (!TryComp<MetaDataComponent>(sendEntity, out var metadata) ||
+ !TryComp<PaperComponent>(sendEntity, out var paper))
+ return;
+
+ // TODO: See comment in 'Send()' about not being able to copy whole entities
+ var printout = new FaxPrintout(paper.Content,
+ metadata.EntityName,
+ metadata.EntityPrototype?.ID ?? DefaultPaperPrototypeId,
+ paper.StampState,
+ paper.StampedBy);
+
+ component.PrintingQueue.Enqueue(printout);
+ component.SendTimeoutRemaining += component.SendTimeout;
+
+ // Don't play component.SendSound - it clashes with the printing sound, which
+ // will start immediately.
+
+ UpdateUserInterface(uid, component);
+ }
+
/// <summary>
/// Sends message to addressee if paper is set and a known fax is selected
- /// A timeout is set after sending
+ /// A timeout is set after sending, which is shared by the copy button.
/// </summary>
public void Send(EntityUid uid, FaxMachineComponent? component = null, EntityUid? sender = null)
{
// TODO: Ideally, we could just make a copy of the whole entity when it's
// faxed, in order to preserve visuals, etc.. This functionality isn't
// available yet, so we'll pass along the originating prototypeId and fall
- // back to "Paper" in SpawnPaperFromQueue if we can't find one here.
+ // back to DefaultPaperPrototypeId in SpawnPaperFromQueue if we can't find one here.
payload[FaxConstants.FaxPaperPrototypeData] = metadata.EntityPrototype.ID;
}
var printout = component.PrintingQueue.Dequeue();
- var entityToSpawn = printout.PrototypeId.Length == 0 ? "Paper" : printout.PrototypeId;
+ var entityToSpawn = printout.PrototypeId.Length == 0 ? DefaultPaperPrototypeId : printout.PrototypeId;
var printed = EntityManager.SpawnEntity(entityToSpawn, Transform(uid).Coordinates);
if (TryComp<PaperComponent>(printed, out var paper))