Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix script popup #286

Merged
merged 7 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions addons/block_code/block_code_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 22 additions & 2 deletions addons/block_code/ui/script_window/script_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,31 @@ extends Window

var script_content: String = ""

@onready var script_label: TextEdit = $Margin/VBox/ColorRect/Scroll/Margin/Code
@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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

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)
Comment on lines +24 to +25
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good finding, I didn't know the read-only was doing that. Thanks for digging the sourcecode.



func _ready():
popup_centered()
_apply_editor_syntax_highlighter()
_remove_font_color_alpha_clamp()
script_label.text = script_content.replace("\t", " ")


Expand Down
45 changes: 18 additions & 27 deletions addons/block_code/ui/script_window/script_window.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -35,50 +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="CodeEdit" 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_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")
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"]