From 71ab6608857aea9dd4db0b68b33e9521a960edd8 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Fri, 22 Sep 2023 14:08:28 -0700 Subject: [PATCH] Add role bans tab to the bans admin window (#20388) --- .../UI/BanList/BanListControl.xaml.cs | 76 ----------------- .../Administration/UI/BanList/BanListEui.cs | 82 +++++++++++++++++-- .../UI/BanList/BanListLine.xaml.cs | 59 ------------- .../UI/BanList/BanListWindow.xaml | 7 +- .../UI/BanList/BanListWindow.xaml.cs | 3 + .../UI/BanList/{ => Bans}/BanListControl.xaml | 8 +- .../UI/BanList/Bans/BanListControl.xaml.cs | 36 ++++++++ .../UI/BanList/{ => Bans}/BanListHeader.xaml | 1 - .../BanList/{ => Bans}/BanListHeader.xaml.cs | 2 +- .../UI/BanList/{ => Bans}/BanListLine.xaml | 5 +- .../UI/BanList/Bans/BanListLine.xaml.cs | 38 +++++++++ .../Administration/UI/BanList/IBanListLine.cs | 13 +++ .../BanList/RoleBans/RoleBanListControl.xaml | 11 +++ .../RoleBans/RoleBanListControl.xaml.cs | 36 ++++++++ .../BanList/RoleBans/RoleBanListHeader.xaml | 34 ++++++++ .../RoleBans/RoleBanListHeader.xaml.cs | 14 ++++ .../UI/BanList/RoleBans/RoleBanListLine.xaml | 46 +++++++++++ .../BanList/RoleBans/RoleBanListLine.xaml.cs | 40 +++++++++ .../Administration/BanList/BanListEui.cs | 58 +++++++++++-- .../Administration/BanList/BanListEuiState.cs | 4 +- .../Administration/BanList/SharedServerBan.cs | 2 +- .../BanList/SharedServerRoleBan.cs | 18 ++++ .../en-US/administration/ui/ban-list.ftl | 4 + 23 files changed, 437 insertions(+), 160 deletions(-) delete mode 100644 Content.Client/Administration/UI/BanList/BanListControl.xaml.cs delete mode 100644 Content.Client/Administration/UI/BanList/BanListLine.xaml.cs rename Content.Client/Administration/UI/BanList/{ => Bans}/BanListControl.xaml (58%) create mode 100644 Content.Client/Administration/UI/BanList/Bans/BanListControl.xaml.cs rename Content.Client/Administration/UI/BanList/{ => Bans}/BanListHeader.xaml (97%) rename Content.Client/Administration/UI/BanList/{ => Bans}/BanListHeader.xaml.cs (83%) rename Content.Client/Administration/UI/BanList/{ => Bans}/BanListLine.xaml (91%) create mode 100644 Content.Client/Administration/UI/BanList/Bans/BanListLine.xaml.cs create mode 100644 Content.Client/Administration/UI/BanList/IBanListLine.cs create mode 100644 Content.Client/Administration/UI/BanList/RoleBans/RoleBanListControl.xaml create mode 100644 Content.Client/Administration/UI/BanList/RoleBans/RoleBanListControl.xaml.cs create mode 100644 Content.Client/Administration/UI/BanList/RoleBans/RoleBanListHeader.xaml create mode 100644 Content.Client/Administration/UI/BanList/RoleBans/RoleBanListHeader.xaml.cs create mode 100644 Content.Client/Administration/UI/BanList/RoleBans/RoleBanListLine.xaml create mode 100644 Content.Client/Administration/UI/BanList/RoleBans/RoleBanListLine.xaml.cs create mode 100644 Content.Shared/Administration/BanList/SharedServerRoleBan.cs diff --git a/Content.Client/Administration/UI/BanList/BanListControl.xaml.cs b/Content.Client/Administration/UI/BanList/BanListControl.xaml.cs deleted file mode 100644 index f7fe7709c8..0000000000 --- a/Content.Client/Administration/UI/BanList/BanListControl.xaml.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Linq; -using System.Numerics; -using Content.Client.Administration.UI.CustomControls; -using Content.Shared.Administration.BanList; -using Robust.Client.AutoGenerated; -using Robust.Client.UserInterface; -using Robust.Client.UserInterface.XAML; - -namespace Content.Client.Administration.UI.BanList; - -[GenerateTypedNameReferences] -public sealed partial class BanListControl : Control -{ - private BanListIdsPopup? _popup; - - public BanListControl() - { - RobustXamlLoader.Load(this); - } - - public void SetBans(List bans) - { - foreach (var control in Bans.Children.ToArray()[1..]) - { - control.Orphan(); - } - - foreach (var ban in bans) - { - Bans.AddChild(new HSeparator()); - - var line = new BanListLine(ban); - line.OnIdsClicked += LineIdsClicked; - - Bans.AddChild(line); - } - } - - private void ClosePopup() - { - _popup?.Close(); - _popup = null; - } - - private bool LineIdsClicked(BanListLine line) - { - ClosePopup(); - - var ban = line.Ban; - var id = ban.Id == null ? string.Empty : Loc.GetString("ban-list-id", ("id", ban.Id.Value)); - var ip = ban.Address == null - ? string.Empty - : Loc.GetString("ban-list-ip", ("ip", ban.Address.Value.address)); - var hwid = ban.HWId == null ? string.Empty : Loc.GetString("ban-list-hwid", ("hwid", ban.HWId)); - var guid = ban.UserId == null - ? string.Empty - : Loc.GetString("ban-list-guid", ("guid", ban.UserId.Value.ToString())); - - _popup = new BanListIdsPopup(id, ip, hwid, guid); - - var box = UIBox2.FromDimensions(UserInterfaceManager.MousePositionScaled.Position, new Vector2(1, 1)); - _popup.Open(box); - - return true; - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - if (_popup != null) - { - UserInterfaceManager.PopupRoot.RemoveChild(_popup); - } - } -} diff --git a/Content.Client/Administration/UI/BanList/BanListEui.cs b/Content.Client/Administration/UI/BanList/BanListEui.cs index 07eb2e61f4..2fca1dee52 100644 --- a/Content.Client/Administration/UI/BanList/BanListEui.cs +++ b/Content.Client/Administration/UI/BanList/BanListEui.cs @@ -1,21 +1,47 @@ -using Content.Client.Eui; +using System.Numerics; +using Content.Client.Administration.UI.BanList.Bans; +using Content.Client.Administration.UI.BanList.RoleBans; +using Content.Client.Eui; using Content.Shared.Administration.BanList; using Content.Shared.Eui; -using Content.Shared.Ghost.Roles; +using JetBrains.Annotations; +using Robust.Client.UserInterface; namespace Content.Client.Administration.UI.BanList; +[UsedImplicitly] public sealed class BanListEui : BaseEui { + [Dependency] private readonly IUserInterfaceManager _ui = default!; + + private BanListIdsPopup? _popup; + public BanListEui() { BanWindow = new BanListWindow(); BanWindow.OnClose += OnClosed; + BanControl = BanWindow.BanList; + BanControl.LineIdsClicked += OnLineIdsClicked; + + RoleBanControl = BanWindow.RoleBanList; + RoleBanControl.LineIdsClicked += OnLineIdsClicked; } + private BanListWindow BanWindow { get; } + + private BanListControl BanControl { get; } + private RoleBanListControl RoleBanControl { get; } + private void OnClosed() { + if (_popup != null) + { + _popup.Close(); + _popup.Dispose(); + _popup = null; + } + SendMessage(new CloseEuiMessage()); } @@ -25,10 +51,6 @@ public sealed class BanListEui : BaseEui BanWindow.Close(); } - private BanListWindow BanWindow { get; } - - private BanListControl BanControl { get; } - public override void HandleState(EuiStateBase state) { if (state is not BanListEuiState s) @@ -38,10 +60,58 @@ public sealed class BanListEui : BaseEui s.Bans.Sort((a, b) => a.BanTime.CompareTo(b.BanTime)); BanControl.SetBans(s.Bans); + RoleBanControl.SetRoleBans(s.RoleBans); } public override void Opened() { BanWindow.OpenCentered(); } + + private static string FormatDate(DateTimeOffset date) + { + return date.ToString("MM/dd/yyyy h:mm tt"); + } + + public static void SetData(IBanListLine line, SharedServerBan ban) where T : SharedServerBan + { + line.Reason.Text = ban.Reason; + line.BanTime.Text = FormatDate(ban.BanTime); + line.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))}"; + + line.Expires.Text += $"\n{unbanned}{unbannedBy}"; + } + + line.BanningAdmin.Text = ban.BanningAdminName; + } + + private void OnLineIdsClicked(IBanListLine line) where T : SharedServerBan + { + _popup?.Close(); + _popup = null; + + var ban = line.Ban; + var id = ban.Id == null ? string.Empty : Loc.GetString("ban-list-id", ("id", ban.Id.Value)); + var ip = ban.Address == null + ? string.Empty + : Loc.GetString("ban-list-ip", ("ip", ban.Address.Value.address)); + var hwid = ban.HWId == null ? string.Empty : Loc.GetString("ban-list-hwid", ("hwid", ban.HWId)); + var guid = ban.UserId == null + ? string.Empty + : Loc.GetString("ban-list-guid", ("guid", ban.UserId.Value.ToString())); + + _popup = new BanListIdsPopup(id, ip, hwid, guid); + + var box = UIBox2.FromDimensions(_ui.MousePositionScaled.Position, new Vector2(1, 1)); + _popup.Open(box); + } } diff --git a/Content.Client/Administration/UI/BanList/BanListLine.xaml.cs b/Content.Client/Administration/UI/BanList/BanListLine.xaml.cs deleted file mode 100644 index a2287d832a..0000000000 --- a/Content.Client/Administration/UI/BanList/BanListLine.xaml.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Content.Shared.Administration.BanList; -using Robust.Client.AutoGenerated; -using Robust.Client.UserInterface.Controls; -using Robust.Client.UserInterface.XAML; - -namespace Content.Client.Administration.UI.BanList; - -[GenerateTypedNameReferences] -public sealed partial class BanListLine : BoxContainer -{ - public readonly SharedServerBan Ban; - - public event Func? OnIdsClicked; - - public BanListLine(SharedServerBan ban) - { - RobustXamlLoader.Load(this); - - Ban = ban; - - IdsHidden.OnPressed += IdsPressed; - - 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 IdsPressed(BaseButton.ButtonEventArgs buttonEventArgs) - { - OnIdsClicked?.Invoke(this); - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - IdsHidden.OnPressed -= IdsPressed; - OnIdsClicked = null; - } -} diff --git a/Content.Client/Administration/UI/BanList/BanListWindow.xaml b/Content.Client/Administration/UI/BanList/BanListWindow.xaml index d246a3e3a2..d112824680 100644 --- a/Content.Client/Administration/UI/BanList/BanListWindow.xaml +++ b/Content.Client/Administration/UI/BanList/BanListWindow.xaml @@ -1,6 +1,11 @@  - + + + + diff --git a/Content.Client/Administration/UI/BanList/BanListWindow.xaml.cs b/Content.Client/Administration/UI/BanList/BanListWindow.xaml.cs index 2bb08a8825..c95f8f204d 100644 --- a/Content.Client/Administration/UI/BanList/BanListWindow.xaml.cs +++ b/Content.Client/Administration/UI/BanList/BanListWindow.xaml.cs @@ -10,6 +10,9 @@ public sealed partial class BanListWindow : DefaultWindow public BanListWindow() { RobustXamlLoader.Load(this); + + TabContainer.SetTabTitle(0, Loc.GetString("ban-list-bans")); + TabContainer.SetTabTitle(1, Loc.GetString("ban-list-role-bans")); } public void SetTitlePlayer(string playerName) diff --git a/Content.Client/Administration/UI/BanList/BanListControl.xaml b/Content.Client/Administration/UI/BanList/Bans/BanListControl.xaml similarity index 58% rename from Content.Client/Administration/UI/BanList/BanListControl.xaml rename to Content.Client/Administration/UI/BanList/Bans/BanListControl.xaml index b3c4803689..e12199f4e7 100644 --- a/Content.Client/Administration/UI/BanList/BanListControl.xaml +++ b/Content.Client/Administration/UI/BanList/Bans/BanListControl.xaml @@ -1,11 +1,11 @@ - + xmlns:bans="clr-namespace:Content.Client.Administration.UI.BanList.Bans"> - + - + diff --git a/Content.Client/Administration/UI/BanList/Bans/BanListControl.xaml.cs b/Content.Client/Administration/UI/BanList/Bans/BanListControl.xaml.cs new file mode 100644 index 0000000000..431087568a --- /dev/null +++ b/Content.Client/Administration/UI/BanList/Bans/BanListControl.xaml.cs @@ -0,0 +1,36 @@ +using Content.Client.Administration.UI.CustomControls; +using Content.Shared.Administration.BanList; +using Robust.Client.AutoGenerated; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.XAML; + +namespace Content.Client.Administration.UI.BanList.Bans; + +[GenerateTypedNameReferences] +public sealed partial class BanListControl : Control +{ + public event Action? LineIdsClicked; + + public BanListControl() + { + RobustXamlLoader.Load(this); + } + + public void SetBans(List bans) + { + for (var i = Bans.ChildCount - 1; i >= 1; i--) + { + Bans.GetChild(i).Dispose(); + } + + foreach (var ban in bans) + { + Bans.AddChild(new HSeparator()); + + var line = new BanListLine(ban); + line.IdsClicked += LineIdsClicked; + + Bans.AddChild(line); + } + } +} diff --git a/Content.Client/Administration/UI/BanList/BanListHeader.xaml b/Content.Client/Administration/UI/BanList/Bans/BanListHeader.xaml similarity index 97% rename from Content.Client/Administration/UI/BanList/BanListHeader.xaml rename to Content.Client/Administration/UI/BanList/Bans/BanListHeader.xaml index af02027758..00a652175c 100644 --- a/Content.Client/Administration/UI/BanList/BanListHeader.xaml +++ b/Content.Client/Administration/UI/BanList/Bans/BanListHeader.xaml @@ -25,7 +25,6 @@