AdminNotesLinePopup.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using Content.Shared.Administration.Notes;
  2. using Content.Shared.Database;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.XAML;
  6. using Robust.Shared.Timing;
  7. using static Robust.Client.UserInterface.Controls.BaseButton;
  8. namespace Content.Client.Administration.UI.Notes;
  9. [GenerateTypedNameReferences]
  10. public sealed partial class AdminNotesLinePopup : Popup
  11. {
  12. public event Action<int, NoteType>? OnEditPressed;
  13. public event Action<int, NoteType>? OnDeletePressed;
  14. [Dependency] private readonly IGameTiming _gameTiming = default!;
  15. public AdminNotesLinePopup(SharedAdminNote note, string playerName, bool showDelete, bool showEdit)
  16. {
  17. IoCManager.InjectDependencies(this);
  18. RobustXamlLoader.Load(this);
  19. NoteId = note.Id;
  20. NoteType = note.NoteType;
  21. DeleteButton.Visible = showDelete;
  22. EditButton.Visible = showEdit;
  23. UserInterfaceManager.ModalRoot.AddChild(this);
  24. PlayerNameLabel.Text = Loc.GetString("admin-notes-for", ("player", playerName));
  25. IdLabel.Text = Loc.GetString("admin-notes-id", ("id", note.Id));
  26. TypeLabel.Text = Loc.GetString("admin-notes-type", ("type", note.NoteType));
  27. SeverityLabel.Text = Loc.GetString("admin-notes-severity", ("severity", note.NoteSeverity ?? NoteSeverity.None));
  28. RoundIdLabel.Text = note.Round == null
  29. ? Loc.GetString("admin-notes-round-id-unknown")
  30. : Loc.GetString("admin-notes-round-id", ("id", note.Round));
  31. CreatedByLabel.Text = Loc.GetString("admin-notes-created-by", ("author", note.CreatedByName));
  32. CreatedAtLabel.Text = Loc.GetString("admin-notes-created-at", ("date", note.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")));
  33. EditedByLabel.Text = Loc.GetString("admin-notes-last-edited-by", ("author", note.EditedByName));
  34. EditedAtLabel.Text = Loc.GetString("admin-notes-last-edited-at", ("date", note.LastEditedAt?.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") ?? Loc.GetString("admin-notes-edited-never")));
  35. ExpiryTimeLabel.Text = note.ExpiryTime == null
  36. ? Loc.GetString("admin-notes-expires-never")
  37. : Loc.GetString("admin-notes-expires", ("expires", note.ExpiryTime.Value.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")));
  38. NoteTextEdit.InsertAtCursor(note.Message);
  39. if (note.NoteType is NoteType.ServerBan or NoteType.RoleBan)
  40. {
  41. DeleteButton.Text = Loc.GetString("admin-notes-hide");
  42. }
  43. EditButton.OnPressed += EditPressed;
  44. DeleteButton.OnPressed += DeletePressed;
  45. }
  46. public int NoteId { get; }
  47. public NoteType NoteType { get; }
  48. private TimeSpan? DeleteResetOn { get; set; }
  49. private void EditPressed(ButtonEventArgs args)
  50. {
  51. OnEditPressed?.Invoke(NoteId, NoteType);
  52. Close();
  53. }
  54. private void DeletePressed(ButtonEventArgs args)
  55. {
  56. if (DeleteResetOn is null)
  57. {
  58. DeleteResetOn = _gameTiming.CurTime.Add(TimeSpan.FromSeconds(3));
  59. DeleteButton.Text = Loc.GetString("admin-notes-delete-confirm");
  60. DeleteButton.ModulateSelfOverride = Color.Red;
  61. return;
  62. }
  63. ResetDeleteButton();
  64. OnDeletePressed?.Invoke(NoteId, NoteType);
  65. Close();
  66. }
  67. protected override void FrameUpdate(FrameEventArgs args)
  68. {
  69. base.FrameUpdate(args);
  70. // This checks for null for free, do not invert it as null always produces a false value
  71. if (DeleteResetOn < _gameTiming.CurTime)
  72. {
  73. ResetDeleteButton();
  74. DeleteResetOn = null;
  75. }
  76. }
  77. private void ResetDeleteButton()
  78. {
  79. DeleteButton.Text = Loc.GetString("admin-notes-delete");
  80. DeleteButton.ModulateSelfOverride = null;
  81. }
  82. protected override void Dispose(bool disposing)
  83. {
  84. base.Dispose(disposing);
  85. if (!disposing)
  86. {
  87. return;
  88. }
  89. EditButton.OnPressed -= EditPressed;
  90. DeleteButton.OnPressed -= DeletePressed;
  91. OnEditPressed = null;
  92. OnDeletePressed = null;
  93. }
  94. }