Newer
Older
DungeonShooting / DungeonShooting_Godot / editor / src / CodeHintItem.cs
@小李xl 小李xl on 26 Sep 2022 1 KB 代码提示组件开发
  1. using Godot;
  2.  
  3. namespace DScript.GodotEditor
  4. {
  5. /// <summary>
  6. /// 提示面板中的提示项
  7. /// </summary>
  8. public class CodeHintItem : Button
  9. {
  10. /// <summary>
  11. /// 活动时背景颜色
  12. /// </summary>
  13. private static Color ActiveColor = new Color(0.20784314F,0.30980393F,0.52156866F);
  14. /// <summary>
  15. /// 非活动时背景颜色
  16. /// </summary>
  17. private static Color UnActiveColor = new Color(0, 0, 0, 0);
  18. /// <summary>
  19. /// 当前项的索引
  20. /// </summary>
  21. public int Index { get; internal set; }
  22. /// <summary>
  23. /// 代码类型
  24. /// </summary>
  25. public CodeHintType CodeType
  26. {
  27. get => _codeType;
  28. set => SetCodeType(value);
  29. }
  30. private CodeHintType _codeType;
  31.  
  32. /// <summary>
  33. /// 代码文本
  34. /// </summary>
  35. public string CodeText
  36. {
  37. get => _codeText;
  38. set => SetCodeText(value);
  39. }
  40. //显示的文本
  41. private string _codeText;
  42.  
  43. private TextureRect _icon;
  44. private RichTextLabel _text;
  45. private ColorRect _bgColor;
  46.  
  47. public override void _Ready()
  48. {
  49. _icon = GetNode<TextureRect>("Icon");
  50. _text = GetNode<RichTextLabel>("Text");
  51. _bgColor = GetNode<ColorRect>("BgColor");
  52. }
  53.  
  54. public void SetText()
  55. {
  56. }
  57.  
  58. /// <summary>
  59. /// 设置成活动状态
  60. /// </summary>
  61. internal void SetActive(bool active)
  62. {
  63. _bgColor.Color = active ? ActiveColor : UnActiveColor;
  64. }
  65. //设置代码类型
  66. private void SetCodeType(CodeHintType type)
  67. {
  68. _codeType = type;
  69. }
  70. //设置代码文本
  71. private void SetCodeText(string code)
  72. {
  73. _codeText = code;
  74. _text.BbcodeText = code;
  75. }
  76.  
  77. //点击时调用
  78. private void _on_click()
  79. {
  80. CodeHintPanel.Instance.ConfirmInput(Index);
  81. }
  82. }
  83. }