GuideReagentGroupEmbed.xaml.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Diagnostics.CodeAnalysis;
  2. using System.Linq;
  3. using Content.Client.Guidebook.Richtext;
  4. using Content.Shared.Chemistry.Reagent;
  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 a reagent into a guidebook.
  14. /// </summary>
  15. [UsedImplicitly, GenerateTypedNameReferences]
  16. public sealed partial class GuideReagentGroupEmbed : BoxContainer, IDocumentTag
  17. {
  18. [Dependency] private readonly IPrototypeManager _prototype = default!;
  19. public GuideReagentGroupEmbed()
  20. {
  21. RobustXamlLoader.Load(this);
  22. IoCManager.InjectDependencies(this);
  23. MouseFilter = MouseFilterMode.Stop;
  24. }
  25. public GuideReagentGroupEmbed(string group) : this()
  26. {
  27. var prototypes = _prototype.EnumeratePrototypes<ReagentPrototype>()
  28. .Where(p => p.Group.Equals(group)).OrderBy(p => p.LocalizedName);
  29. foreach (var reagent in prototypes)
  30. {
  31. var embed = new GuideReagentEmbed(reagent);
  32. GroupContainer.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("Group", out var group))
  39. {
  40. Logger.Error("Reagent group embed tag is missing group argument");
  41. return false;
  42. }
  43. var prototypes = _prototype.EnumeratePrototypes<ReagentPrototype>()
  44. .Where(p => p.Group.Equals(group)).OrderBy(p => p.LocalizedName);
  45. foreach (var reagent in prototypes)
  46. {
  47. var embed = new GuideReagentEmbed(reagent);
  48. GroupContainer.AddChild(embed);
  49. }
  50. control = this;
  51. return true;
  52. }
  53. }