96 lines
2.9 KiB
C#
96 lines
2.9 KiB
C#
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));
|
|
}
|
|
}
|