1
0

PdaNavigationButton.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Numerics;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.Graphics;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.XAML;
  6. using Robust.Shared.Utility;
  7. namespace Content.Client.PDA;
  8. [GenerateTypedNameReferences]
  9. public sealed partial class PdaNavigationButton : ContainerButton
  10. {
  11. private bool _isCurrent;
  12. private bool _isActive = true;
  13. private Thickness _borderThickness = new(0, 0, 0, 2);
  14. private Thickness _currentTabBorderThickness = new(2, 0, 2, 0);
  15. private readonly StyleBoxFlat _styleBox = new()
  16. {
  17. BackgroundColor = Color.FromHex("#202023"),
  18. BorderColor = Color.FromHex("#5a5a5a"),
  19. BorderThickness = new Thickness(0, 0, 0, 2)
  20. };
  21. public string InactiveBgColor { get; set; } = "#202023";
  22. public string ActiveBgColor { get; set; } = "#25252a";
  23. public string InactiveFgColor { get; set; } = "#5a5a5a";
  24. public string ActiveFgColor { get; set; } = "#FFFFFF";
  25. public SpriteSpecifier? IconTexture
  26. {
  27. set
  28. {
  29. Icon.Visible = value != null;
  30. Label.Visible = value == null;
  31. if (value is not null)
  32. Icon.SetFromSpriteSpecifier(value);
  33. }
  34. }
  35. public Vector2 IconScale
  36. {
  37. get => Icon.DisplayRect.TextureScale;
  38. set => Icon.DisplayRect.TextureScale = value;
  39. }
  40. public string? LabelText
  41. {
  42. get => Label.Text;
  43. set => Label.Text = value;
  44. }
  45. /// <summary>
  46. /// Sets the border thickness when the tab is not the currently active one
  47. /// </summary>
  48. public Thickness BorderThickness
  49. {
  50. get => _borderThickness;
  51. set
  52. {
  53. _borderThickness = value;
  54. _styleBox.BorderThickness = _isCurrent ? _currentTabBorderThickness : value;
  55. }
  56. }
  57. /// <summary>
  58. /// Sets the border thickness when this tab is the currently active tab
  59. /// </summary>
  60. public Thickness CurrentTabBorderThickness
  61. {
  62. get => _currentTabBorderThickness;
  63. set
  64. {
  65. _currentTabBorderThickness = value;
  66. _styleBox.BorderThickness = _isCurrent ? value : _borderThickness;
  67. }
  68. }
  69. public bool IsCurrent
  70. {
  71. get => _isCurrent;
  72. set
  73. {
  74. _isCurrent = value;
  75. _styleBox.BackgroundColor = Color.FromHex(value ? ActiveBgColor : InactiveBgColor);
  76. _styleBox.BorderThickness = value ? CurrentTabBorderThickness : BorderThickness;
  77. }
  78. }
  79. public bool IsActive
  80. {
  81. get => _isActive;
  82. set
  83. {
  84. _isActive = value;
  85. Icon.Modulate = Color.FromHex(value ? ActiveFgColor : InactiveFgColor);
  86. Label.FontColorOverride = Color.FromHex(value ? ActiveFgColor : InactiveFgColor);
  87. }
  88. }
  89. public PdaNavigationButton()
  90. {
  91. RobustXamlLoader.Load(this);
  92. Background.PanelOverride = _styleBox;
  93. }
  94. }