From 6713e0fa5ba9adf2ae7356bd945231e311449efe Mon Sep 17 00:00:00 2001 From: Yuri Rubinsky Date: Mon, 23 Jan 2023 12:01:28 +0300 Subject: Add handling of script creation/deletion for custom visual shader nodes --- doc/classes/FileSystemDock.xml | 5 + editor/dependency_editor.cpp | 12 +- editor/filesystem_dock.cpp | 6 + editor/filesystem_dock.h | 1 + editor/plugins/visual_shader_editor_plugin.cpp | 187 +++++++++++++++++++------ editor/plugins/visual_shader_editor_plugin.h | 11 +- 6 files changed, 176 insertions(+), 46 deletions(-) diff --git a/doc/classes/FileSystemDock.xml b/doc/classes/FileSystemDock.xml index 00f5c7ddff..f76bc2c279 100644 --- a/doc/classes/FileSystemDock.xml +++ b/doc/classes/FileSystemDock.xml @@ -51,5 +51,10 @@ + + + + + diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index a925e2d1d3..c98ec7b2d5 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -536,12 +536,17 @@ void DependencyRemoveDialog::show(const Vector &p_folders, const Vector< } void DependencyRemoveDialog::ok_pressed() { - for (int i = 0; i < files_to_delete.size(); ++i) { - if (ResourceCache::has(files_to_delete[i])) { - Ref res = ResourceCache::get_ref(files_to_delete[i]); + for (const KeyValue &E : all_remove_files) { + String file = E.key; + + if (ResourceCache::has(file)) { + Ref res = ResourceCache::get_ref(file); + emit_signal(SNAME("resource_removed"), res); res->set_path(""); } + } + for (int i = 0; i < files_to_delete.size(); ++i) { // If the file we are deleting for e.g. the main scene, default environment, // or audio bus layout, we must clear its definition in Project Settings. if (files_to_delete[i] == String(GLOBAL_GET("application/config/icon"))) { @@ -621,6 +626,7 @@ void DependencyRemoveDialog::ok_pressed() { } void DependencyRemoveDialog::_bind_methods() { + ADD_SIGNAL(MethodInfo("resource_removed", PropertyInfo(Variant::OBJECT, "obj"))); ADD_SIGNAL(MethodInfo("file_removed", PropertyInfo(Variant::STRING, "file"))); ADD_SIGNAL(MethodInfo("folder_removed", PropertyInfo(Variant::STRING, "folder"))); } diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index f41792af7f..70a6ded690 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1531,6 +1531,10 @@ void FileSystemDock::_make_scene_confirm() { EditorNode::get_singleton()->save_scene_list({ scene_path }); } +void FileSystemDock::_resource_removed(const Ref &p_resource) { + emit_signal(SNAME("resource_removed"), p_resource); +} + void FileSystemDock::_file_removed(String p_file) { emit_signal(SNAME("file_removed"), p_file); @@ -3077,6 +3081,7 @@ void FileSystemDock::_bind_methods() { ADD_SIGNAL(MethodInfo("inherit", PropertyInfo(Variant::STRING, "file"))); ADD_SIGNAL(MethodInfo("instantiate", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"))); + ADD_SIGNAL(MethodInfo("resource_removed", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); ADD_SIGNAL(MethodInfo("file_removed", PropertyInfo(Variant::STRING, "file"))); ADD_SIGNAL(MethodInfo("folder_removed", PropertyInfo(Variant::STRING, "folder"))); ADD_SIGNAL(MethodInfo("files_moved", PropertyInfo(Variant::STRING, "old_file"), PropertyInfo(Variant::STRING, "new_file"))); @@ -3235,6 +3240,7 @@ FileSystemDock::FileSystemDock() { add_child(owners_editor); remove_dialog = memnew(DependencyRemoveDialog); + remove_dialog->connect("resource_removed", callable_mp(this, &FileSystemDock::_resource_removed)); remove_dialog->connect("file_removed", callable_mp(this, &FileSystemDock::_file_removed)); remove_dialog->connect("folder_removed", callable_mp(this, &FileSystemDock::_folder_removed)); add_child(remove_dialog); diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 3f12b73043..08fb63dfe4 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -227,6 +227,7 @@ private: void _update_favorites_list_after_move(const HashMap &p_files_renames, const HashMap &p_folders_renames) const; void _update_project_settings_after_move(const HashMap &p_renames) const; + void _resource_removed(const Ref &p_resource); void _file_removed(String p_file); void _folder_removed(String p_folder); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 96b1ad7ee0..dc19870f70 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -40,6 +40,7 @@ #include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" +#include "editor/filesystem_dock.h" #include "editor/inspector_dock.h" #include "editor/plugins/curve_editor_plugin.h" #include "editor/plugins/shader_editor_plugin.h" @@ -1271,18 +1272,55 @@ Dictionary VisualShaderEditor::get_custom_node_data(Ref return dict; } -void VisualShaderEditor::update_custom_type(const Ref &p_resource) { - Ref