Add a 'Copy' button to the fax UI (#22027)
* Add a 'Copy' button to the fax UI * Add ValidatePrototypeId attribute Co-authored-by: Kara <lunarautomaton6@gmail.com> --------- Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
@@ -22,6 +22,7 @@ public sealed class FaxBoundUi : BoundUserInterface
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.CopyButtonPressed += OnCopyButtonPressed;
|
||||
_window.SendButtonPressed += OnSendButtonPressed;
|
||||
_window.RefreshButtonPressed += OnRefreshButtonPressed;
|
||||
_window.PeerSelected += OnPeerSelected;
|
||||
@@ -32,6 +33,11 @@ public sealed class FaxBoundUi : BoundUserInterface
|
||||
SendMessage(new FaxSendMessage());
|
||||
}
|
||||
|
||||
private void OnCopyButtonPressed()
|
||||
{
|
||||
SendMessage(new FaxCopyMessage());
|
||||
}
|
||||
|
||||
private void OnRefreshButtonPressed()
|
||||
{
|
||||
SendMessage(new FaxRefreshMessage());
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
</BoxContainer>
|
||||
<Control HorizontalExpand="True" MinHeight="20" />
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Button Name="CopyButton"
|
||||
Text="{Loc 'fax-machine-ui-copy-button'}"
|
||||
HorizontalExpand="False"
|
||||
Disabled="True" />
|
||||
<Button Name="SendButton"
|
||||
Text="{Loc 'fax-machine-ui-send-button'}"
|
||||
HorizontalExpand="True"
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Content.Client.Fax.UI;
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class FaxWindow : DefaultWindow
|
||||
{
|
||||
public event Action? CopyButtonPressed;
|
||||
public event Action? SendButtonPressed;
|
||||
public event Action? RefreshButtonPressed;
|
||||
public event Action<string>? PeerSelected;
|
||||
@@ -17,6 +18,7 @@ public sealed partial class FaxWindow : DefaultWindow
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
CopyButton.OnPressed += _ => CopyButtonPressed?.Invoke();
|
||||
SendButton.OnPressed += _ => SendButtonPressed?.Invoke();
|
||||
RefreshButton.OnPressed += _ => RefreshButtonPressed?.Invoke();
|
||||
PeerSelector.OnItemSelected += args =>
|
||||
@@ -25,6 +27,7 @@ public sealed partial class FaxWindow : DefaultWindow
|
||||
|
||||
public void UpdateState(FaxUiState state)
|
||||
{
|
||||
CopyButton.Disabled = !state.CanCopy;
|
||||
SendButton.Disabled = !state.CanSend;
|
||||
FromLabel.Text = state.DeviceName;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Fax;
|
||||
|
||||
@@ -43,6 +44,13 @@ public sealed class FaxSystem : EntitySystem
|
||||
|
||||
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();
|
||||
@@ -63,6 +71,7 @@ public sealed class FaxSystem : EntitySystem
|
||||
|
||||
// UI
|
||||
SubscribeLocalEvent<FaxMachineComponent, AfterActivatableUIOpenEvent>(OnToggleInterface);
|
||||
SubscribeLocalEvent<FaxMachineComponent, FaxCopyMessage>(OnCopyButtonPressed);
|
||||
SubscribeLocalEvent<FaxMachineComponent, FaxSendMessage>(OnSendButtonPressed);
|
||||
SubscribeLocalEvent<FaxMachineComponent, FaxRefreshMessage>(OnRefreshButtonPressed);
|
||||
SubscribeLocalEvent<FaxMachineComponent, FaxDestinationMessage>(OnDestinationSelected);
|
||||
@@ -291,6 +300,11 @@ public sealed class FaxSystem : EntitySystem
|
||||
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);
|
||||
@@ -329,7 +343,10 @@ public sealed class FaxSystem : EntitySystem
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -369,9 +386,42 @@ public sealed class FaxSystem : EntitySystem
|
||||
_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)
|
||||
{
|
||||
@@ -404,7 +454,7 @@ public sealed class FaxSystem : EntitySystem
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -454,7 +504,7 @@ public sealed class FaxSystem : EntitySystem
|
||||
|
||||
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))
|
||||
|
||||
@@ -16,10 +16,12 @@ public sealed class FaxUiState : BoundUserInterfaceState
|
||||
public string? DestinationAddress { get; }
|
||||
public bool IsPaperInserted { get; }
|
||||
public bool CanSend { get; }
|
||||
public bool CanCopy { get; }
|
||||
|
||||
public FaxUiState(string deviceName,
|
||||
Dictionary<string, string> peers,
|
||||
bool canSend,
|
||||
bool canCopy,
|
||||
bool isPaperInserted,
|
||||
string? destAddress)
|
||||
{
|
||||
@@ -27,10 +29,16 @@ public sealed class FaxUiState : BoundUserInterfaceState
|
||||
AvailablePeers = peers;
|
||||
IsPaperInserted = isPaperInserted;
|
||||
CanSend = canSend;
|
||||
CanCopy = canCopy;
|
||||
DestinationAddress = destAddress;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class FaxCopyMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class FaxSendMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ fax-machine-dialog-rename = Rename
|
||||
fax-machine-dialog-field-name = Name
|
||||
|
||||
fax-machine-ui-window = Fax Machine
|
||||
fax-machine-ui-copy-button = Copy
|
||||
fax-machine-ui-send-button = Send
|
||||
fax-machine-ui-refresh-button = Refresh
|
||||
fax-machine-ui-no-peers = No Peers
|
||||
|
||||
Reference in New Issue
Block a user