AdminRemarksWindow.xaml.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Linq;
  2. using Content.Client.Administration.UI.Notes;
  3. using Content.Client.UserInterface.Controls;
  4. using Content.Shared.Administration.Notes;
  5. using Content.Shared.Database;
  6. using Robust.Client.AutoGenerated;
  7. using Robust.Client.GameObjects;
  8. using Robust.Client.UserInterface.XAML;
  9. namespace Content.Client.Administration.UI.AdminRemarks;
  10. [GenerateTypedNameReferences]
  11. public sealed partial class AdminRemarksWindow : FancyWindow
  12. {
  13. [Dependency] private readonly IEntitySystemManager _entitySystem = default!;
  14. private readonly SpriteSystem _sprites;
  15. private readonly Dictionary<(int, NoteType), AdminNotesLine> _inputs = new();
  16. public AdminRemarksWindow()
  17. {
  18. RobustXamlLoader.Load(this);
  19. IoCManager.InjectDependencies(this);
  20. _sprites = _entitySystem.GetEntitySystem<SpriteSystem>();
  21. }
  22. public void SetNotes(Dictionary<(int, NoteType), SharedAdminNote> notes)
  23. {
  24. foreach (var (id, input) in _inputs)
  25. {
  26. if (notes.ContainsKey(id))
  27. continue;
  28. NotesContainer.RemoveChild(input);
  29. _inputs.Remove(id);
  30. }
  31. foreach (var note in notes.Values.OrderByDescending(note => note.CreatedAt))
  32. {
  33. if (_inputs.TryGetValue((note.Id, note.NoteType), out var input))
  34. {
  35. input.UpdateNote(note);
  36. continue;
  37. }
  38. input = new AdminNotesLine(_sprites, note);
  39. NotesContainer.AddChild(input);
  40. _inputs[(note.Id, note.NoteType)] = input;
  41. }
  42. }
  43. }