1
0

RulesControl.xaml.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Client.Guidebook;
  2. using Content.Client.Guidebook.RichText;
  3. using Content.Client.UserInterface.Systems.Info;
  4. using Content.Shared.Guidebook;
  5. using Robust.Client.AutoGenerated;
  6. using Robust.Client.UserInterface.Controls;
  7. using Robust.Client.UserInterface.XAML;
  8. using Robust.Shared.Prototypes;
  9. namespace Content.Client.Info;
  10. [GenerateTypedNameReferences]
  11. public sealed partial class RulesControl : BoxContainer, ILinkClickHandler
  12. {
  13. [Dependency] private readonly DocumentParsingManager _parsingMan = default!;
  14. private string? _currentEntry;
  15. private readonly Stack<string> _priorEntries = new();
  16. public RulesControl()
  17. {
  18. RobustXamlLoader.Load(this);
  19. IoCManager.InjectDependencies(this);
  20. SetGuide();
  21. HomeButton.OnPressed += _ => SetGuide();
  22. BackButton.OnPressed += _ => SetGuide(_priorEntries.Pop(), false);
  23. }
  24. public void HandleClick(string link)
  25. {
  26. SetGuide(link);
  27. }
  28. private void SetGuide(ProtoId<GuideEntryPrototype>? entry = null, bool addToPrior = true)
  29. {
  30. var coreEntry = UserInterfaceManager.GetUIController<InfoUIController>().GetCoreRuleEntry();
  31. entry ??= coreEntry;
  32. Scroll.SetScrollValue(default);
  33. RulesContainer.Children.Clear();
  34. if (!_parsingMan.TryAddMarkup(RulesContainer, entry.Value))
  35. return;
  36. if (addToPrior && _currentEntry != null)
  37. _priorEntries.Push(_currentEntry);
  38. _currentEntry = entry.Value;
  39. HomeButton.Visible = entry.Value != coreEntry.Id;
  40. BackButton.Visible = _priorEntries.Count != 0 && _priorEntries.Peek() != entry.Value;
  41. }
  42. }