Newer
Older
DungeonShooting / DungeonShooting_Godot / editor / src / IdeTextEditor.cs
@小李xl 小李xl on 21 Sep 2022 1 KB 编写代码ide样式
  1. using Godot;
  2.  
  3. namespace Editor
  4. {
  5. public class IdeTextEditor : TextEdit
  6. {
  7. private readonly Color KeyCodeColor = new Color(86 / 255f,156 / 255f,214 / 255f);
  8. private readonly Color AnnotationColor = new Color(77 / 255f,144 / 255f,52 / 255f);
  9. private readonly Color StringColor = new Color(214 / 255f,157 / 255f,133 / 255f);
  10. private readonly string[] KeyCodes = {
  11. "var",
  12. "namespace",
  13. "this",
  14. "class",
  15. "extends",
  16. "func",
  17. "get",
  18. "set",
  19. "import",
  20. "static",
  21. "new",
  22. "return",
  23. "for",
  24. "switch",
  25. "case",
  26. "break",
  27. "default",
  28. "while",
  29. "do",
  30. "is",
  31. "repeat",
  32. "null",
  33. "true",
  34. "false",
  35. "readonly",
  36. "enum",
  37. "private",
  38. "super",
  39. "if",
  40. "else",
  41. "continue",
  42. "typeof"
  43. };
  44. public override void _Ready()
  45. {
  46. //添加关键字
  47. for (int i = 0; i < KeyCodes.Length; i++)
  48. {
  49. AddKeywordColor(KeyCodes[i], KeyCodeColor);
  50. }
  51. AddColorRegion("//", "", AnnotationColor, true);
  52. AddColorRegion("/*", "*/", AnnotationColor);
  53. AddColorRegion("\"", "\"", StringColor);
  54. Text = @"
  55. //导入命名空间
  56. import system;
  57. //声明一个类, 继承Object
  58. class MyClass extends Object;
  59.  
  60. //声明变量
  61. var text = ""hello \""world\"""";
  62.  
  63. func say(message) {
  64. print(message);
  65. }
  66.  
  67. static test() {
  68. var arr = [1, 2, 3];
  69. if (arr.length > 0) {
  70. for (var i = 0; i < arr.length; i++) {
  71. print(arr[i]);
  72. }
  73. }
  74. }
  75.  
  76. ";
  77. }
  78. }
  79. }