Add fax admin panel (#15215)

This commit is contained in:
Morb
2023-04-16 23:20:57 -07:00
committed by GitHub
parent 55f82d2c15
commit 0e6b273f1f
13 changed files with 367 additions and 27 deletions

View File

@@ -0,0 +1,37 @@
using Content.Client.Eui;
using Content.Shared.Eui;
using Content.Shared.Fax;
using JetBrains.Annotations;
namespace Content.Client.Fax.AdminUI;
[UsedImplicitly]
public sealed class AdminFaxEui : BaseEui
{
private readonly AdminFaxWindow _window;
public AdminFaxEui()
{
_window = new AdminFaxWindow();
_window.OnClose += () => SendMessage(new AdminFaxEuiMsg.Close());
_window.OnFollowFax += uid => SendMessage(new AdminFaxEuiMsg.Follow(uid));
_window.OnMessageSend += args => SendMessage(new AdminFaxEuiMsg.Send(args.uid, args.title, args.from, args.message, args.stamp));
}
public override void Opened()
{
_window.OpenCentered();
}
public override void Closed()
{
_window.Close();
}
public override void HandleState(EuiStateBase state)
{
if (state is not AdminFaxEuiState cast)
return;
_window.PopulateFaxes(cast.Entries);
}
}

View File

@@ -0,0 +1,27 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc admin-fax-title}"
MinWidth="400">
<BoxContainer Orientation="Vertical" VerticalExpand="True">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc admin-fax-fax}" />
<Control MinWidth="4" />
<OptionButton Name="FaxSelector" HorizontalExpand="True" />
<Control MinWidth="4" />
<Button Name="FollowButton" Text="{Loc admin-fax-follow}" />
</BoxContainer>
<Control MinHeight="5" />
<LineEdit Name="TitleEdit" HorizontalExpand="True" PlaceHolder="{Loc admin-fax-title-placeholder}"></LineEdit>
<Control MinHeight="5" />
<LineEdit Name="FromEdit" HorizontalExpand="True" PlaceHolder="{Loc admin-fax-from-placeholder}"></LineEdit>
<Control MinHeight="5" />
<TextEdit Name="MessageEdit" HorizontalExpand="True" MinHeight="200"></TextEdit>
<Control MinHeight="5" />
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc admin-fax-stamp}" />
<Control MinWidth="5" />
<OptionButton Name="StampSelector" HorizontalExpand="True" />
</BoxContainer>
<Control MinHeight="10" />
<Button Name="SendButton" Text="{Loc admin-fax-send}"></Button>
</BoxContainer>
</DefaultWindow>

View File

@@ -0,0 +1,95 @@
using Content.Shared.Fax;
using Robust.Client.AutoGenerated;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Utility;
namespace Content.Client.Fax.AdminUI;
[GenerateTypedNameReferences]
public sealed partial class AdminFaxWindow : DefaultWindow
{
private const string StampsRsiPath = "/Textures/Objects/Misc/bureaucracy.rsi";
public Action<(EntityUid uid, string title, string from, string message, string stamp)>? OnMessageSend;
public Action<EntityUid>? OnFollowFax;
public AdminFaxWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
PopulateStamps();
FaxSelector.OnItemSelected += args => FaxSelector.SelectId(args.Id);
StampSelector.OnItemSelected += args => StampSelector.SelectId(args.Id);
FollowButton.OnPressed += FollowFax;
SendButton.OnPressed += SendMessage;
var loc = IoCManager.Resolve<ILocalizationManager>();
MessageEdit.Placeholder = new Rope.Leaf(loc.GetString("admin-fax-message-placeholder")); // TextEdit work only with Nodes
}
public void PopulateFaxes(List<AdminFaxEntry> faxes)
{
for (var i = 0; i < faxes.Count; i++)
{
var fax = faxes[i];
FaxSelector.AddItem($"{fax.Name} ({fax.Address})", i);
FaxSelector.SetItemMetadata(i, fax.Uid);
}
}
private void PopulateStamps()
{
var rsi = IoCManager.Resolve<IResourceCache>().GetResource<RSIResource>(StampsRsiPath).RSI;
using (var enumerator = rsi.GetEnumerator())
{
var i = 0;
while (enumerator.MoveNext())
{
var state = enumerator.Current;
var stateName = state.StateId.Name!;
if (!stateName.StartsWith("paper_stamp-"))
continue;
StampSelector.AddItem(stateName, i);
StampSelector.SetItemMetadata(i, stateName);
i++;
}
}
}
private void FollowFax(BaseButton.ButtonEventArgs obj)
{
var faxUid = (EntityUid?) FaxSelector.SelectedMetadata;
if (faxUid == null)
return;
OnFollowFax?.Invoke(faxUid.Value);
}
private void SendMessage(BaseButton.ButtonEventArgs obj)
{
var faxUid = (EntityUid?) FaxSelector.SelectedMetadata;
if (faxUid == null)
return;
var stamp = (string?) StampSelector.SelectedMetadata;
if (stamp == null)
return;
var title = TitleEdit.Text;
if (string.IsNullOrEmpty(title))
return;
var message = Rope.Collapse(MessageEdit.TextRope);
if (string.IsNullOrEmpty(message))
return;
var from = FromEdit.Text;
OnMessageSend?.Invoke((faxUid.Value, title, from, message, stamp));
}
}