Fax Machine (#11704)
This commit is contained in:
58
Content.Client/Fax/UI/FaxBoundUi.cs
Normal file
58
Content.Client/Fax/UI/FaxBoundUi.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Content.Shared.Fax;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Fax.UI;
|
||||
|
||||
public sealed class FaxBoundUi : BoundUserInterface
|
||||
{
|
||||
private FaxWindow? _window;
|
||||
|
||||
public FaxBoundUi(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_window = new FaxWindow();
|
||||
_window.OpenCentered();
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.SendButtonPressed += OnSendButtonPressed;
|
||||
_window.RefreshButtonPressed += OnRefreshButtonPressed;
|
||||
_window.PeerSelected += OnPeerSelected;
|
||||
}
|
||||
|
||||
private void OnSendButtonPressed()
|
||||
{
|
||||
SendMessage(new FaxSendMessage());
|
||||
}
|
||||
|
||||
private void OnRefreshButtonPressed()
|
||||
{
|
||||
SendMessage(new FaxRefreshMessage());
|
||||
}
|
||||
|
||||
private void OnPeerSelected(string address)
|
||||
{
|
||||
SendMessage(new FaxDestinationMessage(address));
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (_window == null || state is not FaxUiState cast)
|
||||
return;
|
||||
|
||||
_window.UpdateState(cast);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (disposing)
|
||||
_window?.Dispose();
|
||||
}
|
||||
}
|
||||
32
Content.Client/Fax/UI/FaxWindow.xaml
Normal file
32
Content.Client/Fax/UI/FaxWindow.xaml
Normal file
@@ -0,0 +1,32 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
xmlns:viewport="clr-namespace:Content.Client.Viewport"
|
||||
Title="{Loc 'fax-machine-ui-window'}"
|
||||
MinWidth="250">
|
||||
<BoxContainer Orientation="Vertical" VerticalExpand="True">
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'fax-machine-ui-paper'}" />
|
||||
<Control MinWidth="4" />
|
||||
<Label Name="PaperStatusLabel" />
|
||||
</BoxContainer>
|
||||
<Control HorizontalExpand="True" MinHeight="20" />
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'fax-machine-ui-from'}" />
|
||||
<Control MinWidth="4" />
|
||||
<Label Name="FromLabel" />
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'fax-machine-ui-to'}" />
|
||||
<Control MinWidth="4" />
|
||||
<OptionButton Name="PeerSelector" HorizontalExpand="True" />
|
||||
</BoxContainer>
|
||||
<Control HorizontalExpand="True" MinHeight="20" />
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<Button Name="SendButton"
|
||||
Text="{Loc 'fax-machine-ui-send-button'}"
|
||||
HorizontalExpand="True"
|
||||
Disabled="True" />
|
||||
<Button Name="RefreshButton"
|
||||
Text="{Loc 'fax-machine-ui-refresh-button'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</DefaultWindow>
|
||||
81
Content.Client/Fax/UI/FaxWindow.xaml.cs
Normal file
81
Content.Client/Fax/UI/FaxWindow.xaml.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Fax;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Fax.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class FaxWindow : DefaultWindow
|
||||
{
|
||||
public event Action? SendButtonPressed;
|
||||
public event Action? RefreshButtonPressed;
|
||||
public event Action<string>? PeerSelected;
|
||||
|
||||
public FaxWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
SendButton.OnPressed += _ => SendButtonPressed?.Invoke();
|
||||
RefreshButton.OnPressed += _ => RefreshButtonPressed?.Invoke();
|
||||
PeerSelector.OnItemSelected += args =>
|
||||
PeerSelected?.Invoke((string) args.Button.GetItemMetadata(args.Id)!);
|
||||
}
|
||||
|
||||
public void UpdateState(FaxUiState state)
|
||||
{
|
||||
SendButton.Disabled = !state.CanSend;
|
||||
FromLabel.Text = state.DeviceName;
|
||||
|
||||
if (state.IsPaperInserted)
|
||||
{
|
||||
PaperStatusLabel.FontColorOverride = Color.Green;
|
||||
PaperStatusLabel.Text = Loc.GetString("fax-machine-ui-paper-inserted");
|
||||
}
|
||||
else
|
||||
{
|
||||
PaperStatusLabel.FontColorOverride = Color.Red;
|
||||
PaperStatusLabel.Text = Loc.GetString("fax-machine-ui-paper-not-inserted");
|
||||
}
|
||||
|
||||
if (state.AvailablePeers.Count == 0)
|
||||
{
|
||||
PeerSelector.AddItem(Loc.GetString("fax-machine-ui-no-peers"));
|
||||
PeerSelector.Disabled = true;
|
||||
}
|
||||
|
||||
if (PeerSelector.Disabled && state.AvailablePeers.Count != 0)
|
||||
{
|
||||
PeerSelector.Clear();
|
||||
PeerSelector.Disabled = false;
|
||||
}
|
||||
|
||||
// always must be selected destination
|
||||
if (string.IsNullOrEmpty(state.DestinationAddress) && state.AvailablePeers.Count != 0)
|
||||
{
|
||||
PeerSelected?.Invoke(state.AvailablePeers.First().Key);
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.AvailablePeers.Count != 0)
|
||||
{
|
||||
PeerSelector.Clear();
|
||||
|
||||
foreach (var (address, name) in state.AvailablePeers)
|
||||
{
|
||||
var id = AddPeerSelect(name, address);
|
||||
if (address == state.DestinationAddress)
|
||||
PeerSelector.Select(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int AddPeerSelect(string name, string address)
|
||||
{
|
||||
PeerSelector.AddItem(name);
|
||||
PeerSelector.SetItemMetadata(PeerSelector.ItemCount - 1, address);
|
||||
return PeerSelector.ItemCount - 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user