RulesAndInfoWindow.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Numerics;
  2. using Content.Client.UserInterface.Systems.EscapeMenu;
  3. using Robust.Client.UserInterface;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.CustomControls;
  6. using Robust.Shared.ContentPack;
  7. namespace Content.Client.Info
  8. {
  9. public sealed class RulesAndInfoWindow : DefaultWindow
  10. {
  11. [Dependency] private readonly IResourceManager _resourceManager = default!;
  12. public RulesAndInfoWindow()
  13. {
  14. IoCManager.InjectDependencies(this);
  15. Title = Loc.GetString("ui-info-title");
  16. var rootContainer = new TabContainer();
  17. var rulesList = new RulesControl
  18. {
  19. Margin = new Thickness(10)
  20. };
  21. var tutorialList = new Info
  22. {
  23. Margin = new Thickness(10)
  24. };
  25. rootContainer.AddChild(rulesList);
  26. rootContainer.AddChild(tutorialList);
  27. TabContainer.SetTabTitle(rulesList, Loc.GetString("ui-info-tab-rules"));
  28. TabContainer.SetTabTitle(tutorialList, Loc.GetString("ui-info-tab-tutorial"));
  29. PopulateTutorial(tutorialList);
  30. Contents.AddChild(rootContainer);
  31. SetSize = new Vector2(650, 650);
  32. }
  33. private void PopulateTutorial(Info tutorialList)
  34. {
  35. AddSection(tutorialList, Loc.GetString("ui-info-header-intro"), "Intro.txt");
  36. var infoControlSection = new InfoControlsSection();
  37. tutorialList.InfoContainer.AddChild(infoControlSection);
  38. AddSection(tutorialList, Loc.GetString("ui-info-header-gameplay"), "Gameplay.txt", true);
  39. AddSection(tutorialList, Loc.GetString("ui-info-header-sandbox"), "Sandbox.txt", true);
  40. infoControlSection.ControlsButton.OnPressed += _ => UserInterfaceManager.GetUIController<OptionsUIController>().OpenWindow();
  41. }
  42. private static void AddSection(Info info, Control control)
  43. {
  44. info.InfoContainer.AddChild(control);
  45. }
  46. private void AddSection(Info info, string title, string path, bool markup = false)
  47. {
  48. AddSection(info, MakeSection(title, path, markup, _resourceManager));
  49. }
  50. private static Control MakeSection(string title, string path, bool markup, IResourceManager res)
  51. {
  52. return new InfoSection(title, res.ContentFileReadAllText($"/ServerInfo/{path}"), markup);
  53. }
  54. }
  55. }