diff --git a/DungeonShooting_Godot/editor/ide_cn_font_12.tres b/DungeonShooting_Godot/editor/ide_cn_font_12.tres new file mode 100644 index 0000000..60ada92 --- /dev/null +++ b/DungeonShooting_Godot/editor/ide_cn_font_12.tres @@ -0,0 +1,11 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[ext_resource path="res://SourceHanSerifCN-SemiBold.otf" type="DynamicFontData" id=1] + +[resource] +size = 12 +use_mipmaps = true +use_filter = true +extra_spacing_char = 1 +extra_spacing_space = 2 +font_data = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/editor/ide_cn_font_12_hint.tres b/DungeonShooting_Godot/editor/ide_cn_font_12_hint.tres new file mode 100644 index 0000000..37d6b04 --- /dev/null +++ b/DungeonShooting_Godot/editor/ide_cn_font_12_hint.tres @@ -0,0 +1,10 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[ext_resource path="res://SourceHanSerifCN-SemiBold.otf" type="DynamicFontData" id=1] + +[resource] +size = 12 +use_mipmaps = true +use_filter = true +extra_spacing_space = 2 +font_data = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/editor/ide_cn_font_6.tres b/DungeonShooting_Godot/editor/ide_cn_font_6.tres deleted file mode 100644 index 60ada92..0000000 --- a/DungeonShooting_Godot/editor/ide_cn_font_6.tres +++ /dev/null @@ -1,11 +0,0 @@ -[gd_resource type="DynamicFont" load_steps=2 format=2] - -[ext_resource path="res://SourceHanSerifCN-SemiBold.otf" type="DynamicFontData" id=1] - -[resource] -size = 12 -use_mipmaps = true -use_filter = true -extra_spacing_char = 1 -extra_spacing_space = 2 -font_data = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/editor/prefabs/CodeHintItem.tscn b/DungeonShooting_Godot/editor/prefabs/CodeHintItem.tscn index 83874f2..cbad202 100644 --- a/DungeonShooting_Godot/editor/prefabs/CodeHintItem.tscn +++ b/DungeonShooting_Godot/editor/prefabs/CodeHintItem.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=6 format=2] [ext_resource path="res://editor/src/CodeHintItem.cs" type="Script" id=1] -[ext_resource path="res://editor/ide_cn_font_6.tres" type="DynamicFont" id=2] +[ext_resource path="res://editor/ide_cn_font_12_hint.tres" type="DynamicFont" id=2] [ext_resource path="res://addons/dungeonShooting_plugin/ActivityObject.svg" type="Texture" id=3] [sub_resource type="StyleBoxFlat" id=3] diff --git a/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn b/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn index 423ae3a..7702389 100644 --- a/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn +++ b/DungeonShooting_Godot/editor/prefabs/CodePanel.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=2] [ext_resource path="res://editor/src/CodeTextEditor.cs" type="Script" id=1] -[ext_resource path="res://editor/ide_cn_font_6.tres" type="DynamicFont" id=2] +[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] diff --git a/DungeonShooting_Godot/editor/src/CodeHintItem.cs b/DungeonShooting_Godot/editor/src/CodeHintItem.cs index b7b3fff..0aa4dde 100644 --- a/DungeonShooting_Godot/editor/src/CodeHintItem.cs +++ b/DungeonShooting_Godot/editor/src/CodeHintItem.cs @@ -83,7 +83,7 @@ //点击时调用 private void _on_click() { - CodeHintPanel.Instance.ActiveIndex = Index; + CodeHintPanel.Instance.ConfirmInput(Index); } } } diff --git a/DungeonShooting_Godot/editor/src/CodeHintPanel.cs b/DungeonShooting_Godot/editor/src/CodeHintPanel.cs index 9714550..69ec1a6 100644 --- a/DungeonShooting_Godot/editor/src/CodeHintPanel.cs +++ b/DungeonShooting_Godot/editor/src/CodeHintPanel.cs @@ -34,6 +34,13 @@ //当前已启用项的列表 private List _activeItemList = new List(); + //长按计时器 + private float _clickTimer = 0; + private bool _continuousFlag = false; + + //当前的文本编辑器对象 + private TextEdit _textEdit; + public CodeHintPanel() { Instance = this; @@ -44,16 +51,46 @@ _scrollContainer = GetNode("ScrollContainer"); _itemContainer = _scrollContainer.GetNode("VBoxContainer"); - for (int i = 0; i < 20; i++) + for (int i = 0; i < CodeTextEditor.KeyCodes.Length; i++) { var item = CreateItem(); - item.CodeText = i.ToString(); + item.CodeText = CodeTextEditor.KeyCodes[i]; } } public override void _Process(float delta) { - if (Input.IsActionJustPressed("ui_down") && _activeItemList.Count > 1) //按下下键 + if (!Visible) return; + if (_textEdit == null) + { + Visible = false; + _textEdit = null; + return; + } + + //长按判定 + var down = Input.IsActionPressed("ui_down"); + var up = Input.IsActionPressed("ui_up"); + //是否触发选项移动 + bool clickFlag = false; + if (down || up) + { + _clickTimer += delta; + if ((!_continuousFlag && _clickTimer > 0.5f) || (_continuousFlag && _clickTimer > 0.1f)) + { + _continuousFlag = true; + _clickTimer = 0; + clickFlag = true; + } + } + else + { + _clickTimer = 0; + _continuousFlag = false; + } + + //选项移动判定 + if ((Input.IsActionJustPressed("ui_down") || (clickFlag && down)) && _activeItemList.Count > 1) //按下下键 { var index = ActiveIndex; index += 1; @@ -62,9 +99,9 @@ index = 0; } - ActiveIndex = index; + ActiveIndex = index; } - else if (Input.IsActionJustPressed("ui_up") && _activeItemList.Count > 1) //按下上键 + else if ((Input.IsActionJustPressed("ui_up") || (clickFlag && up)) && _activeItemList.Count > 1) //按下上键 { var index = ActiveIndex; index -= 1; @@ -75,18 +112,50 @@ ActiveIndex = index; } + + //确认输入 + if (Input.IsKeyPressed((int)KeyList.Enter)) + { + ConfirmInput(ActiveIndex); + } } /// + /// 确认输入选中的项, 补全代码 + /// + internal void ConfirmInput(int index) + { + if (index >= 0 && _activeItemList.Count > 0 && index < _activeItemList.Count && _textEdit != null) + { + _textEdit.InsertTextAtCursor(_activeItemList[index].CodeText); + } + Hide(); + } + + /// /// 显示提示面板 /// - public void ShowPanel(Vector2 pos) + public void ShowPanel(TextEdit textEdit, Vector2 pos) { + _textEdit = textEdit; RectPosition = pos; - Popup_(); + if (!Visible) + { + Popup_(); + GD.Print(_textEdit.GetWordUnderCursor()); + } } /// + /// 隐藏面板 + /// + public void HidePanel() + { + Hide(); + _textEdit = null; + } + + /// /// 设置活动项 /// private void SetActiveIndex(int index) diff --git a/DungeonShooting_Godot/editor/src/CodeTextEditor.cs b/DungeonShooting_Godot/editor/src/CodeTextEditor.cs index 21dda1f..d57a504 100644 --- a/DungeonShooting_Godot/editor/src/CodeTextEditor.cs +++ b/DungeonShooting_Godot/editor/src/CodeTextEditor.cs @@ -22,7 +22,7 @@ /// /// 关键字列表 /// - private readonly string[] KeyCodes = + public static readonly string[] KeyCodes = { "var", "namespace", @@ -92,9 +92,13 @@ { if (Input.IsMouseButtonPressed((int)ButtonList.Right)) { + //绘制报错行 _editPainter.DrawTextEditErrorLine(CursorGetLine()); - CodeHintPanel.Instance.ShowPanel(_editPainter.ToPainterPosition(GetPosAtLineColumn(CursorGetLine(), 0))); - CodeHintPanel.Instance.ActiveIndex = 1; + var pos = _editPainter.ToPainterPosition(GetPosAtLineColumn(CursorGetLine(), 0)); + //弹出提示面板 + CodeHintPanel.Instance.ShowPanel(this, pos); + //选中第一项 + CodeHintPanel.Instance.ActiveIndex = 0; } }