summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/classes/EditorPlugin.xml6
-rw-r--r--editor/editor_node.cpp69
-rw-r--r--editor/editor_node.h4
-rw-r--r--editor/editor_plugin.cpp5
-rw-r--r--editor/editor_plugin.h2
-rw-r--r--modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp9
6 files changed, 67 insertions, 28 deletions
diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml
index d28bf80a1e..7bbb2ae26c 100644
--- a/doc/classes/EditorPlugin.xml
+++ b/doc/classes/EditorPlugin.xml
@@ -470,6 +470,12 @@
Returns the [EditorInterface] object that gives you control over Godot editor's window and its functionalities.
</description>
</method>
+ <method name="get_export_as_menu">
+ <return type="PopupMenu" />
+ <description>
+ Returns the [PopupMenu] under [b]Scene &gt; Export As...[/b].
+ </description>
+ </method>
<method name="get_script_create_dialog">
<return type="ScriptCreateDialog" />
<description>
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; }
diff --git a/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp b/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp
index 23a7b7fed6..95db1c0965 100644
--- a/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp
+++ b/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp
@@ -64,9 +64,12 @@ SceneExporterGLTFPlugin::SceneExporterGLTFPlugin() {
file_export_lib->clear_filters();
file_export_lib->add_filter("*.glb");
file_export_lib->add_filter("*.gltf");
- file_export_lib->set_title(TTR("Export Mesh GLTF2"));
- String gltf_scene_name = TTR("Export GLTF...");
- add_tool_menu_item(gltf_scene_name, callable_mp(this, &SceneExporterGLTFPlugin::convert_scene_to_gltf2));
+ file_export_lib->set_title(TTR("Export Scene to glTF 2.0 File"));
+
+ PopupMenu *menu = get_export_as_menu();
+ int idx = menu->get_item_count();
+ menu->add_item(TTR("glTF 2.0 Scene..."));
+ menu->set_item_metadata(idx, callable_mp(this, &SceneExporterGLTFPlugin::convert_scene_to_gltf2));
}
void SceneExporterGLTFPlugin::_gltf2_dialog_action(String p_file) {