diff --git a/DungeonShooting_Godot/editor/example.ds b/DungeonShooting_Godot/editor/example.ds
index f6c8aa5..7b3d21a 100644
--- a/DungeonShooting_Godot/editor/example.ds
+++ b/DungeonShooting_Godot/editor/example.ds
@@ -25,23 +25,23 @@
//在类中声明一个叫 length 的 get 属性, get 属性必须有返回值
get length() {
- return b;
+ return b;
}
//在类中声明一个叫 length 的 set 属性, set 属性设置的数据变量叫 param
//param 关键字只能出现在 set 属性中, 并且只读
set length(val) {
- b = val;
+ b = val;
}
//在类中声明一个 say 的函数, 并且支持传入一个参数
func say(str) {
- var message = "say: " + str;
- print(message);
+ var message = "say: " + str;
+ print(message);
}
//在类中声明一个 say 的函数重载, 该重载为 0 个参数
//注意, 因为脚本数据类型为弱类型, 无法通过数据类型判断重载, 所以函数重载是根据参数长度来进行重载
func say() {
- say("hello");
+ say("hello");
}
//在类中声明构造函数, 其他地方调用 MyClass(); 时就会调用该类的构造函数, 无参构造可省略
@@ -51,7 +51,7 @@
}
//构造继承, 构造函数继承该类的无参构造函数
func MyClass(message) extends MyClass() {
- print("创建了MyClass, message: " + message);
+ print("创建了MyClass, message: " + message);
}
//语法展示
diff --git a/DungeonShooting_Godot/editor/prefabs/CodeHintPanel.tscn b/DungeonShooting_Godot/editor/prefabs/CodeHintPanel.tscn
index 3acd025..4be1e8d 100644
--- a/DungeonShooting_Godot/editor/prefabs/CodeHintPanel.tscn
+++ b/DungeonShooting_Godot/editor/prefabs/CodeHintPanel.tscn
@@ -12,9 +12,9 @@
border_color = Color( 0.270588, 0.270588, 0.270588, 1 )
[node name="CodeHintPanel" type="PopupPanel"]
-visible = true
margin_right = 273.0
margin_bottom = 130.0
+focus_mode = 1
custom_styles/panel = SubResource( 4 )
script = ExtResource( 2 )
CodeHintItem = ExtResource( 1 )
diff --git a/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn b/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn
index 7702389..b661115 100644
--- a/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn
+++ b/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn
@@ -1,6 +1,6 @@
[gd_scene load_steps=5 format=2]
-[ext_resource path="res://editor/src/CodeTextEditor.cs" type="Script" id=1]
+[ext_resource path="res://editor/src/CodeTextEdit.cs" type="Script" id=1]
[ext_resource path="res://editor/ide_cn_font_12.tres" type="DynamicFont" id=2]
[ext_resource path="res://editor/src/CodePanel.cs" type="Script" id=3]
[ext_resource path="res://editor/src/TextEditPainter.cs" type="Script" id=4]
@@ -29,8 +29,10 @@
highlight_current_line = true
syntax_highlighting = true
show_line_numbers = true
+draw_tabs = true
bookmark_gutter = true
context_menu_enabled = false
+virtual_keyboard_enabled = false
deselect_on_focus_loss_enabled = false
minimap_draw = true
caret_blink = true
@@ -40,4 +42,5 @@
script = ExtResource( 4 )
[connection signal="resized" from="ScalePanel" to="." method="_on_ScalePanel_resized"]
+[connection signal="cursor_changed" from="ScalePanel/TextEdit" to="ScalePanel/TextEdit" method="_on_TextEdit_cursor_changed"]
[connection signal="text_changed" from="ScalePanel/TextEdit" to="ScalePanel/TextEdit" method="_on_TextEdit_text_changed"]
diff --git a/DungeonShooting_Godot/editor/prefabs/Editor.tscn b/DungeonShooting_Godot/editor/prefabs/Editor.tscn
new file mode 100644
index 0000000..47cd4db
--- /dev/null
+++ b/DungeonShooting_Godot/editor/prefabs/Editor.tscn
@@ -0,0 +1,18 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://editor/src/Editor.cs" type="Script" id=1]
+[ext_resource path="res://editor/prefabs/CodePanel.tscn" type="PackedScene" id=2]
+[ext_resource path="res://editor/prefabs/CodeHintPanel.tscn" type="PackedScene" id=3]
+
+[node name="Editor" type="Control"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+script = ExtResource( 1 )
+
+[node name="CodePanel" parent="." instance=ExtResource( 2 )]
+
+[node name="CodeHintPanel" parent="." instance=ExtResource( 3 )]
+margin_left = 196.0
+margin_top = 125.0
+margin_right = 469.0
+margin_bottom = 255.0
diff --git a/DungeonShooting_Godot/editor/src/CodeHintManager.cs b/DungeonShooting_Godot/editor/src/CodeHintManager.cs
new file mode 100644
index 0000000..db81be6
--- /dev/null
+++ b/DungeonShooting_Godot/editor/src/CodeHintManager.cs
@@ -0,0 +1,87 @@
+using System.Text.RegularExpressions;
+using Godot;
+
+namespace DScript.GodotEditor
+{
+ ///
+ /// 代码提示管理类
+ ///
+ public static class CodeHintManager
+ {
+ ///
+ /// 是否使用 enter 输入过代码
+ ///
+ internal static bool EnterInput = false;
+
+ ///
+ /// 按下快捷键 ctrl + / 触发显示提示面板
+ ///
+ [EditorShortcutKey(KeyList.Slash, Ctrl = true)]
+ private static void TriggerInput()
+ {
+ var textEditor = CodeTextEdit.CurrentTextEdit;
+ if (textEditor != null && textEditor.HasFocus())
+ {
+ RequestSyntaxTree(textEditor);
+ }
+ }
+
+ ///
+ /// 触发编辑器输入
+ ///
+ /// 当前活动的编辑器
+ public static void TriggerInput(CodeTextEdit textEdit)
+ {
+ var column = textEdit.CursorGetColumn();
+ if (column > 0)
+ {
+ var line = textEdit.CursorGetLine();
+ var str = textEdit.GetTextInRange(line, column - 1, line, column);
+ //判断前一个字符串是否能触发提示
+ if (Regex.IsMatch(str, "[\\.\\w]"))
+ {
+ RequestSyntaxTree(textEdit);
+ }
+ }
+ }
+
+ ///
+ /// 结束输入, 关闭提示弹窗
+ ///
+ public static void OverInput()
+ {
+ CodeHintPanel.Instance.HidePanel();
+ }
+
+ ///
+ /// 返回提示面板是否显示
+ ///
+ public static bool IsShowPanel()
+ {
+ return CodeHintPanel.Instance.Visible;
+ }
+
+ ///
+ /// 显示提示面板
+ ///
+ private static void ShowPanel(CodeTextEdit textEdit)
+ {
+ //先确定面板位置
+ var line = textEdit.CursorGetLine();
+ var column = textEdit.CursorGetColumn();
+
+ Vector2 pos =
+ textEdit.EditPainter.ToPainterPosition(
+ textEdit.GetPosAtLineColumn(line, column == 0 ? 0 : (column - 1)));
+ CodeHintPanel.Instance.ShowPanel(textEdit, pos);
+ }
+
+ ///
+ /// 请求语法树, 结合上下文, 判断是否能弹出
+ ///
+ private static void RequestSyntaxTree(CodeTextEdit textEdit)
+ {
+ ShowPanel(textEdit);
+ }
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/editor/src/CodeHintPanel.cs b/DungeonShooting_Godot/editor/src/CodeHintPanel.cs
index 69ec1a6..f8d7f0f 100644
--- a/DungeonShooting_Godot/editor/src/CodeHintPanel.cs
+++ b/DungeonShooting_Godot/editor/src/CodeHintPanel.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using Godot;
namespace DScript.GodotEditor
@@ -39,7 +40,9 @@
private bool _continuousFlag = false;
//当前的文本编辑器对象
- private TextEdit _textEdit;
+ private CodeTextEdit _textEdit;
+ private int startLine;
+ private int startcColumn;
public CodeHintPanel()
{
@@ -51,10 +54,10 @@
_scrollContainer = GetNode("ScrollContainer");
_itemContainer = _scrollContainer.GetNode("VBoxContainer");
- for (int i = 0; i < CodeTextEditor.KeyCodes.Length; i++)
+ for (int i = 0; i < CodeTextEdit.KeyCodes.Length; i++)
{
var item = CreateItem();
- item.CodeText = CodeTextEditor.KeyCodes[i];
+ item.CodeText = CodeTextEdit.KeyCodes[i];
}
}
@@ -76,10 +79,10 @@
if (down || up)
{
_clickTimer += delta;
- if ((!_continuousFlag && _clickTimer > 0.5f) || (_continuousFlag && _clickTimer > 0.1f))
+ if ((!_continuousFlag && _clickTimer > 0.5f) || (_continuousFlag && _clickTimer > 0.06f))
{
_continuousFlag = true;
- _clickTimer = 0;
+ _clickTimer %= 0.06f;
clickFlag = true;
}
}
@@ -112,11 +115,27 @@
ActiveIndex = index;
}
-
- //确认输入
- if (Input.IsKeyPressed((int)KeyList.Enter))
+ }
+
+ public override void _Input(InputEvent @event)
+ {
+ if (!Visible) return;
+ if (@event is InputEventKey eventKey)
{
- ConfirmInput(ActiveIndex);
+ if (eventKey.IsPressed())
+ {
+ //按下左,右,空格时隐藏提示框
+ if (eventKey.Scancode == (int)KeyList.Left || eventKey.Scancode == (int)KeyList.Right ||
+ eventKey.Scancode == (int)KeyList.Space)
+ {
+ HidePanel();
+ }
+ //按下 enter 或者 tab 确认输入
+ else if (eventKey.Scancode == (int)KeyList.Enter || eventKey.Scancode == (int)KeyList.Tab)
+ {
+ ConfirmInput(ActiveIndex);
+ }
+ }
}
}
@@ -127,22 +146,45 @@
{
if (index >= 0 && _activeItemList.Count > 0 && index < _activeItemList.Count && _textEdit != null)
{
- _textEdit.InsertTextAtCursor(_activeItemList[index].CodeText);
+ var line = _textEdit.CursorGetLine();
+ var column = _textEdit.CursorGetColumn();
+ var lineStr = _textEdit.GetLine(line);
+
+ var beforeStr = lineStr.Substring(0, column);
+
+ var result = Regex.Match(beforeStr, "[\\w]+$");
+ if (result.Success)
+ {
+ var text = _activeItemList[index].CodeText;
+ lineStr = beforeStr.Substring(0,
+ result.Index) + text + lineStr.Substring(column);
+ _textEdit.SetLine(line, lineStr);
+ _textEdit.CursorSetColumn(result.Index + text.Length);
+ _textEdit.TriggerTextChanged();
+ }
+ else
+ {
+ _textEdit.InsertTextAtCursor(_activeItemList[index].CodeText);
+ }
}
+
Hide();
+ CodeHintManager.EnterInput = true;
}
-
+
///
/// 显示提示面板
///
- public void ShowPanel(TextEdit textEdit, Vector2 pos)
+ public void ShowPanel(CodeTextEdit textEdit, Vector2 pos)
{
_textEdit = textEdit;
RectPosition = pos;
if (!Visible)
{
+ GD.Print("call ShowPanel()");
Popup_();
- GD.Print(_textEdit.GetWordUnderCursor());
+ _textEdit.GrabFocus();
+ ActiveIndex = 0;
}
}
@@ -151,6 +193,7 @@
///
public void HidePanel()
{
+ GD.Print("call HidePanel()");
Hide();
_textEdit = null;
}
@@ -174,7 +217,7 @@
var item = _activeItemList[index];
item.SetActive(true);
- //矫正滑动组件滑y轴值, 使其选中项不会跑到视野外
+ //矫正滑动组件y轴值, 使其选中项不会跑到视野外
var vertical = _scrollContainer.ScrollVertical;
var scrollSize = _scrollContainer.GetVScrollbar().RectSize;
var itemPos = item.RectPosition;
diff --git a/DungeonShooting_Godot/editor/src/CodePanel.cs b/DungeonShooting_Godot/editor/src/CodePanel.cs
index 0202a55..e7db0f8 100644
--- a/DungeonShooting_Godot/editor/src/CodePanel.cs
+++ b/DungeonShooting_Godot/editor/src/CodePanel.cs
@@ -14,19 +14,19 @@
//绘制组件
private TextEditPainter _editPainter;
//文本编辑节点
- private CodeTextEditor _codeTextEditor;
+ private CodeTextEdit _codeTextEdit;
public override void _Ready()
{
- _codeTextEditor = GetNode("ScalePanel/TextEdit");
- _editPainter = _codeTextEditor.GetNode("TextEditPainter");
+ _codeTextEdit = GetNode("ScalePanel/TextEdit");
+ _editPainter = _codeTextEdit.GetNode("TextEditPainter");
_scalePanel = GetNode("ScalePanel");
StartScale = _scalePanel.RectScale;
_editPainter.SetIdePanel(this);
- _editPainter.SetTextEdit(_codeTextEditor);
+ _editPainter.SetTextEdit(_codeTextEdit);
//刷新大小
_on_ScalePanel_resized();
diff --git a/DungeonShooting_Godot/editor/src/CodeTextEdit.cs b/DungeonShooting_Godot/editor/src/CodeTextEdit.cs
new file mode 100644
index 0000000..93ee9fd
--- /dev/null
+++ b/DungeonShooting_Godot/editor/src/CodeTextEdit.cs
@@ -0,0 +1,206 @@
+using Godot;
+using File = System.IO.File;
+
+namespace DScript.GodotEditor
+{
+ public class CodeTextEdit : TextEdit
+ {
+ ///
+ /// 获取当前的文本编辑器
+ ///
+ public static CodeTextEdit CurrentTextEdit { get; private set; }
+
+ ///
+ /// 关键字颜色
+ ///
+ 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编辑器中设置的
+
+ ///
+ /// 关键字列表
+ ///
+ public static readonly string[] KeyCodes =
+ {
+ "var",
+ "namespace",
+ "this",
+ "class",
+ "extends",
+ "func",
+ "get",
+ "set",
+ "import",
+ "static",
+ "new",
+ "return",
+ "for",
+ "switch",
+ "case",
+ "break",
+ "default",
+ "while",
+ "do",
+ "is",
+ "repeat",
+ "null",
+ "true",
+ "false",
+ "readonly",
+ "enum",
+ "private",
+ "super",
+ "if",
+ "else",
+ "continue",
+ "typeof"
+ };
+
+
+ private int prevTextLength = 0;
+
+ private readonly string[] autoCompeleteRight = { "{", "\"", "(", "[" };
+ private readonly string[] autoCompeleteLeft = { "}", "\"", ")", "]" };
+
+ //记录光标位置
+ private int _line;
+ private int _column;
+
+ ///
+ /// 字体大小
+ ///
+ public int FontSize { get; private set; } = 15;
+
+ ///
+ /// 绘制对象
+ ///
+ public TextEditPainter EditPainter { get; private set; }
+
+ public override void _Ready()
+ {
+ CurrentTextEdit = this;
+
+ EditPainter = GetNode("TextEditPainter");
+ //添加关键字
+ for (int i = 0; i < KeyCodes.Length; i++)
+ {
+ AddKeywordColor(KeyCodes[i], KeyCodeColor);
+ }
+
+ AddColorRegion("//", "", AnnotationColor, true);
+ AddColorRegion("/*", "*/", AnnotationColor);
+ AddColorRegion("\"", "\"", StringColor);
+
+ Text = File.ReadAllText("editor/example.ds");
+ ClearUndoHistory();
+ }
+
+ public override void _Process(float delta)
+ {
+ if (Input.IsMouseButtonPressed((int)ButtonList.Right))
+ {
+ //绘制报错行
+ EditPainter.DrawTextEditErrorLine(CursorGetLine());
+ }
+ }
+
+ ///
+ /// 刷新记录的字符串长度
+ ///
+ public void TriggerTextChanged()
+ {
+ EmitSignal("text_changed");
+ }
+
+ ///
+ /// 获取指定范围内的文本
+ ///
+ /// 起始行
+ /// 起始列
+ /// 结束行
+ /// 结束列
+ public string GetTextInRange(int startLine, int startColumn, int endLine, int endColumn)
+ {
+ var line = CursorGetLine();
+ var column = CursorGetColumn();
+ Select(startLine, startColumn, endLine, endColumn);
+ var key = GetSelectionText();
+ Select(line, column, line, column);
+ return key;
+ }
+
+ ///
+ /// 连接信号, 当文本改变时调用
+ ///
+ private void _on_TextEdit_text_changed()
+ {
+ var newLength = Text.Length;
+
+ // //括号补全
+ // if (newLength > prevTextLength)
+ // {
+ // var line = CursorGetLine();
+ // var column = CursorGetColumn();
+ // //前一个字符串
+ // var key = GetTextInRange(line, column - 1, line, column);
+ //
+ // for (int i = 0; i < autoCompeleteRight.Length; i++)
+ // {
+ // if (key == autoCompeleteRight[i])
+ // {
+ // InsertTextAtCursor(autoCompeleteLeft[i]);
+ // CursorSetColumn(CursorGetColumn() - 1);
+ // }
+ // }
+ // }
+
+ if (newLength < prevTextLength) //删除内容
+ {
+ if (CodeHintManager.IsShowPanel()) //提示面板打开
+ {
+ //关闭面板
+ CodeHintManager.OverInput();
+ }
+ }
+ else if (newLength > prevTextLength) //添加内容
+ {
+ if (CodeHintManager.EnterInput) //是否输入过换行
+ {
+ Undo();
+ CodeHintManager.EnterInput = false;
+ newLength -= 1;
+ }
+ else //触发输入
+ {
+ //触发输入
+ CodeHintManager.TriggerInput(this);
+ }
+ }
+
+ prevTextLength = newLength;
+ }
+
+ private void _on_TextEdit_cursor_changed()
+ {
+ if (CodeHintManager.IsShowPanel() && (Input.IsKeyPressed((int)KeyList.Up) ||
+ Input.IsKeyPressed((int)KeyList.Down)))
+ {
+ CursorSetLine(_line);
+ CursorSetColumn(_column);
+ }
+ else
+ {
+ //记录光标位置
+ _line = CursorGetLine();
+ _column = CursorGetColumn();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/editor/src/CodeTextEditor.cs b/DungeonShooting_Godot/editor/src/CodeTextEditor.cs
deleted file mode 100644
index d57a504..0000000
--- a/DungeonShooting_Godot/editor/src/CodeTextEditor.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-using Godot;
-using File = System.IO.File;
-
-namespace DScript.GodotEditor
-{
- 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编辑器中设置的
-
- ///
- /// 关键字列表
- ///
- public static readonly string[] KeyCodes =
- {
- "var",
- "namespace",
- "this",
- "class",
- "extends",
- "func",
- "get",
- "set",
- "import",
- "static",
- "new",
- "return",
- "for",
- "switch",
- "case",
- "break",
- "default",
- "while",
- "do",
- "is",
- "repeat",
- "null",
- "true",
- "false",
- "readonly",
- "enum",
- "private",
- "super",
- "if",
- "else",
- "continue",
- "typeof"
- };
-
-
- private int prevTextLength = 0;
-
- private readonly string[] autoCompeleteRight = { "{", "\"", "(", "[" };
- private readonly string[] autoCompeleteLeft = { "}", "\"", ")", "]" };
-
- ///
- /// 字体大小
- ///
- public int FontSize { get; private set; } = 15;
-
- private TextEditPainter _editPainter;
-
- public override void _Ready()
- {
- _editPainter = GetNode("TextEditPainter");
- //添加关键字
- for (int i = 0; i < KeyCodes.Length; i++)
- {
- AddKeywordColor(KeyCodes[i], KeyCodeColor);
- }
-
- AddColorRegion("//", "", AnnotationColor, true);
- AddColorRegion("/*", "*/", AnnotationColor);
- AddColorRegion("\"", "\"", StringColor);
-
- Text = File.ReadAllText("editor/example.ds");
- ClearUndoHistory();
- }
-
- public override void _Process(float delta)
- {
- if (Input.IsMouseButtonPressed((int)ButtonList.Right))
- {
- //绘制报错行
- _editPainter.DrawTextEditErrorLine(CursorGetLine());
- var pos = _editPainter.ToPainterPosition(GetPosAtLineColumn(CursorGetLine(), 0));
- //弹出提示面板
- CodeHintPanel.Instance.ShowPanel(this, pos);
- //选中第一项
- CodeHintPanel.Instance.ActiveIndex = 0;
- }
- }
-
- ///
- /// 连接信号, 当文本改变时调用
- ///
- private void _on_TextEdit_text_changed()
- {
- var newLength = Text.Length;
- if (newLength != prevTextLength)
- {
- //括号补全
- if (newLength > prevTextLength)
- {
- var line = CursorGetLine();
- var column = CursorGetColumn();
- Select(line, column - 1, line, column);
- var key = GetSelectionText();
- Select(line, column, line, column);
-
- for (int i = 0; i < autoCompeleteRight.Length; i++)
- {
- if (key == autoCompeleteRight[i])
- {
- InsertTextAtCursor(autoCompeleteLeft[i]);
- CursorSetColumn(CursorGetColumn() - 1);
- }
- }
- }
- }
-
- prevTextLength = newLength;
- }
- }
-}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/editor/src/Editor.cs b/DungeonShooting_Godot/editor/src/Editor.cs
new file mode 100644
index 0000000..314e348
--- /dev/null
+++ b/DungeonShooting_Godot/editor/src/Editor.cs
@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using Godot;
+
+namespace DScript.GodotEditor
+{
+ ///
+ /// 编辑器类
+ ///
+ public class Editor : Control
+ {
+
+ private class ShortcutKeyData
+ {
+ public int key;
+ public bool ctrl;
+ public bool shift;
+ public bool alt;
+ public MethodInfo methodInfo;
+ public bool isPressed;
+ }
+
+ ///
+ /// 获取编辑器实例
+ ///
+ public static Editor Instance => _instance;
+
+ private static Editor _instance;
+
+ private List _shortcutKeyMethods = new List();
+
+ public Editor()
+ {
+ _instance = this;
+ }
+
+ public override void _Ready()
+ {
+ ScannerAssembly();
+ }
+
+ public override void _Process(float delta)
+ {
+ if (Input.IsKeyPressed((int)KeyList.Control))
+ {
+
+ }
+ }
+
+ public override void _Input(InputEvent @event)
+ {
+ if (!Visible)
+ {
+ return;
+ }
+
+ if (@event is InputEventKey eventKey)
+ {
+ uint key = eventKey.Scancode;
+ //检测快捷键
+ if (key != (int)KeyList.Control && key != (int)KeyList.Shift && key != (int)KeyList.Alt)
+ {
+ for (int i = 0; i < _shortcutKeyMethods.Count; i++)
+ {
+ var item = _shortcutKeyMethods[i];
+ var flag = key == item.key && eventKey.Pressed && item.ctrl == eventKey.Control &&
+ item.shift == eventKey.Shift && item.alt == eventKey.Alt;
+ if (flag)
+ {
+ //触发快捷键调用
+ if (!item.isPressed)
+ {
+ item.isPressed = true;
+ item.methodInfo.Invoke(null, new object[0]);
+ }
+ }
+ else
+ {
+ item.isPressed = false;
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// 扫描程序集, 并完成注册标记
+ ///
+ private void ScannerAssembly()
+ {
+ var types = GetType().Assembly.GetTypes();
+ foreach (var type in types)
+ {
+ if (type.Namespace == null || !type.Namespace.StartsWith("DScript.GodotEditor")) continue;
+ MethodInfo[] methods =
+ type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
+ foreach (var method in methods)
+ {
+ Attribute mAttribute;
+ //快捷键注册
+ if ((mAttribute = Attribute.GetCustomAttribute(method, typeof(EditorShortcutKey), false)) !=
+ null)
+ {
+ var att = (EditorShortcutKey)mAttribute;
+ var data = new ShortcutKeyData();
+ data.key = (int)att.Key;
+ data.methodInfo = method;
+ data.shift = att.Shift;
+ data.ctrl = att.Ctrl;
+ data.alt = att.Alt;
+ _shortcutKeyMethods.Add(data);
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/editor/src/EditorShortcutKey.cs b/DungeonShooting_Godot/editor/src/EditorShortcutKey.cs
new file mode 100644
index 0000000..c3592dc
--- /dev/null
+++ b/DungeonShooting_Godot/editor/src/EditorShortcutKey.cs
@@ -0,0 +1,37 @@
+using System;
+using Godot;
+
+namespace DScript.GodotEditor
+{
+ ///
+ /// 用在静态函数上, 当按下指定键位后调用函数, 仅在 DScript.GodotEditor 命名空间下生效
+ ///
+ [AttributeUsage(AttributeTargets.Method)]
+ public class EditorShortcutKey : Attribute
+ {
+ ///
+ /// 绑定的快捷键
+ ///
+ public KeyList Key;
+
+ ///
+ /// 是否检测 Ctrl
+ ///
+ public bool Ctrl = false;
+
+ ///
+ /// 是否检测 Shift
+ ///
+ public bool Shift = false;
+
+ ///
+ /// 是否检测 Alt
+ ///
+ public bool Alt = false;
+
+ public EditorShortcutKey(KeyList key)
+ {
+ Key = key;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/editor/src/TextEditPainter.cs b/DungeonShooting_Godot/editor/src/TextEditPainter.cs
index 3e9eb61..f0b0642 100644
--- a/DungeonShooting_Godot/editor/src/TextEditPainter.cs
+++ b/DungeonShooting_Godot/editor/src/TextEditPainter.cs
@@ -19,7 +19,7 @@
///
/// 设置文本编辑器
///
- public void SetTextEdit(CodeTextEditor textEdit)
+ public void SetTextEdit(CodeTextEdit textEdit)
{
_textEdit = textEdit;
}
diff --git a/DungeonShooting_Godot/scene/Main.tscn b/DungeonShooting_Godot/scene/Main.tscn
index 7067b37..2fdc7dd 100644
--- a/DungeonShooting_Godot/scene/Main.tscn
+++ b/DungeonShooting_Godot/scene/Main.tscn
@@ -1,16 +1,9 @@
-[gd_scene load_steps=3 format=2]
+[gd_scene load_steps=2 format=2]
-[ext_resource path="res://editor/prefabs/CodePanel.tscn" type="PackedScene" id=1]
-[ext_resource path="res://editor/prefabs/CodeHintPanel.tscn" type="PackedScene" id=2]
+[ext_resource path="res://editor/prefabs/Editor.tscn" type="PackedScene" id=1]
[node name="Main" type="Node2D"]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
-[node name="CodePanel" parent="CanvasLayer" instance=ExtResource( 1 )]
-
-[node name="CodeHintPanel" parent="CanvasLayer" instance=ExtResource( 2 )]
-margin_left = 200.0
-margin_top = 135.0
-margin_right = 473.0
-margin_bottom = 265.0
+[node name="Editor" parent="CanvasLayer" instance=ExtResource( 1 )]
diff --git a/DungeonShooting_Godot/src/game/manager/GameManager.cs b/DungeonShooting_Godot/src/game/manager/GameManager.cs
index 48a9d2b..87b3571 100644
--- a/DungeonShooting_Godot/src/game/manager/GameManager.cs
+++ b/DungeonShooting_Godot/src/game/manager/GameManager.cs
@@ -9,7 +9,7 @@
public GameManager()
{
- GameManager.Instance = this;
+ Instance = this;
//扫描并注册当前程序集下的武器
WeaponManager.RegisterWeaponFromAssembly(GetType().Assembly);