diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-12-16 14:26:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-16 14:26:56 +0100 |
commit | 9df7ed59fb39e38db30326365adc18afb79903bb (patch) | |
tree | 59d2220e78fe5295dd6ac4aa5607da6501a96eb6 /editor | |
parent | 3914bdb82eafa558bc1512c7cf3c4f77565d0847 (diff) | |
parent | 065e2670af53ae2f71b78d57f8a217b4539cbbe2 (diff) |
Merge pull request #19501 from Zylann/custom_loaders
Added basic support for custom resource savers and loaders
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_file_system.cpp | 8 | ||||
-rw-r--r-- | editor/editor_node.cpp | 14 | ||||
-rw-r--r-- | editor/editor_node.h | 6 | ||||
-rw-r--r-- | editor/editor_plugin.cpp | 30 | ||||
-rw-r--r-- | editor/editor_plugin.h | 3 | ||||
-rw-r--r-- | editor/editor_plugin_settings.cpp | 2 |
6 files changed, 54 insertions, 9 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 94eb1a3399..37e2079b64 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1401,6 +1401,14 @@ void EditorFileSystem::update_script_classes() { ScriptServer::save_global_classes(); EditorNode::get_editor_data().script_class_save_icon_paths(); + + // Rescan custom loaders and savers. + // Doing the following here because the `filesystem_changed` signal fires multiple times and isn't always followed by script classes update. + // So I thought it's better to do this when script classes really get updated + ResourceLoader::remove_custom_loaders(); + ResourceLoader::add_custom_loaders(); + ResourceSaver::remove_custom_savers(); + ResourceSaver::add_custom_savers(); } void EditorFileSystem::_queue_update_script_classes() { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index d100d7f618..1063447376 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2471,7 +2471,7 @@ void EditorNode::_editor_select(int p_which) { } } -void EditorNode::add_editor_plugin(EditorPlugin *p_editor) { +void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) { if (p_editor->has_main_screen()) { @@ -2496,9 +2496,11 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor) { } singleton->editor_data.add_editor_plugin(p_editor); singleton->add_child(p_editor); + if (p_config_changed) + p_editor->enable_plugin(); } -void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) { +void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) { if (p_editor->has_main_screen()) { @@ -2521,6 +2523,8 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) { } p_editor->make_visible(false); p_editor->clear(); + if (p_config_changed) + p_editor->disable_plugin(); singleton->editor_plugins_over->get_plugins_list().erase(p_editor); singleton->remove_child(p_editor); singleton->editor_data.remove_editor_plugin(p_editor); @@ -2546,7 +2550,7 @@ void EditorNode::_update_addon_config() { project_settings->queue_save(); } -void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled) { +void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed) { ERR_FAIL_COND(p_enabled && plugin_addons.has(p_addon)); ERR_FAIL_COND(!p_enabled && !plugin_addons.has(p_addon)); @@ -2554,7 +2558,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled) if (!p_enabled) { EditorPlugin *addon = plugin_addons[p_addon]; - remove_editor_plugin(addon); + remove_editor_plugin(addon, p_config_changed); memdelete(addon); //bye plugin_addons.erase(p_addon); _update_addon_config(); @@ -2606,7 +2610,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled) ep->set_script(script.get_ref_ptr()); ep->set_dir_cache(p_addon); plugin_addons[p_addon] = ep; - add_editor_plugin(ep); + add_editor_plugin(ep, p_config_changed); _update_addon_config(); } diff --git a/editor/editor_node.h b/editor/editor_node.h index e5670e5e7c..f4c0375c2e 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -637,8 +637,8 @@ public: ProjectSettingsEditor *get_project_settings() { return project_settings; } - static void add_editor_plugin(EditorPlugin *p_editor); - static void remove_editor_plugin(EditorPlugin *p_editor); + static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false); + static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false); void new_inherited_scene() { _menu_option_confirm(FILE_NEW_INHERITED_SCENE, false); } @@ -651,7 +651,7 @@ public: void add_control_to_dock(DockSlot p_slot, Control *p_control); void remove_control_from_dock(Control *p_control); - void set_addon_plugin_enabled(const String &p_addon, bool p_enabled); + void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false); bool is_addon_plugin_enabled(const String &p_addon) const; void edit_node(Node *p_node); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index cd024ff870..403db4b8ba 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -698,6 +698,34 @@ void EditorPlugin::remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_ ResourceImporterScene::get_singleton()->remove_importer(p_importer); } +int find(const PoolStringArray &a, const String &v) { + PoolStringArray::Read r = a.read(); + for (int j = 0; j < a.size(); ++j) { + if (r[j] == v) { + return j; + } + } + return -1; +} + +void EditorPlugin::enable_plugin() { + // Called when the plugin gets enabled in project settings, after it's added to the tree. + // You can implement it to register autoloads. + + if (get_script_instance() && get_script_instance()->has_method("enable_plugin")) { + get_script_instance()->call("enable_plugin"); + } +} + +void EditorPlugin::disable_plugin() { + // Last function called when the plugin gets disabled in project settings. + // Implement it to cleanup things from the project, such as unregister autoloads. + + if (get_script_instance() && get_script_instance()->has_method("disable_plugin")) { + get_script_instance()->call("disable_plugin"); + } +} + void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) { @@ -801,6 +829,8 @@ void EditorPlugin::_bind_methods() { ClassDB::add_virtual_method(get_class_static(), MethodInfo("set_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo("get_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "build")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo("enable_plugin")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo("disable_plugin")); ADD_SIGNAL(MethodInfo("scene_changed", PropertyInfo(Variant::OBJECT, "scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath"))); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index e03aeb5d30..5f060a4e96 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -232,6 +232,9 @@ public: String get_dir_cache() { return _dir_cache; } Ref<ConfigFile> get_config(); + void enable_plugin(); + void disable_plugin(); + EditorPlugin(); virtual ~EditorPlugin(); }; diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index 30027c0c34..a4d543c567 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -152,7 +152,7 @@ void EditorPluginSettings::_plugin_activity_changed() { bool active = ti->get_range(3); String name = ti->get_metadata(0); - EditorNode::get_singleton()->set_addon_plugin_enabled(name, active); + EditorNode::get_singleton()->set_addon_plugin_enabled(name, active, true); bool is_active = EditorNode::get_singleton()->is_addon_plugin_enabled(name); |