NewsReaderUiFragment.xaml.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Content.Client.Message;
  2. using Content.Shared.MassMedia.Systems;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.XAML;
  6. namespace Content.Client.CartridgeLoader.Cartridges;
  7. [GenerateTypedNameReferences]
  8. public sealed partial class NewsReaderUiFragment : BoxContainer
  9. {
  10. public event Action? OnNextButtonPressed;
  11. public event Action? OnPrevButtonPressed;
  12. public event Action? OnNotificationSwithPressed;
  13. public NewsReaderUiFragment()
  14. {
  15. RobustXamlLoader.Load(this);
  16. Next.OnPressed += _ => OnNextButtonPressed?.Invoke();
  17. Prev.OnPressed += _ => OnPrevButtonPressed?.Invoke();
  18. NotificationSwitch.OnPressed += _ => OnNotificationSwithPressed?.Invoke();
  19. }
  20. public void UpdateState(NewsArticle article, int targetNum, int totalNum, bool notificationOn)
  21. {
  22. PageNum.Visible = true;
  23. PageText.Visible = true;
  24. ShareTime.Visible = true;
  25. Author.Visible = true;
  26. PageName.Text = article.Title;
  27. PageText.SetMarkupPermissive(article.Content);
  28. PageNum.Text = $"{targetNum}/{totalNum}";
  29. NotificationSwitch.Text = Loc.GetString(notificationOn ? "news-read-ui-notification-on" : "news-read-ui-notification-off");
  30. string shareTime = article.ShareTime.ToString(@"hh\:mm\:ss");
  31. ShareTime.SetMarkup(Loc.GetString("news-read-ui-time-prefix-text") + " " + shareTime);
  32. Author.SetMarkup(Loc.GetString("news-read-ui-author-prefix") + " " + (article.Author != null ? article.Author : Loc.GetString("news-read-ui-no-author")));
  33. Prev.Disabled = targetNum <= 1;
  34. Next.Disabled = targetNum >= totalNum;
  35. }
  36. public void UpdateEmptyState(bool notificationOn)
  37. {
  38. PageNum.Visible = false;
  39. PageText.Visible = false;
  40. ShareTime.Visible = false;
  41. Author.Visible = false;
  42. PageName.Text = Loc.GetString("news-read-ui-not-found-text");
  43. NotificationSwitch.Text = Loc.GetString(notificationOn ? "news-read-ui-notification-on" : "news-read-ui-notification-off");
  44. }
  45. }