1
0

GuideMicrowaveGroupEmbed.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Diagnostics.CodeAnalysis;
  2. using System.Linq;
  3. using Content.Client.Guidebook.Richtext;
  4. using Content.Shared.Kitchen;
  5. using JetBrains.Annotations;
  6. using Robust.Client.UserInterface.Controls;
  7. using Robust.Client.UserInterface;
  8. using Robust.Shared.Prototypes;
  9. namespace Content.Client.Guidebook.Controls;
  10. /// <summary>
  11. /// Control for listing microwave recipes in a guidebook
  12. /// </summary>
  13. [UsedImplicitly]
  14. public sealed partial class GuideMicrowaveGroupEmbed : BoxContainer, IDocumentTag
  15. {
  16. [Dependency] private readonly IPrototypeManager _prototype = default!;
  17. public GuideMicrowaveGroupEmbed()
  18. {
  19. Orientation = LayoutOrientation.Vertical;
  20. IoCManager.InjectDependencies(this);
  21. MouseFilter = MouseFilterMode.Stop;
  22. }
  23. public GuideMicrowaveGroupEmbed(string group) : this()
  24. {
  25. CreateEntries(group);
  26. }
  27. public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out Control? control)
  28. {
  29. control = null;
  30. if (!args.TryGetValue("Group", out var group))
  31. {
  32. Logger.Error("Microwave group embed tag is missing group argument");
  33. return false;
  34. }
  35. CreateEntries(group);
  36. control = this;
  37. return true;
  38. }
  39. private void CreateEntries(string group)
  40. {
  41. var prototypes = _prototype.EnumeratePrototypes<FoodRecipePrototype>()
  42. .Where(p => p.Group.Equals(group))
  43. .OrderBy(p => p.Name);
  44. foreach (var recipe in prototypes)
  45. {
  46. var embed = new GuideMicrowaveEmbed(recipe);
  47. AddChild(embed);
  48. }
  49. }
  50. }