1
0

LinkBanner.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Content.Client.Changelog;
  2. using Content.Client.UserInterface.Systems.EscapeMenu;
  3. using Content.Client.UserInterface.Systems.Guidebook;
  4. using Content.Shared.CCVar;
  5. using Robust.Client.UserInterface;
  6. using Robust.Client.UserInterface.Controls;
  7. using Robust.Shared.Collections;
  8. using Robust.Shared.Configuration;
  9. namespace Content.Client.Info
  10. {
  11. public sealed class LinkBanner : BoxContainer
  12. {
  13. private readonly IConfigurationManager _cfg;
  14. private ValueList<(CVarDef<string> cVar, Button button)> _infoLinks;
  15. public LinkBanner()
  16. {
  17. var buttons = new BoxContainer
  18. {
  19. Orientation = LayoutOrientation.Horizontal
  20. };
  21. AddChild(buttons);
  22. var uriOpener = IoCManager.Resolve<IUriOpener>();
  23. _cfg = IoCManager.Resolve<IConfigurationManager>();
  24. var rulesButton = new Button() {Text = Loc.GetString("server-info-rules-button")};
  25. rulesButton.OnPressed += args => new RulesAndInfoWindow().Open();
  26. buttons.AddChild(rulesButton);
  27. AddInfoButton("server-info-discord-button", CCVars.InfoLinksDiscord);
  28. AddInfoButton("server-info-website-button", CCVars.InfoLinksWebsite);
  29. AddInfoButton("server-info-wiki-button", CCVars.InfoLinksWiki);
  30. AddInfoButton("server-info-forum-button", CCVars.InfoLinksForum);
  31. AddInfoButton("server-info-telegram-button", CCVars.InfoLinksTelegram);
  32. var guidebookController = UserInterfaceManager.GetUIController<GuidebookUIController>();
  33. var guidebookButton = new Button() { Text = Loc.GetString("server-info-guidebook-button") };
  34. guidebookButton.OnPressed += _ =>
  35. {
  36. guidebookController.ToggleGuidebook();
  37. };
  38. buttons.AddChild(guidebookButton);
  39. var changelogButton = new ChangelogButton();
  40. changelogButton.OnPressed += args => UserInterfaceManager.GetUIController<ChangelogUIController>().ToggleWindow();
  41. buttons.AddChild(changelogButton);
  42. void AddInfoButton(string loc, CVarDef<string> cVar)
  43. {
  44. var button = new Button { Text = Loc.GetString(loc) };
  45. button.OnPressed += _ => uriOpener.OpenUri(_cfg.GetCVar(cVar));
  46. buttons.AddChild(button);
  47. _infoLinks.Add((cVar, button));
  48. }
  49. }
  50. protected override void EnteredTree()
  51. {
  52. // LinkBanner is constructed before the client even connects to the server due to UI refactor stuff.
  53. // We need to update these buttons when the UI is shown.
  54. base.EnteredTree();
  55. foreach (var (cVar, link) in _infoLinks)
  56. {
  57. link.Visible = _cfg.GetCVar(cVar) != "";
  58. }
  59. }
  60. }
  61. }