RoundEndSummaryWindow.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System.Linq;
  2. using System.Numerics;
  3. using Content.Client.Message;
  4. using Content.Shared.GameTicking;
  5. using Robust.Client.UserInterface.Controls;
  6. using Robust.Client.UserInterface.CustomControls;
  7. using Robust.Shared.Utility;
  8. using static Robust.Client.UserInterface.Controls.BoxContainer;
  9. namespace Content.Client.RoundEnd
  10. {
  11. public sealed class RoundEndSummaryWindow : DefaultWindow
  12. {
  13. private readonly IEntityManager _entityManager;
  14. public int RoundId;
  15. public RoundEndSummaryWindow(string gm, string roundEnd, TimeSpan roundTimeSpan, int roundId,
  16. RoundEndMessageEvent.RoundEndPlayerInfo[] info, IEntityManager entityManager)
  17. {
  18. _entityManager = entityManager;
  19. MinSize = SetSize = new Vector2(520, 580);
  20. Title = Loc.GetString("round-end-summary-window-title");
  21. // The round end window is split into two tabs, one about the round stats
  22. // and the other is a list of RoundEndPlayerInfo for each player.
  23. // This tab would be a good place for things like: "x many people died.",
  24. // "clown slipped the crew x times.", "x shots were fired this round.", etc.
  25. // Also good for serious info.
  26. RoundId = roundId;
  27. var roundEndTabs = new TabContainer();
  28. roundEndTabs.AddChild(MakeRoundEndSummaryTab(gm, roundEnd, roundTimeSpan, roundId));
  29. roundEndTabs.AddChild(MakePlayerManifestTab(info));
  30. Contents.AddChild(roundEndTabs);
  31. OpenCenteredRight();
  32. MoveToFront();
  33. }
  34. private BoxContainer MakeRoundEndSummaryTab(string gamemode, string roundEnd, TimeSpan roundDuration, int roundId)
  35. {
  36. var roundEndSummaryTab = new BoxContainer
  37. {
  38. Orientation = LayoutOrientation.Vertical,
  39. Name = Loc.GetString("round-end-summary-window-round-end-summary-tab-title")
  40. };
  41. var roundEndSummaryContainerScrollbox = new ScrollContainer
  42. {
  43. VerticalExpand = true,
  44. Margin = new Thickness(10)
  45. };
  46. var roundEndSummaryContainer = new BoxContainer
  47. {
  48. Orientation = LayoutOrientation.Vertical
  49. };
  50. //Gamemode Name
  51. var gamemodeLabel = new RichTextLabel();
  52. var gamemodeMessage = new FormattedMessage();
  53. gamemodeMessage.AddMarkupOrThrow(Loc.GetString("round-end-summary-window-round-id-label", ("roundId", roundId)));
  54. gamemodeMessage.AddText(" ");
  55. gamemodeMessage.AddMarkupOrThrow(Loc.GetString("round-end-summary-window-gamemode-name-label", ("gamemode", gamemode)));
  56. gamemodeLabel.SetMessage(gamemodeMessage);
  57. roundEndSummaryContainer.AddChild(gamemodeLabel);
  58. //Duration
  59. var roundTimeLabel = new RichTextLabel();
  60. roundTimeLabel.SetMarkup(Loc.GetString("round-end-summary-window-duration-label",
  61. ("hours", roundDuration.Hours),
  62. ("minutes", roundDuration.Minutes),
  63. ("seconds", roundDuration.Seconds)));
  64. roundEndSummaryContainer.AddChild(roundTimeLabel);
  65. //Round end text
  66. if (!string.IsNullOrEmpty(roundEnd))
  67. {
  68. var roundEndLabel = new RichTextLabel();
  69. roundEndLabel.SetMarkup(roundEnd);
  70. roundEndSummaryContainer.AddChild(roundEndLabel);
  71. }
  72. roundEndSummaryContainerScrollbox.AddChild(roundEndSummaryContainer);
  73. roundEndSummaryTab.AddChild(roundEndSummaryContainerScrollbox);
  74. return roundEndSummaryTab;
  75. }
  76. private BoxContainer MakePlayerManifestTab(RoundEndMessageEvent.RoundEndPlayerInfo[] playersInfo)
  77. {
  78. var playerManifestTab = new BoxContainer
  79. {
  80. Orientation = LayoutOrientation.Vertical,
  81. Name = Loc.GetString("round-end-summary-window-player-manifest-tab-title")
  82. };
  83. var playerInfoContainerScrollbox = new ScrollContainer
  84. {
  85. VerticalExpand = true,
  86. Margin = new Thickness(10)
  87. };
  88. var playerInfoContainer = new BoxContainer
  89. {
  90. Orientation = LayoutOrientation.Vertical
  91. };
  92. //Put observers at the bottom of the list. Put antags on top.
  93. var sortedPlayersInfo = playersInfo.OrderBy(p => p.Observer).ThenBy(p => !p.Antag);
  94. //Create labels for each player info.
  95. foreach (var playerInfo in sortedPlayersInfo)
  96. {
  97. var hBox = new BoxContainer
  98. {
  99. Orientation = LayoutOrientation.Horizontal,
  100. };
  101. var playerInfoText = new RichTextLabel
  102. {
  103. VerticalAlignment = VAlignment.Center,
  104. VerticalExpand = true,
  105. };
  106. if (playerInfo.PlayerNetEntity != null)
  107. {
  108. hBox.AddChild(new SpriteView(playerInfo.PlayerNetEntity.Value, _entityManager)
  109. {
  110. OverrideDirection = Direction.South,
  111. VerticalAlignment = VAlignment.Center,
  112. SetSize = new Vector2(32, 32),
  113. VerticalExpand = true,
  114. });
  115. }
  116. if (playerInfo.PlayerICName != null)
  117. {
  118. if (playerInfo.Observer)
  119. {
  120. playerInfoText.SetMarkup(
  121. Loc.GetString("round-end-summary-window-player-info-if-observer-text",
  122. ("playerOOCName", playerInfo.PlayerOOCName),
  123. ("playerICName", playerInfo.PlayerICName)));
  124. }
  125. else
  126. {
  127. //TODO: On Hover display a popup detailing more play info.
  128. //For example: their antag goals and if they completed them sucessfully.
  129. var icNameColor = playerInfo.Antag ? "red" : "white";
  130. playerInfoText.SetMarkup(
  131. Loc.GetString("round-end-summary-window-player-info-if-not-observer-text",
  132. ("playerOOCName", playerInfo.PlayerOOCName),
  133. ("icNameColor", icNameColor),
  134. ("playerICName", playerInfo.PlayerICName),
  135. ("playerRole", Loc.GetString(playerInfo.Role))));
  136. }
  137. }
  138. hBox.AddChild(playerInfoText);
  139. playerInfoContainer.AddChild(hBox);
  140. }
  141. playerInfoContainerScrollbox.AddChild(playerInfoContainer);
  142. playerManifestTab.AddChild(playerInfoContainerScrollbox);
  143. return playerManifestTab;
  144. }
  145. }
  146. }