diff --git a/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn b/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn index 4966385..450e71d 100644 --- a/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn +++ b/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn @@ -23,6 +23,7 @@ custom_colors/member_variable_color = Color( 0.862745, 0.862745, 0.862745, 1 ) custom_colors/function_color = Color( 0.862745, 0.862745, 0.666667, 1 ) custom_colors/safe_line_number_color = Color( 1, 0.164706, 0.141176, 1 ) +custom_colors/caret_color = Color( 0, 0, 0, 0 ) custom_colors/background_color = Color( 0.117647, 0.117647, 0.117647, 1 ) custom_colors/number_color = Color( 0.709804, 0.807843, 0.658824, 1 ) custom_colors/current_line_color = Color( 0.0588235, 0.0588235, 0.0588235, 1 ) @@ -35,9 +36,8 @@ bookmark_gutter = true fold_gutter = true context_menu_enabled = false +deselect_on_focus_loss_enabled = false minimap_draw = true -caret_blink = true -caret_blink_speed = 0.4 script = ExtResource( 1 ) [node name="TextEditPainter" type="Node2D" parent="ScalePanel/TextEdit"] diff --git a/DungeonShooting_Godot/editor/src/CodeTextEditor.cs b/DungeonShooting_Godot/editor/src/CodeTextEditor.cs index eadde35..328549d 100644 --- a/DungeonShooting_Godot/editor/src/CodeTextEditor.cs +++ b/DungeonShooting_Godot/editor/src/CodeTextEditor.cs @@ -4,10 +4,23 @@ { public class CodeTextEditor : TextEdit { + /// + /// 关键字颜色 + /// private readonly Color KeyCodeColor = new Color(86 / 255f, 156 / 255f, 214 / 255f); + /// + /// 注释颜色 + /// private readonly Color AnnotationColor = new Color(77 / 255f, 144 / 255f, 52 / 255f); + /// + /// 字符串颜色 + /// private readonly Color StringColor = new Color(214 / 255f, 157 / 255f, 133 / 255f); + //------- 其他着色是在godot编辑器中设置的 + /// + /// 关键字列表 + /// private readonly string[] KeyCodes = { "var", @@ -47,6 +60,11 @@ private readonly string[] auto_compelete_right = { "'", "{", "\"", "(", "[" }; private readonly string[] auto_compelete_left = { "'", "}", "\"", ")", "]" }; + /// + /// 字体大小 + /// + public int FontSize { get; private set; } = 15; + private TextEditPainter _editPainter; public override void _Ready() @@ -188,19 +206,17 @@ private void _on_TextEdit_text_changed() { - // GD.Print(GetWordUnderCursor()); - // GD.Print(GetPosAtLineColumn(1, 1)); - Select(CursorGetLine(), CursorGetColumn() - 1, CursorGetLine(), CursorGetColumn()); - var key = GetSelectionText(); - Select(CursorGetLine(), CursorGetColumn(), CursorGetLine(), CursorGetColumn()); - for (int i = 0; i < 5; i++) - { - if (key == auto_compelete_right[i]) - { - InsertTextAtCursor(auto_compelete_left[i]); - CursorSetColumn(CursorGetColumn() - 1); - } - } + // Select(CursorGetLine(), CursorGetColumn() - 1, CursorGetLine(), CursorGetColumn()); + // var key = GetSelectionText(); + // Select(CursorGetLine(), CursorGetColumn(), CursorGetLine(), CursorGetColumn()); + // for (int i = 0; i < 5; i++) + // { + // if (key == auto_compelete_right[i]) + // { + // InsertTextAtCursor(auto_compelete_left[i]); + // CursorSetColumn(CursorGetColumn() - 1); + // } + // } } } } \ No newline at end of file diff --git a/DungeonShooting_Godot/editor/src/TextEditPainter.cs b/DungeonShooting_Godot/editor/src/TextEditPainter.cs index e93b00d..8797dd7 100644 --- a/DungeonShooting_Godot/editor/src/TextEditPainter.cs +++ b/DungeonShooting_Godot/editor/src/TextEditPainter.cs @@ -67,9 +67,35 @@ public override void _Draw() { + if (_textEdit == null) return; + + var lineHeight = _textEdit.GetLineHeight(); + + //绘制光标 + var line = _textEdit.CursorGetLine(); + var column = _textEdit.CursorGetColumn(); + var str = _textEdit.GetLine(line); + if (str != null && str.Length == column) + { + var cursorPos = _textEdit.GetPosAtLineColumn(line, column - 1); + if (cursorPos.x > -1 && cursorPos.y > -1) + { + DrawRect(new Rect2(cursorPos.x + 10, cursorPos.y - lineHeight, 1.4f, lineHeight), Colors.White); + } + } + else + { + var cursorPos = _textEdit.GetPosAtLineColumn(line, column); + if (cursorPos.x > -1 && cursorPos.y > -1) + { + DrawRect(new Rect2(cursorPos.x, cursorPos.y - lineHeight, 1.4f, lineHeight), Colors.White); + } + } + + + //绘制报错的行 if (_errorLines.Count > 0) { - var lineHeight = _textEdit.GetLineHeight(); var width = _textEdit.RectSize.x - _textEdit.MinimapWidth; for (int i = 0; i < _errorLines.Count; i++) { @@ -81,11 +107,5 @@ } } } - - //提交绘制 - private void CommitDrawLine(Vector2 start, Vector2 end, Color color, float width) - { - - } } } \ No newline at end of file