Fax machines can print from text file (#23262)
* added * checks tweaking * fixed what sloth wanted * fixed? * dialog diposing fix * checks tweaking * more changes * dispose streamreader * Update Content.Client/Fax/UI/FaxBoundUi.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Fax/FaxSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * fix minor typo --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Fax;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.Fax.UI;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class FaxBoundUi : BoundUserInterface
|
||||
{
|
||||
[Dependency] private readonly IFileDialogManager _fileDialogManager = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private FaxWindow? _window;
|
||||
|
||||
private bool _dialogIsOpen = false;
|
||||
|
||||
public FaxBoundUi(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
@@ -22,12 +29,33 @@ public sealed class FaxBoundUi : BoundUserInterface
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.FileButtonPressed += OnFileButtonPressed;
|
||||
_window.CopyButtonPressed += OnCopyButtonPressed;
|
||||
_window.SendButtonPressed += OnSendButtonPressed;
|
||||
_window.RefreshButtonPressed += OnRefreshButtonPressed;
|
||||
_window.PeerSelected += OnPeerSelected;
|
||||
}
|
||||
|
||||
private async void OnFileButtonPressed()
|
||||
{
|
||||
if (_dialogIsOpen)
|
||||
return;
|
||||
|
||||
_dialogIsOpen = true;
|
||||
var filters = new FileDialogFilters(new FileDialogFilters.Group("txt"));
|
||||
await using var file = await _fileDialogManager.OpenFile(filters);
|
||||
_dialogIsOpen = false;
|
||||
|
||||
if (_window == null || _window.Disposed || file == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(file);
|
||||
var content = await reader.ReadToEndAsync();
|
||||
SendMessage(new FaxFileMessage(content[..Math.Min(content.Length, FaxFileMessageValidation.MaxContentSize)], _window.OfficePaper));
|
||||
}
|
||||
|
||||
private void OnSendButtonPressed()
|
||||
{
|
||||
SendMessage(new FaxSendMessage());
|
||||
|
||||
@@ -19,6 +19,14 @@
|
||||
<OptionButton Name="PeerSelector" HorizontalExpand="True" />
|
||||
</BoxContainer>
|
||||
<Control HorizontalExpand="True" MinHeight="20" />
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Button Name="FileButton"
|
||||
Text="{Loc 'fax-machine-ui-file-button'}"
|
||||
HorizontalExpand="False"/>
|
||||
<Button Name="PaperButton"
|
||||
Text="{Loc 'fax-machine-ui-paper-button-normal'}"
|
||||
HorizontalExpand="False"/>
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Button Name="CopyButton"
|
||||
Text="{Loc 'fax-machine-ui-copy-button'}"
|
||||
|
||||
@@ -3,21 +3,30 @@ using Content.Shared.Fax;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.Fax.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class FaxWindow : DefaultWindow
|
||||
{
|
||||
public event Action? FileButtonPressed;
|
||||
public event Action? PaperButtonPressed;
|
||||
public event Action? CopyButtonPressed;
|
||||
public event Action? SendButtonPressed;
|
||||
public event Action? RefreshButtonPressed;
|
||||
public event Action<string>? PeerSelected;
|
||||
|
||||
public bool OfficePaper = false;
|
||||
|
||||
public FaxWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
PaperButtonPressed += OnPaperButtonPressed;
|
||||
|
||||
FileButton.OnPressed += _ => FileButtonPressed?.Invoke();
|
||||
PaperButton.OnPressed += _ => PaperButtonPressed?.Invoke();
|
||||
CopyButton.OnPressed += _ => CopyButtonPressed?.Invoke();
|
||||
SendButton.OnPressed += _ => SendButtonPressed?.Invoke();
|
||||
RefreshButton.OnPressed += _ => RefreshButtonPressed?.Invoke();
|
||||
@@ -80,4 +89,14 @@ public sealed partial class FaxWindow : DefaultWindow
|
||||
PeerSelector.SetItemMetadata(PeerSelector.ItemCount - 1, address);
|
||||
return PeerSelector.ItemCount - 1;
|
||||
}
|
||||
|
||||
private void OnPaperButtonPressed()
|
||||
{
|
||||
OfficePaper = !OfficePaper;
|
||||
|
||||
if(OfficePaper)
|
||||
PaperButton.Text = Loc.GetString("fax-machine-ui-paper-button-office");
|
||||
else
|
||||
PaperButton.Text = Loc.GetString("fax-machine-ui-paper-button-normal");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user