CreditsWindow.xaml.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Numerics;
  4. using Content.Client.Stylesheets;
  5. using Content.Shared.CCVar;
  6. using Robust.Client.AutoGenerated;
  7. using Robust.Client.Credits;
  8. using Robust.Client.ResourceManagement;
  9. using Robust.Client.UserInterface;
  10. using Robust.Client.UserInterface.Controls;
  11. using Robust.Client.UserInterface.CustomControls;
  12. using Robust.Client.UserInterface.XAML;
  13. using Robust.Shared.Configuration;
  14. using Robust.Shared.ContentPack;
  15. using Robust.Shared.IoC;
  16. using Robust.Shared.Localization;
  17. using Robust.Shared.Maths;
  18. using Robust.Shared.Utility;
  19. using YamlDotNet.RepresentationModel;
  20. using static Robust.Client.UserInterface.Controls.BoxContainer;
  21. namespace Content.Client.Credits
  22. {
  23. [GenerateTypedNameReferences]
  24. public sealed partial class CreditsWindow : DefaultWindow
  25. {
  26. [Dependency] private readonly IResourceManager _resourceManager = default!;
  27. [Dependency] private readonly IConfigurationManager _cfg = default!;
  28. private static readonly Dictionary<string, int> PatronTierPriority = new()
  29. {
  30. ["Nuclear Operative"] = 1,
  31. ["Syndicate Agent"] = 2,
  32. ["Revolutionary"] = 3
  33. };
  34. public CreditsWindow()
  35. {
  36. IoCManager.InjectDependencies(this);
  37. RobustXamlLoader.Load(this);
  38. TabContainer.SetTabTitle(Ss14ContributorsTab, Loc.GetString("credits-window-ss14contributorslist-tab"));
  39. TabContainer.SetTabTitle(PatronsTab, Loc.GetString("credits-window-patrons-tab"));
  40. TabContainer.SetTabTitle(LicensesTab, Loc.GetString("credits-window-licenses-tab"));
  41. PopulateContributors(Ss14ContributorsContainer);
  42. PopulatePatrons(PatronsContainer);
  43. PopulateLicenses(LicensesContainer);
  44. }
  45. private void PopulateLicenses(BoxContainer licensesContainer)
  46. {
  47. foreach (var entry in CreditsManager.GetLicenses(_resourceManager).OrderBy(p => p.Name))
  48. {
  49. licensesContainer.AddChild(new Label {StyleClasses = {StyleBase.StyleClassLabelHeading}, Text = entry.Name});
  50. // We split these line by line because otherwise
  51. // the LGPL causes Clyde to go out of bounds in the rendering code.
  52. foreach (var line in entry.License.Split("\n"))
  53. {
  54. licensesContainer.AddChild(new Label {Text = line, FontColorOverride = new Color(200, 200, 200)});
  55. }
  56. }
  57. }
  58. private void PopulatePatrons(BoxContainer patronsContainer)
  59. {
  60. var patrons = LoadPatrons();
  61. // Do not show "become a patron" button on Steam builds
  62. // since Patreon violates Valve's rules about alternative storefronts.
  63. var linkPatreon = _cfg.GetCVar(CCVars.InfoLinksPatreon);
  64. if (!_cfg.GetCVar(CCVars.BrandingSteam) && linkPatreon != "")
  65. {
  66. Button patronButton;
  67. patronsContainer.AddChild(patronButton = new Button
  68. {
  69. Text = Loc.GetString("credits-window-become-patron-button"),
  70. HorizontalAlignment = HAlignment.Center
  71. });
  72. patronButton.OnPressed +=
  73. _ => IoCManager.Resolve<IUriOpener>().OpenUri(linkPatreon);
  74. }
  75. var first = true;
  76. foreach (var tier in patrons.GroupBy(p => p.Tier).OrderBy(p => PatronTierPriority[p.Key]))
  77. {
  78. if (!first)
  79. {
  80. patronsContainer.AddChild(new Control {MinSize = new Vector2(0, 10)});
  81. }
  82. first = false;
  83. patronsContainer.AddChild(new Label {StyleClasses = {StyleBase.StyleClassLabelHeading}, Text = $"{tier.Key}"});
  84. var msg = string.Join(", ", tier.OrderBy(p => p.Name).Select(p => p.Name));
  85. var label = new RichTextLabel();
  86. label.SetMessage(msg);
  87. patronsContainer.AddChild(label);
  88. }
  89. }
  90. private IEnumerable<PatronEntry> LoadPatrons()
  91. {
  92. var yamlStream = _resourceManager.ContentFileReadYaml(new ("/Credits/Patrons.yml"));
  93. var sequence = (YamlSequenceNode) yamlStream.Documents[0].RootNode;
  94. return sequence
  95. .Cast<YamlMappingNode>()
  96. .Select(m => new PatronEntry(m["Name"].AsString(), m["Tier"].AsString()));
  97. }
  98. private void PopulateContributors(BoxContainer ss14ContributorsContainer)
  99. {
  100. Button contributeButton;
  101. ss14ContributorsContainer.AddChild(new BoxContainer
  102. {
  103. Orientation = LayoutOrientation.Horizontal,
  104. HorizontalAlignment = HAlignment.Center,
  105. SeparationOverride = 20,
  106. Children =
  107. {
  108. new Label {Text = Loc.GetString("credits-window-contributor-encouragement-label") },
  109. (contributeButton = new Button {Text = Loc.GetString("credits-window-contribute-button")})
  110. }
  111. });
  112. var first = true;
  113. void AddSection(string title, string path, bool markup = false)
  114. {
  115. if (!first)
  116. {
  117. ss14ContributorsContainer.AddChild(new Control {MinSize = new Vector2(0, 10)});
  118. }
  119. first = false;
  120. ss14ContributorsContainer.AddChild(new Label {StyleClasses = {StyleBase.StyleClassLabelHeading}, Text = title});
  121. var label = new RichTextLabel();
  122. var text = _resourceManager.ContentFileReadAllText($"/Credits/{path}");
  123. if (markup)
  124. {
  125. label.SetMessage(FormattedMessage.FromMarkupOrThrow(text.Trim()));
  126. }
  127. else
  128. {
  129. label.SetMessage(text);
  130. }
  131. ss14ContributorsContainer.AddChild(label);
  132. }
  133. AddSection(Loc.GetString("credits-window-contributors-section-title"), "GitHub.txt");
  134. AddSection(Loc.GetString("credits-window-codebases-section-title"), "SpaceStation13.txt");
  135. AddSection(Loc.GetString("credits-window-original-remake-team-section-title"), "OriginalRemake.txt");
  136. AddSection(Loc.GetString("credits-window-special-thanks-section-title"), "SpecialThanks.txt", true);
  137. var linkGithub = _cfg.GetCVar(CCVars.InfoLinksGithub);
  138. contributeButton.OnPressed += _ =>
  139. IoCManager.Resolve<IUriOpener>().OpenUri(linkGithub);
  140. if (linkGithub == "")
  141. contributeButton.Visible = false;
  142. }
  143. private sealed class PatronEntry
  144. {
  145. public string Name { get; }
  146. public string Tier { get; }
  147. public PatronEntry(string name, string tier)
  148. {
  149. Name = name;
  150. Tier = tier;
  151. }
  152. }
  153. }
  154. }