-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.gd
46 lines (32 loc) · 1.33 KB
/
plugin.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
tool
extends EditorPlugin
const ImageEditor = preload("res://addons/godot-image-editor-plugin/ImageEditor.tscn")
var _image_editor_root = null
func _enter_tree():
var editor_interface = get_editor_interface()
var editor_inspector = editor_interface.get_inspector()
editor_inspector.connect("resource_selected", self, "_on_resource_selected")
var editor_selection = editor_interface.get_selection()
editor_selection.connect("selection_changed", self, "_on_selection_changed")
func _exit_tree():
_close_image_editor()
func _open_image_editor(image_texture):
if _image_editor_root != null:
_close_image_editor()
_image_editor_root = ImageEditor.instance()
_image_editor_root.image_texture = image_texture
_image_editor_root.is_standalone = false
add_control_to_bottom_panel(_image_editor_root, "Image Editor")
func _close_image_editor():
if _image_editor_root == null:
return
remove_control_from_bottom_panel(_image_editor_root)
# TODO: make sure we don't need to free
_image_editor_root = null
func _on_resource_selected(resource, _property):
"""triggered when "Edit" pressed on resource - opens resource in inspector"""
if resource is ImageTexture:
_open_image_editor(resource)
func _on_selection_changed():
"""triggered when node(s) selected in Editor's SceneTree - opens something else in inspector"""
_close_image_editor()