Add ban list window (#12574)

This commit is contained in:
DrSmugleaf
2022-11-14 20:06:55 +01:00
committed by GitHub
parent 29a1c7d12d
commit da29a01846
25 changed files with 535 additions and 79 deletions

View File

@@ -0,0 +1,70 @@
using Content.Shared.Administration.BanList;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Input;
namespace Content.Client.Administration.UI.BanList;
[GenerateTypedNameReferences]
public sealed partial class BanListLine : BoxContainer
{
public readonly SharedServerBan Ban;
public event Func<BanListLine, bool>? OnIdsClicked;
public BanListLine(SharedServerBan ban)
{
RobustXamlLoader.Load(this);
Ban = ban;
IdsHidden.OnKeyBindDown += IdsKeyBindDown;
Reason.Text = ban.Reason;
BanTime.Text = FormatDate(ban.BanTime);
Expires.Text = ban.ExpirationTime == null
? Loc.GetString("ban-list-permanent")
: FormatDate(ban.ExpirationTime.Value);
if (ban.Unban is { } unban)
{
var unbanned = Loc.GetString("ban-list-unbanned", ("date", FormatDate(unban.UnbanTime)));
var unbannedBy = unban.UnbanningAdmin == null
? string.Empty
: $"\n{Loc.GetString("ban-list-unbanned-by", ("unbanner", unban.UnbanningAdmin))}";
Expires.Text += $"\n{unbanned}{unbannedBy}";
}
BanningAdmin.Text = ban.BanningAdminName;
}
private static string FormatDate(DateTimeOffset date)
{
return date.ToString("MM/dd/yyyy h:mm tt");
}
private void IdsKeyBindDown(GUIBoundKeyEventArgs args)
{
if (args.Function != EngineKeyFunctions.UIRightClick &&
args.Function != EngineKeyFunctions.UIClick)
{
return;
}
if (OnIdsClicked?.Invoke(this) == true)
{
args.Handle();
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
IdsHidden.OnKeyBindDown -= IdsKeyBindDown;
OnIdsClicked = null;
}
}