diff options
-rw-r--r-- | editor/editor_node.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e0a5cab167..d5e29f6973 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3299,33 +3299,39 @@ void EditorNode::_update_addon_config() { } void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed) { - ERR_FAIL_COND(p_enabled && addon_name_to_plugin.has(p_addon)); - ERR_FAIL_COND(!p_enabled && !addon_name_to_plugin.has(p_addon)); + String addon_path = p_addon; + + if (!addon_path.begins_with("res://")) { + addon_path = "res://addons/" + addon_path + "/plugin.cfg"; + } + + ERR_FAIL_COND(p_enabled && addon_name_to_plugin.has(addon_path)); + ERR_FAIL_COND(!p_enabled && !addon_name_to_plugin.has(addon_path)); if (!p_enabled) { - EditorPlugin *addon = addon_name_to_plugin[p_addon]; + EditorPlugin *addon = addon_name_to_plugin[addon_path]; remove_editor_plugin(addon, p_config_changed); memdelete(addon); - addon_name_to_plugin.erase(p_addon); + addon_name_to_plugin.erase(addon_path); _update_addon_config(); return; } Ref<ConfigFile> cf; cf.instantiate(); - if (!DirAccess::exists(p_addon.get_base_dir())) { - _remove_plugin_from_enabled(p_addon); - WARN_PRINT("Addon '" + p_addon + "' failed to load. No directory found. Removing from enabled plugins."); + if (!DirAccess::exists(addon_path.get_base_dir())) { + _remove_plugin_from_enabled(addon_path); + WARN_PRINT("Addon '" + addon_path + "' failed to load. No directory found. Removing from enabled plugins."); return; } - Error err = cf->load(p_addon); + Error err = cf->load(addon_path); if (err != OK) { - show_warning(vformat(TTR("Unable to enable addon plugin at: '%s' parsing of config failed."), p_addon)); + show_warning(vformat(TTR("Unable to enable addon plugin at: '%s' parsing of config failed."), addon_path)); return; } if (!cf->has_section_key("plugin", "script")) { - show_warning(vformat(TTR("Unable to find script field for addon plugin at: '%s'."), p_addon)); + show_warning(vformat(TTR("Unable to find script field for addon plugin at: '%s'."), addon_path)); return; } @@ -3334,7 +3340,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, // Only try to load the script if it has a name. Else, the plugin has no init script. if (script_path.length() > 0) { - script_path = p_addon.get_base_dir().plus_file(script_path); + script_path = addon_path.get_base_dir().plus_file(script_path); script = ResourceLoader::load(script_path); if (script.is_null()) { @@ -3344,8 +3350,8 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, // Errors in the script cause the base_type to be an empty StringName. if (script->get_instance_base_type() == StringName()) { - show_warning(vformat(TTR("Unable to load addon script from path: '%s'. This might be due to a code error in that script.\nDisabling the addon at '%s' to prevent further errors."), script_path, p_addon)); - _remove_plugin_from_enabled(p_addon); + show_warning(vformat(TTR("Unable to load addon script from path: '%s'. This might be due to a code error in that script.\nDisabling the addon at '%s' to prevent further errors."), script_path, addon_path)); + _remove_plugin_from_enabled(addon_path); return; } @@ -3363,14 +3369,18 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, EditorPlugin *ep = memnew(EditorPlugin); ep->set_script(script); - addon_name_to_plugin[p_addon] = ep; + addon_name_to_plugin[addon_path] = ep; add_editor_plugin(ep, p_config_changed); _update_addon_config(); } bool EditorNode::is_addon_plugin_enabled(const String &p_addon) const { - return addon_name_to_plugin.has(p_addon); + if (p_addon.begins_with("res://")) { + return addon_name_to_plugin.has(p_addon); + } + + return addon_name_to_plugin.has("res://addons/" + p_addon + "/plugin.cfg"); } void EditorNode::_remove_edited_scene(bool p_change_tab) { |