diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-04-27 11:51:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-27 11:51:49 +0200 |
commit | d22850234ceb958857d081c6f195bedec232430b (patch) | |
tree | 214061009b1f87e95b565771aededd42e9fb4d0f /editor | |
parent | 523a7ecef31d93f0f794e06aa5aa84cf3f53901c (diff) | |
parent | 0ea7780e3337d075af43d4de9f66bd80fea9e3ef (diff) |
Merge pull request #59393 from techiepriyansh/move-gltf-export-under-scene-menu
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 69 | ||||
-rw-r--r-- | editor/editor_node.h | 4 | ||||
-rw-r--r-- | editor/editor_plugin.cpp | 5 | ||||
-rw-r--r-- | editor/editor_plugin.h | 2 |
4 files changed, 55 insertions, 25 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index db6bf4f816..113f01caae 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2660,25 +2660,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { project_export->popup_export(); } break; - case FILE_EXPORT_MESH_LIBRARY: { - if (!editor_data.get_edited_scene_root()) { - show_accept(TTR("This operation can't be done without a scene."), TTR("OK")); - break; - } - - List<String> extensions; - Ref<MeshLibrary> ml(memnew(MeshLibrary)); - ResourceSaver::get_recognized_extensions(ml, &extensions); - file_export_lib->clear_filters(); - for (const String &E : extensions) { - file_export_lib->add_filter("*." + E); - } - - file_export_lib->popup_file_dialog(); - file_export_lib->set_title(TTR("Export Mesh Library")); - - } break; - case FILE_EXTERNAL_OPEN_SCENE: { if (unsaved_cache && !p_confirmed) { confirmation->get_ok_button()->set_text(TTR("Open")); @@ -3022,6 +3003,40 @@ void EditorNode::_tool_menu_option(int p_idx) { } } +void EditorNode::_export_as_menu_option(int p_idx) { + if (p_idx == 0) { // MeshLibrary + current_menu_option = FILE_EXPORT_MESH_LIBRARY; + + if (!editor_data.get_edited_scene_root()) { + show_accept(TTR("This operation can't be done without a scene."), TTR("OK")); + return; + } + + List<String> extensions; + Ref<MeshLibrary> ml(memnew(MeshLibrary)); + ResourceSaver::get_recognized_extensions(ml, &extensions); + file_export_lib->clear_filters(); + for (const String &E : extensions) { + file_export_lib->add_filter("*." + E); + } + + file_export_lib->popup_file_dialog(); + file_export_lib->set_title(TTR("Export Mesh Library")); + } else { // Custom menu options added by plugins + if (export_as_menu->get_item_submenu(p_idx).is_empty()) { // If not a submenu + Callable callback = export_as_menu->get_item_metadata(p_idx); + Callable::CallError ce; + Variant result; + callback.call(nullptr, 0, result, ce); + + if (ce.error != Callable::CallError::CALL_OK) { + String err = Variant::get_callable_error_text(callback, nullptr, 0, ce); + ERR_PRINT("Error calling function from export_as menu: " + err); + } + } + } +} + int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) { for (int i = p_start; i < editor_data.get_edited_scene_count(); i++) { if (!editor_data.get_edited_scene_root(i)) { @@ -5473,6 +5488,10 @@ void EditorNode::remove_tool_menu_item(const String &p_name) { } } +PopupMenu *EditorNode::get_export_as_menu() { + return export_as_menu; +} + void EditorNode::_global_menu_scene(const Variant &p_tag) { int idx = (int)p_tag; scene_tabs->set_current_tab(idx); @@ -6447,12 +6466,12 @@ EditorNode::EditorNode() { p->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/quick_open_script", TTR("Quick Open Script..."), KeyModifierMask::CMD + KeyModifierMask::ALT + Key::O), FILE_QUICK_OPEN_SCRIPT); p->add_separator(); - PopupMenu *pm_export = memnew(PopupMenu); - pm_export->set_name("Export"); - p->add_child(pm_export); - p->add_submenu_item(TTR("Convert To..."), "Export"); - pm_export->add_shortcut(ED_SHORTCUT("editor/convert_to_MeshLibrary", TTR("MeshLibrary...")), FILE_EXPORT_MESH_LIBRARY); - pm_export->connect("id_pressed", callable_mp(this, &EditorNode::_menu_option)); + export_as_menu = memnew(PopupMenu); + export_as_menu->set_name("Export"); + p->add_child(export_as_menu); + p->add_submenu_item(TTR("Export As..."), "Export"); + export_as_menu->add_shortcut(ED_SHORTCUT("editor/export_as_mesh_library", TTR("MeshLibrary...")), FILE_EXPORT_MESH_LIBRARY); + export_as_menu->connect("index_pressed", callable_mp(this, &EditorNode::_export_as_menu_option)); p->add_separator(); p->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO, true); diff --git a/editor/editor_node.h b/editor/editor_node.h index c6c1f09938..82118b8b70 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -323,6 +323,7 @@ private: MenuButton *settings_menu = nullptr; MenuButton *help_menu = nullptr; PopupMenu *tool_menu = nullptr; + PopupMenu *export_as_menu = nullptr; Button *export_button = nullptr; Button *prev_scene = nullptr; Button *play_button = nullptr; @@ -524,6 +525,7 @@ private: void _save_screenshot(NodePath p_path); void _tool_menu_option(int p_idx); + void _export_as_menu_option(int p_idx); void _update_file_menu_opened(); void _update_file_menu_closed(); @@ -840,6 +842,8 @@ public: void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu); void remove_tool_menu_item(const String &p_name); + PopupMenu *get_export_as_menu(); + void save_all_scenes(); void save_scene_list(Vector<String> p_scene_filenames); void restart_editor(); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 6596c245bc..639846861b 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -524,6 +524,10 @@ void EditorPlugin::remove_tool_menu_item(const String &p_name) { EditorNode::get_singleton()->remove_tool_menu_item(p_name); } +PopupMenu *EditorPlugin::get_export_as_menu() { + return EditorNode::get_singleton()->get_export_as_menu(); +} + void EditorPlugin::set_input_event_forwarding_always_enabled() { input_event_forwarding_always_enabled = true; EditorPluginList *always_input_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding(); @@ -870,6 +874,7 @@ void EditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "callable"), &EditorPlugin::add_tool_menu_item); ClassDB::bind_method(D_METHOD("add_tool_submenu_item", "name", "submenu"), &EditorPlugin::add_tool_submenu_item); ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"), &EditorPlugin::remove_tool_menu_item); + ClassDB::bind_method(D_METHOD("get_export_as_menu"), &EditorPlugin::get_export_as_menu); ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type); ClassDB::bind_method(D_METHOD("remove_custom_type", "type"), &EditorPlugin::remove_custom_type); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 1a5be7a89b..c666b4639d 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -220,6 +220,8 @@ public: void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu); void remove_tool_menu_item(const String &p_name); + PopupMenu *get_export_as_menu(); + void set_input_event_forwarding_always_enabled(); bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; } |