From 5ba3c30a1729ea478351cc87dc43787612aa8016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Wed, 23 Oct 2024 10:02:47 -0300 Subject: [PATCH 1/7] Script Window: Use popup_dialog This is better because it considers the editor single window mode. --- addons/block_code/block_code_plugin.gd | 4 +--- addons/block_code/ui/script_window/script_window.gd | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/addons/block_code/block_code_plugin.gd b/addons/block_code/block_code_plugin.gd index 0067b7f2..9ced14ee 100644 --- a/addons/block_code/block_code_plugin.gd +++ b/addons/block_code/block_code_plugin.gd @@ -61,9 +61,7 @@ func _enter_tree(): func script_window_requested(script: String): var script_window = ScriptWindow.instantiate() script_window.script_content = script - - EditorInterface.get_base_control().add_child(script_window) - + EditorInterface.popup_dialog(script_window) await script_window.close_requested script_window.queue_free() diff --git a/addons/block_code/ui/script_window/script_window.gd b/addons/block_code/ui/script_window/script_window.gd index 77b09dd8..6fee30c1 100644 --- a/addons/block_code/ui/script_window/script_window.gd +++ b/addons/block_code/ui/script_window/script_window.gd @@ -7,7 +7,6 @@ var script_content: String = "" func _ready(): - popup_centered() script_label.text = script_content.replace("\t", " ") From 8288b9b2054182e174e23c71675c8c561192bbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Wed, 23 Oct 2024 10:08:16 -0300 Subject: [PATCH 2/7] Script Window: Remove background color The TextEdit control node had the background color hardcoded to black. --- addons/block_code/ui/script_window/script_window.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/block_code/ui/script_window/script_window.tscn b/addons/block_code/ui/script_window/script_window.tscn index b275d5cb..7031f116 100644 --- a/addons/block_code/ui/script_window/script_window.tscn +++ b/addons/block_code/ui/script_window/script_window.tscn @@ -4,6 +4,7 @@ [sub_resource type="SystemFont" id="SystemFont_r6ct2"] font_names = PackedStringArray("DejaVu Sans Mono") +subpixel_positioning = 0 [sub_resource type="CodeHighlighter" id="CodeHighlighter_yvmnf"] number_color = Color(0.498039, 0.760784, 0.686275, 1) @@ -76,7 +77,6 @@ theme_override_constants/margin_bottom = 35 [node name="Code" type="TextEdit" parent="Margin/VBox/ColorRect/Scroll/Margin"] layout_mode = 2 -theme_override_colors/background_color = Color(0.144063, 0.144063, 0.144062, 1) theme_override_fonts/font = SubResource("SystemFont_r6ct2") editable = false syntax_highlighter = SubResource("CodeHighlighter_yvmnf") From fc523e562c1a027935da17f4599a68b1317e4981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Wed, 23 Oct 2024 10:31:44 -0300 Subject: [PATCH 3/7] Script Window: Improve layout Remove black ColorRect node. Also remove the Scroll node because the TextEdit containing the script can scroll automatically. Add a PanelContainer and Panel node. And remove unneeded MarginContainer nodes. This makes the layout work as expected when resizing the window. Previously the controls didn't shrink correctly (overflowing below the window). --- .../ui/script_window/script_window.gd | 2 +- .../ui/script_window/script_window.tscn | 43 ++++++++----------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/addons/block_code/ui/script_window/script_window.gd b/addons/block_code/ui/script_window/script_window.gd index 6fee30c1..9c18275b 100644 --- a/addons/block_code/ui/script_window/script_window.gd +++ b/addons/block_code/ui/script_window/script_window.gd @@ -3,7 +3,7 @@ extends Window var script_content: String = "" -@onready var script_label: TextEdit = $Margin/VBox/ColorRect/Scroll/Margin/Code +@onready var script_label: TextEdit = %Code func _ready(): diff --git a/addons/block_code/ui/script_window/script_window.tscn b/addons/block_code/ui/script_window/script_window.tscn index 7031f116..cb8fb854 100644 --- a/addons/block_code/ui/script_window/script_window.tscn +++ b/addons/block_code/ui/script_window/script_window.tscn @@ -36,49 +36,40 @@ size = Vector2i(750, 750) transient = true script = ExtResource("1_jja22") -[node name="Margin" type="MarginContainer" parent="."] +[node name="PanelContainer" type="PanelContainer" parent="."] anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme_override_constants/margin_left = 25 -theme_override_constants/margin_top = 25 -theme_override_constants/margin_right = 25 -theme_override_constants/margin_bottom = 25 -[node name="VBox" type="VBoxContainer" parent="Margin"] +[node name="Panel" type="Panel" parent="PanelContainer"] layout_mode = 2 -[node name="CopyCode" type="Button" parent="Margin/VBox"] +[node name="VBox" type="VBoxContainer" parent="PanelContainer"] layout_mode = 2 -text = "Copy" -[node name="ColorRect" type="ColorRect" parent="Margin/VBox"] +[node name="Code" type="TextEdit" parent="PanelContainer/VBox"] +unique_name_in_owner = true layout_mode = 2 -size_flags_horizontal = 3 size_flags_vertical = 3 -color = Color(0.172833, 0.172833, 0.172833, 1) +theme_override_fonts/font = SubResource("SystemFont_r6ct2") +editable = false +syntax_highlighter = SubResource("CodeHighlighter_yvmnf") -[node name="Scroll" type="ScrollContainer" parent="Margin/VBox/ColorRect"] +[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBox"] layout_mode = 2 -offset_top = -27.0 -offset_right = 700.0 -offset_bottom = 673.0 -[node name="Margin" type="MarginContainer" parent="Margin/VBox/ColorRect/Scroll"] +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer/VBox/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 -size_flags_vertical = 3 -theme_override_constants/margin_left = 35 -theme_override_constants/margin_top = 55 -theme_override_constants/margin_right = 35 -theme_override_constants/margin_bottom = 35 +theme_override_constants/margin_left = 3 +theme_override_constants/margin_right = 3 +theme_override_constants/margin_bottom = 3 -[node name="Code" type="TextEdit" parent="Margin/VBox/ColorRect/Scroll/Margin"] +[node name="CopyCode" type="Button" parent="PanelContainer/VBox/HBoxContainer/MarginContainer"] layout_mode = 2 -theme_override_fonts/font = SubResource("SystemFont_r6ct2") -editable = false -syntax_highlighter = SubResource("CodeHighlighter_yvmnf") +size_flags_horizontal = 4 +text = "Copy" -[connection signal="pressed" from="Margin/VBox/CopyCode" to="." method="_on_copy_code_pressed"] +[connection signal="pressed" from="PanelContainer/VBox/HBoxContainer/MarginContainer/CopyCode" to="." method="_on_copy_code_pressed"] From 83b6cd28f0e32a0641fd1ab0ed70f52dedb4f0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Wed, 23 Oct 2024 11:22:20 -0300 Subject: [PATCH 4/7] Script Window: Change control type to CodeEdit Changing from TextEdit to CodeEdit shows a better background color, making it more readable. --- addons/block_code/ui/script_window/script_window.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/block_code/ui/script_window/script_window.tscn b/addons/block_code/ui/script_window/script_window.tscn index cb8fb854..0a72b48d 100644 --- a/addons/block_code/ui/script_window/script_window.tscn +++ b/addons/block_code/ui/script_window/script_window.tscn @@ -49,7 +49,7 @@ layout_mode = 2 [node name="VBox" type="VBoxContainer" parent="PanelContainer"] layout_mode = 2 -[node name="Code" type="TextEdit" parent="PanelContainer/VBox"] +[node name="Code" type="CodeEdit" parent="PanelContainer/VBox"] unique_name_in_owner = true layout_mode = 2 size_flags_vertical = 3 From b7568dbb45994f8080a5e47fd0ef981d2a970704 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 23 Oct 2024 16:14:21 +0100 Subject: [PATCH 5/7] fixup! Script Window: Change control type to CodeEdit --- addons/block_code/ui/script_window/script_window.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/block_code/ui/script_window/script_window.gd b/addons/block_code/ui/script_window/script_window.gd index 9c18275b..ae7c0005 100644 --- a/addons/block_code/ui/script_window/script_window.gd +++ b/addons/block_code/ui/script_window/script_window.gd @@ -3,7 +3,7 @@ extends Window var script_content: String = "" -@onready var script_label: TextEdit = %Code +@onready var script_label: CodeEdit = %Code func _ready(): From 527bc4b6f7b3090753e2b132ddb1503c9b6c3d32 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 23 Oct 2024 16:15:14 +0100 Subject: [PATCH 6/7] Script Window: Attempt to match editor's syntax highlighting If there is at least one script open in the editor, we can steal its syntax highlighter and apply it to the script window's CodeEdit control. Otherwise, we continue to use a built-in SyntaxHighlighter. --- addons/block_code/ui/script_window/script_window.gd | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/block_code/ui/script_window/script_window.gd b/addons/block_code/ui/script_window/script_window.gd index ae7c0005..413098f1 100644 --- a/addons/block_code/ui/script_window/script_window.gd +++ b/addons/block_code/ui/script_window/script_window.gd @@ -6,7 +6,20 @@ var script_content: String = "" @onready var script_label: CodeEdit = %Code +## Attempts to match the syntax highlighting for some open script in the +## editor, which is more likely to be appropriate for the editor theme +## than our hardcoded default +func _apply_editor_syntax_highlighter(): + var script_editor: ScriptEditor = EditorInterface.get_script_editor() + for x in script_editor.get_open_script_editors(): + var control: Control = x.get_base_editor() + if control is TextEdit: + script_label.syntax_highlighter = control.syntax_highlighter + break + + func _ready(): + _apply_editor_syntax_highlighter() script_label.text = script_content.replace("\t", " ") From 778c8d72e6a4f617208c7361696a583767c46606 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 23 Oct 2024 16:59:32 +0100 Subject: [PATCH 7/7] Script Window: Don't clamp font color alpha channel to 0.65 Because the CodeEdit's readonly property is set, TextEdit forces the alpha channel of all text rendered to be no higher than the alpha channel of the default colour for text in disabled controls, which is 0.65 as I type this. While we do not want the code in this popover to be editable, we do want it to be legible. Override the relevant font color on the control to set its alpha channel to 1, effectively disabling this undesired clamping. --- addons/block_code/ui/script_window/script_window.gd | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/block_code/ui/script_window/script_window.gd b/addons/block_code/ui/script_window/script_window.gd index 413098f1..6926e111 100644 --- a/addons/block_code/ui/script_window/script_window.gd +++ b/addons/block_code/ui/script_window/script_window.gd @@ -18,8 +18,16 @@ func _apply_editor_syntax_highlighter(): break +## Undoes the effect of the CodeEdit being read-only +func _remove_font_color_alpha_clamp(): + var font_readonly_color = script_label.get_theme_color("font_readonly_color") + font_readonly_color.a = 1 + script_label.add_theme_color_override("font_readonly_color", font_readonly_color) + + func _ready(): _apply_editor_syntax_highlighter() + _remove_font_color_alpha_clamp() script_label.text = script_content.replace("\t", " ")