1
0

VerbMenuElement.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Numerics;
  2. using Content.Client.ContextMenu.UI;
  3. using Content.Shared.Verbs;
  4. using Robust.Client.GameObjects;
  5. using Robust.Client.UserInterface.Controls;
  6. using Robust.Client.Utility;
  7. using Robust.Shared.GameObjects;
  8. using Robust.Shared.IoC;
  9. using Robust.Shared.Maths;
  10. namespace Content.Client.Verbs.UI
  11. {
  12. /// <summary>
  13. /// Slight extension of <see cref="ContextMenuElement"/> that uses a SpriteSpecifier for it's icon and provides
  14. /// constructors that take verbs or verb categories.
  15. /// </summary>
  16. public sealed partial class VerbMenuElement : ContextMenuElement
  17. {
  18. public const string StyleClassVerbMenuConfirmationTexture = "verbMenuConfirmationTexture";
  19. // Setters to provide access to children generated by XAML.
  20. public bool IconVisible { set => Icon.Visible = value; }
  21. public bool TextVisible { set => Label.Visible = value; }
  22. // Top quality variable naming
  23. public readonly Verb? Verb;
  24. public VerbMenuElement(Verb verb) : base(verb.Text)
  25. {
  26. ToolTip = verb.Message;
  27. Disabled = verb.Disabled;
  28. Verb = verb;
  29. Label.SetOnlyStyleClass(verb.TextStyleClass);
  30. // There are no confirmations in debug fam.
  31. #if !DEBUG
  32. if (verb.ConfirmationPopup)
  33. {
  34. ExpansionIndicator.SetOnlyStyleClass(StyleClassVerbMenuConfirmationTexture);
  35. ExpansionIndicator.Visible = true;
  36. }
  37. #endif
  38. var entManager = IoCManager.Resolve<IEntityManager>();
  39. if (verb.Icon == null && verb.IconEntity != null)
  40. {
  41. var spriteView = new SpriteView()
  42. {
  43. OverrideDirection = Direction.South,
  44. SetSize = new Vector2(ElementHeight, ElementHeight),
  45. };
  46. spriteView.SetEntity(entManager.GetEntity(verb.IconEntity.Value));
  47. Icon.AddChild(spriteView);
  48. return;
  49. }
  50. Icon.AddChild(new TextureRect()
  51. {
  52. Texture = verb.Icon != null ? entManager.System<SpriteSystem>().Frame0(verb.Icon) : null,
  53. Stretch = TextureRect.StretchMode.KeepAspectCentered
  54. });
  55. }
  56. public VerbMenuElement(VerbCategory category, string styleClass) : base(category.Text)
  57. {
  58. Label.SetOnlyStyleClass(styleClass);
  59. Icon.AddChild(new TextureRect()
  60. {
  61. Texture = category.Icon != null ? IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>().Frame0(category.Icon) : null,
  62. Stretch = TextureRect.StretchMode.KeepAspectCentered
  63. });
  64. }
  65. }
  66. }