GuideTechDisciplineEmbed.xaml.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Diagnostics.CodeAnalysis;
  2. using System.Linq;
  3. using Content.Client.Guidebook.Richtext;
  4. using Content.Shared.Research.Prototypes;
  5. using JetBrains.Annotations;
  6. using Robust.Client.AutoGenerated;
  7. using Robust.Client.UserInterface;
  8. using Robust.Client.UserInterface.Controls;
  9. using Robust.Client.UserInterface.XAML;
  10. using Robust.Shared.Prototypes;
  11. namespace Content.Client.Guidebook.Controls;
  12. /// <summary>
  13. /// Control for embedding all the technologies in a discipline into a guidebook.
  14. /// </summary>
  15. [UsedImplicitly, GenerateTypedNameReferences]
  16. public sealed partial class GuideTechDisciplineEmbed : BoxContainer, IDocumentTag
  17. {
  18. [Dependency] private readonly IPrototypeManager _prototype = default!;
  19. public GuideTechDisciplineEmbed()
  20. {
  21. RobustXamlLoader.Load(this);
  22. IoCManager.InjectDependencies(this);
  23. MouseFilter = MouseFilterMode.Stop;
  24. }
  25. public GuideTechDisciplineEmbed(string group) : this()
  26. {
  27. var prototypes = _prototype.EnumeratePrototypes<TechnologyPrototype>()
  28. .Where(p => p.Discipline.Equals(group)).OrderBy(p => p.Tier).ThenBy(p => Loc.GetString(p.Name));
  29. foreach (var tech in prototypes)
  30. {
  31. var embed = new GuideTechnologyEmbed(tech);
  32. DisciplineContainer.AddChild(embed);
  33. }
  34. }
  35. public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out Control? control)
  36. {
  37. control = null;
  38. if (!args.TryGetValue("Discipline", out var group))
  39. {
  40. Logger.Error("Technology discipline embed tag is missing discipline argument");
  41. return false;
  42. }
  43. var prototypes = _prototype.EnumeratePrototypes<TechnologyPrototype>()
  44. .Where(p => p.Discipline.Equals(group)).OrderBy(p => p.Tier).ThenBy(p => Loc.GetString(p.Name));
  45. foreach (var tech in prototypes)
  46. {
  47. var embed = new GuideTechnologyEmbed(tech);
  48. DisciplineContainer.AddChild(embed);
  49. }
  50. control = this;
  51. return true;
  52. }
  53. }