1
0

GuideTechnologyEmbed.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Diagnostics.CodeAnalysis;
  2. using Content.Client.Guidebook.Richtext;
  3. using Content.Client.Message;
  4. using Content.Client.Research;
  5. using Content.Client.UserInterface.ControlExtensions;
  6. using Content.Shared.Research.Prototypes;
  7. using JetBrains.Annotations;
  8. using Robust.Client.AutoGenerated;
  9. using Robust.Client.GameObjects;
  10. using Robust.Client.Graphics;
  11. using Robust.Client.UserInterface;
  12. using Robust.Client.UserInterface.Controls;
  13. using Robust.Client.UserInterface.XAML;
  14. using Robust.Shared.Prototypes;
  15. namespace Content.Client.Guidebook.Controls;
  16. /// <summary>
  17. /// Control for embedding a research technology into a guidebook.
  18. /// </summary>
  19. [UsedImplicitly, GenerateTypedNameReferences]
  20. public sealed partial class GuideTechnologyEmbed : BoxContainer, IDocumentTag, ISearchableControl
  21. {
  22. [Dependency] private readonly IEntitySystemManager _systemManager = default!;
  23. [Dependency] private readonly IPrototypeManager _prototype = default!;
  24. private readonly ResearchSystem _research;
  25. private readonly SpriteSystem _sprite;
  26. public GuideTechnologyEmbed()
  27. {
  28. RobustXamlLoader.Load(this);
  29. IoCManager.InjectDependencies(this);
  30. _research = _systemManager.GetEntitySystem<ResearchSystem>();
  31. _sprite = _systemManager.GetEntitySystem<SpriteSystem>();
  32. MouseFilter = MouseFilterMode.Stop;
  33. }
  34. public GuideTechnologyEmbed(string technology) : this()
  35. {
  36. GenerateControl(_prototype.Index<TechnologyPrototype>(technology));
  37. }
  38. public GuideTechnologyEmbed(TechnologyPrototype technology) : this()
  39. {
  40. GenerateControl(technology);
  41. }
  42. public bool CheckMatchesSearch(string query)
  43. {
  44. return this.ChildrenContainText(query);
  45. }
  46. public void SetHiddenState(bool state, string query)
  47. {
  48. Visible = CheckMatchesSearch(query) ? state : !state;
  49. }
  50. public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out Control? control)
  51. {
  52. control = null;
  53. if (!args.TryGetValue("Technology", out var id))
  54. {
  55. Logger.Error("Technology embed tag is missing technology prototype argument");
  56. return false;
  57. }
  58. if (!_prototype.TryIndex<TechnologyPrototype>(id, out var technology))
  59. {
  60. Logger.Error($"Specified technology prototype \"{id}\" is not a valid technology prototype");
  61. return false;
  62. }
  63. GenerateControl(technology);
  64. control = this;
  65. return true;
  66. }
  67. private void GenerateControl(TechnologyPrototype technology)
  68. {
  69. var discipline = _prototype.Index(technology.Discipline);
  70. NameLabel.SetMarkup($"[bold]{Loc.GetString(technology.Name)}[/bold]");
  71. DescriptionLabel.SetMessage(_research.GetTechnologyDescription(technology, includePrereqs: true, disciplinePrototype: discipline));
  72. TechTexture.Texture = _sprite.Frame0(technology.Icon);
  73. DisciplineColorBackground.PanelOverride = new StyleBoxFlat
  74. {
  75. BackgroundColor = discipline.Color
  76. };
  77. }
  78. }