diff --git a/addons/dialog_plugin/Editor/EditorMainNode.gd b/addons/dialog_plugin/Editor/EditorMainNode.gd index 3707a33a..ad8ad9a8 100644 --- a/addons/dialog_plugin/Editor/EditorMainNode.gd +++ b/addons/dialog_plugin/Editor/EditorMainNode.gd @@ -12,10 +12,6 @@ func _ready() -> void: instance_editor_scene() -func _draw() -> void: - if visible: - instance_editor_scene() - func scan_resources() -> void: DialogDB.Timelines.get_database().scan_resources_folder() DialogDB.Characters.get_database().scan_resources_folder() diff --git a/addons/dialog_plugin/Editor/EditorView.gd b/addons/dialog_plugin/Editor/EditorView.gd index 673068b7..f5afd796 100644 --- a/addons/dialog_plugin/Editor/EditorView.gd +++ b/addons/dialog_plugin/Editor/EditorView.gd @@ -31,3 +31,7 @@ func _on_ToolBar_timeline_selected(timeline) -> void: _editor_view = TimelineEditorScene.instance() _editor_view.base_resource = timeline $ViewContainer.add_child(_editor_view) + +func _exit_tree() -> void: + if _editor_view and is_instance_valid(_editor_view): + _editor_view.free() diff --git a/addons/dialog_plugin/Other/translation_service/translation_inspector.gd b/addons/dialog_plugin/Other/translation_service/translation_inspector.gd index 3ec74fe1..26d798cb 100644 --- a/addons/dialog_plugin/Other/translation_service/translation_inspector.gd +++ b/addons/dialog_plugin/Other/translation_service/translation_inspector.gd @@ -1,27 +1,36 @@ -tool +#tool extends EditorInspectorPlugin -const BaseMetaEditorScene = preload("res://addons/dialog_plugin/Other/translation_service/editor_node/base_meta_editor.tscn") -const TextMetaEditorScene = preload("res://addons/dialog_plugin/Other/translation_service/editor_node/text_node/text_meta_editor.tscn") +var BaseMetaEditorScene = load("res://addons/dialog_plugin/Other/translation_service/editor_node/base_meta_editor.tscn") +var TextMetaEditorScene = load("res://addons/dialog_plugin/Other/translation_service/editor_node/text_node/text_meta_editor.tscn") var modified_object = null +var _control = null func parse_begin(object: Object) -> void: if object is Control: modified_object = object + func can_handle(object: Object) -> bool: if object is Control: return true return false + func parse_end() -> void: if modified_object: - var _control + if _control and is_instance_valid(_control): + print("Control existed before calling parse end") + _control.free() + _control = null + if "text" in modified_object: _control = TextMetaEditorScene.instance() + pass else: _control = BaseMetaEditorScene.instance() + pass _control.BaseNode = modified_object add_custom_control(_control) @@ -30,4 +39,7 @@ func _notification(what:int) -> void: if what == NOTIFICATION_PREDELETE: if modified_object: modified_object = null + if _control and is_instance_valid(_control): + _control.free() + _control = null diff --git a/addons/dialog_plugin/Other/translation_service/translation_service.gd b/addons/dialog_plugin/Other/translation_service/translation_service.gd index f253bbc9..635d752c 100644 --- a/addons/dialog_plugin/Other/translation_service/translation_service.gd +++ b/addons/dialog_plugin/Other/translation_service/translation_service.gd @@ -69,7 +69,9 @@ static func get_editor_locale() -> String: var _locale = "en" if Engine.editor_hint: - _locale = EditorPlugin.new().get_editor_interface().get_editor_settings().get_setting("interface/editor/editor_language") + var _editor_plugin = EditorPlugin.new() + _locale = _editor_plugin.get_editor_interface().get_editor_settings().get_setting("interface/editor/editor_language") + _editor_plugin.free() else: # Just if someone try to get the editor locale in game for some reason _locale = TranslationServer.get_locale() diff --git a/addons/dialog_plugin/plugin_script.gd b/addons/dialog_plugin/plugin_script.gd index 53fdf2e4..1dd49a60 100644 --- a/addons/dialog_plugin/plugin_script.gd +++ b/addons/dialog_plugin/plugin_script.gd @@ -1,6 +1,7 @@ tool extends EditorPlugin +const PLUGIN_NAME = "Dialog Editor" const DialogResources = preload("res://addons/dialog_plugin/Core/DialogResources.gd") const EditorView_Scene = preload("res://addons/dialog_plugin/Editor/EditorMainNode.tscn") const Dialog_i18n = preload("res://addons/dialog_plugin/Core/Dialog_i18n.gd") @@ -15,11 +16,10 @@ func _enter_tree() -> void: DialogResources.verify_resource_directories() _add_editor_translations() - _editor_view = EditorView_Scene.instance() + var _err = connect("main_screen_changed", self, "_on_main_screen_changed") -# _add_editor_inspector_plugins() - get_editor_interface().get_editor_viewport().add_child(_editor_view) + _add_editor_inspector_plugins() make_visible(false) @@ -31,10 +31,7 @@ func _ready() -> void: func _exit_tree() -> void: - if _editor_view: - _editor_view.queue_free() - _editor_view = null - + _remove_main_editor() _remove_editor_inspector_plugins() _remove_editor_translations() @@ -45,7 +42,7 @@ func has_main_screen() -> bool: func get_plugin_name() -> String: - return "Dialog Editor" + return PLUGIN_NAME # Copied @@ -73,6 +70,8 @@ func _remove_editor_inspector_plugins() -> void: remove_inspector_plugin(_parts_inspector) if _translation_inspector: remove_inspector_plugin(_translation_inspector) + # For some reason that i don't know, i have to force an unreference to this object + _translation_inspector.unreference() _parts_inspector = null _translation_inspector = null @@ -85,5 +84,22 @@ func _add_editor_translations() -> void: func _remove_editor_translations() -> void: Dialog_i18n.remove_editor_translations() - _editor_view = null + + +func _add_main_editor() -> void: + _editor_view = EditorView_Scene.instance() + get_editor_interface().get_editor_viewport().add_child(_editor_view) pass + + +func _remove_main_editor() -> void: + if _editor_view and is_instance_valid(_editor_view): + _editor_view.free() + _editor_view = null + + +func _on_main_screen_changed(screen_name:String) -> void: + if screen_name == PLUGIN_NAME: + _add_main_editor() + else: + _remove_main_editor()