diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 162 |
1 files changed, 72 insertions, 90 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 8eaddcb7e1..9ac6fd66ef 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -465,15 +465,15 @@ void EditorNode::shortcut_input(const Ref<InputEvent> &p_event) { } if (ED_IS_SHORTCUT("editor/editor_2d", p_event)) { - _editor_select(EDITOR_2D); + editor_select(EDITOR_2D); } else if (ED_IS_SHORTCUT("editor/editor_3d", p_event)) { - _editor_select(EDITOR_3D); + editor_select(EDITOR_3D); } else if (ED_IS_SHORTCUT("editor/editor_script", p_event)) { - _editor_select(EDITOR_SCRIPT); + editor_select(EDITOR_SCRIPT); } else if (ED_IS_SHORTCUT("editor/editor_help", p_event)) { emit_signal(SNAME("request_help_search"), ""); } else if (ED_IS_SHORTCUT("editor/editor_assetlib", p_event) && AssetLibraryEditorPlugin::is_available()) { - _editor_select(EDITOR_ASSETLIB); + editor_select(EDITOR_ASSETLIB); } else if (ED_IS_SHORTCUT("editor/editor_next", p_event)) { _editor_select_next(); } else if (ED_IS_SHORTCUT("editor/editor_prev", p_event)) { @@ -584,7 +584,7 @@ void EditorNode::_update_from_settings() { void EditorNode::_select_default_main_screen_plugin() { if (EDITOR_3D < main_editor_buttons.size() && main_editor_buttons[EDITOR_3D]->is_visible()) { // If the 3D editor is enabled, use this as the default. - _editor_select(EDITOR_3D); + editor_select(EDITOR_3D); return; } @@ -593,12 +593,12 @@ void EditorNode::_select_default_main_screen_plugin() { for (int i = 0; i < main_editor_buttons.size(); i++) { Button *editor_button = main_editor_buttons[i]; if (editor_button->is_visible()) { - _editor_select(i); + editor_select(i); return; } } - _editor_select(-1); + editor_select(-1); } void EditorNode::_notification(int p_what) { @@ -1190,7 +1190,7 @@ void EditorNode::_editor_select_next() { } } while (!main_editor_buttons[editor]->is_visible()); - _editor_select(editor); + editor_select(editor); } void EditorNode::_open_command_palette() { @@ -1208,7 +1208,7 @@ void EditorNode::_editor_select_prev() { } } while (!main_editor_buttons[editor]->is_visible()); - _editor_select(editor); + editor_select(editor); } Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_deps) { @@ -2390,7 +2390,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) { // Update screen main_plugin. - _editor_select(plugin_index); + editor_select(plugin_index); main_plugin->edit(current_obj); } else { editor_plugin_screen->edit(current_obj); @@ -2450,7 +2450,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { write_movie_file = GLOBAL_GET("editor/movie_writer/movie_file"); } if (write_movie_file == String()) { - show_accept(TTR("Movie Maker mode is enabled, but no movie file path has been specified.\nA default movie file path can be specified in the project settings under the 'Editor/Movie Writer' category.\nAlternatively, for running single scenes, a 'movie_path' metadata can be added to the root node,\nspecifying the path to a movie file that will be used when recording that scene."), TTR("OK")); + show_accept(TTR("Movie Maker mode is enabled, but no movie file path has been specified.\nA default movie file path can be specified in the project settings under the Editor > Movie Writer category.\nAlternatively, for running single scenes, a `movie_file` string metadata can be added to the root node,\nspecifying the path to a movie file that will be used when recording that scene."), TTR("OK")); return; } } @@ -2763,18 +2763,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } else if (extensions.size()) { String root_name = scene->get_name(); - // Very similar to node naming logic. - switch (ProjectSettings::get_singleton()->get("editor/scene/scene_naming").operator int()) { - case SCENE_NAME_CASING_AUTO: - // Use casing of the root node. - break; - case SCENE_NAME_CASING_PASCAL_CASE: { - root_name = root_name.to_pascal_case(); - } break; - case SCENE_NAME_CASING_SNAKE_CASE: - root_name = root_name.replace("-", "_").to_snake_case(); - break; - } + root_name = EditorNode::adjust_scene_name_casing(root_name); file->set_current_path(root_name + "." + extensions.front()->get().to_lower()); } file->popup_file_dialog(); @@ -3080,8 +3069,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case HELP_SUPPORT_GODOT_DEVELOPMENT: { OS::get_singleton()->shell_open("https://godotengine.org/donate"); } break; - case SET_RENDERING_DRIVER_SAVE_AND_RESTART: { - ProjectSettings::get_singleton()->set("rendering/driver/driver_name", rendering_driver_request); + case SET_RENDERER_NAME_SAVE_AND_RESTART: { + ProjectSettings::get_singleton()->set("rendering/renderer/rendering_method", renderer_request); ProjectSettings::get_singleton()->save(); save_all_scenes(); @@ -3090,6 +3079,19 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } +String EditorNode::adjust_scene_name_casing(const String &root_name) { + switch (ProjectSettings::get_singleton()->get("editor/scene/scene_naming").operator int()) { + case SCENE_NAME_CASING_AUTO: + // Use casing of the root node. + break; + case SCENE_NAME_CASING_PASCAL_CASE: + return root_name.to_pascal_case(); + case SCENE_NAME_CASING_SNAKE_CASE: + return root_name.replace("-", "_").to_snake_case(); + } + return root_name; +} + void EditorNode::_request_screenshot() { _screenshot(); } @@ -3303,7 +3305,7 @@ VBoxContainer *EditorNode::get_main_screen_control() { return main_screen_vbox; } -void EditorNode::_editor_select(int p_which) { +void EditorNode::editor_select(int p_which) { static bool selecting = false; if (selecting || changing_scene) { return; @@ -3357,7 +3359,7 @@ void EditorNode::select_editor_by_name(const String &p_name) { for (int i = 0; i < main_editor_buttons.size(); i++) { if (main_editor_buttons[i]->get_text() == p_name) { - _editor_select(i); + editor_select(i); return; } } @@ -3370,7 +3372,7 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed Button *tb = memnew(Button); tb->set_flat(true); tb->set_toggle_mode(true); - tb->connect("pressed", callable_mp(singleton, &EditorNode::_editor_select).bind(singleton->main_editor_buttons.size())); + tb->connect("pressed", callable_mp(singleton, &EditorNode::editor_select).bind(singleton->main_editor_buttons.size())); tb->set_name(p_editor->get_name()); tb->set_text(p_editor->get_name()); @@ -3404,7 +3406,7 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan for (int i = 0; i < singleton->main_editor_buttons.size(); i++) { if (p_editor->get_name() == singleton->main_editor_buttons[i]->get_text()) { if (singleton->main_editor_buttons[i]->is_pressed()) { - singleton->_editor_select(EDITOR_SCRIPT); + singleton->editor_select(EDITOR_SCRIPT); } memdelete(singleton->main_editor_buttons[i]); @@ -3628,7 +3630,7 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { int index = p_state["editor_index"]; if (current < 2) { // If currently in spatial/2d, only switch to spatial/2d. If currently in script, stay there. if (index < 2 || !get_edited_scene()) { - _editor_select(index); + editor_select(index); } } } @@ -3639,9 +3641,9 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { int n2d = 0, n3d = 0; _find_node_types(get_edited_scene(), n2d, n3d); if (n2d > n3d) { - _editor_select(EDITOR_2D); + editor_select(EDITOR_2D); } else if (n3d > n2d) { - _editor_select(EDITOR_3D); + editor_select(EDITOR_3D); } } } @@ -3668,10 +3670,6 @@ bool EditorNode::is_changing_scene() const { return changing_scene; } -void EditorNode::_clear_undo_history() { - get_undo_redo()->clear_history(false); -} - void EditorNode::set_current_scene(int p_idx) { // Save the folding in case the scene gets reloaded. if (editor_data.get_scene_path(p_idx) != "" && editor_data.get_edited_scene_root(p_idx)) { @@ -5882,27 +5880,27 @@ void EditorNode::_bottom_panel_raise_toggled(bool p_pressed) { top_split->set_visible(!p_pressed); } -void EditorNode::_update_rendering_driver_color() { - if (rendering_driver->get_text() == "opengl3") { - rendering_driver->add_theme_color_override("font_color", Color::hex(0x5586a4ff)); - } else if (rendering_driver->get_text() == "vulkan") { - rendering_driver->add_theme_color_override("font_color", theme_base->get_theme_color(SNAME("vulkan_color"), SNAME("Editor"))); +void EditorNode::_update_renderer_color() { + if (renderer->get_text() == "gl_compatibility") { + renderer->add_theme_color_override("font_color", Color::hex(0x5586a4ff)); + } else if (renderer->get_text() == "forward_plus" || renderer->get_text() == "mobile") { + renderer->add_theme_color_override("font_color", theme_base->get_theme_color(SNAME("vulkan_color"), SNAME("Editor"))); } } -void EditorNode::_rendering_driver_selected(int p_which) { - String driver = rendering_driver->get_item_metadata(p_which); +void EditorNode::_renderer_selected(int p_which) { + String rendering_method = renderer->get_item_metadata(p_which); - String current_driver = OS::get_singleton()->get_current_rendering_driver_name(); + String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method"); - if (driver == current_driver) { + if (rendering_method == current_renderer) { return; } - rendering_driver_request = driver; + renderer_request = rendering_method; video_restart_dialog->popup_centered(); - rendering_driver->select(rendering_driver_current); - _update_rendering_driver_color(); + renderer->select(renderer_current); + _update_renderer_color(); } void EditorNode::_resource_saved(Ref<Resource> p_resource, const String &p_path) { @@ -5937,7 +5935,7 @@ void EditorNode::_feature_profile_changed() { if ((profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) && singleton->main_editor_buttons[EDITOR_3D]->is_pressed()) || (profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT) && singleton->main_editor_buttons[EDITOR_SCRIPT]->is_pressed()) || (AssetLibraryEditorPlugin::is_available() && profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) && singleton->main_editor_buttons[EDITOR_ASSETLIB]->is_pressed())) { - _editor_select(EDITOR_2D); + editor_select(EDITOR_2D); } } else { import_tabs->set_tab_hidden(import_tabs->get_tab_idx_from_control(ImportDock::get_singleton()), false); @@ -5960,19 +5958,14 @@ void EditorNode::_bind_methods() { GLOBAL_DEF("editor/scene/scene_naming", SCENE_NAME_CASING_SNAKE_CASE); ProjectSettings::get_singleton()->set_custom_property_info("editor/scene/scene_naming", PropertyInfo(Variant::INT, "editor/scene/scene_naming", PROPERTY_HINT_ENUM, "Auto,PascalCase,snake_case")); ClassDB::bind_method("edit_current", &EditorNode::edit_current); - ClassDB::bind_method("_editor_select", &EditorNode::_editor_select); - ClassDB::bind_method("_node_renamed", &EditorNode::_node_renamed); ClassDB::bind_method("edit_node", &EditorNode::edit_node); ClassDB::bind_method(D_METHOD("push_item", "object", "property", "inspector_only"), &EditorNode::push_item, DEFVAL(""), DEFVAL(false)); - ClassDB::bind_method("_get_scene_metadata", &EditorNode::_get_scene_metadata); ClassDB::bind_method("set_edited_scene", &EditorNode::set_edited_scene); ClassDB::bind_method("open_request", &EditorNode::open_request); ClassDB::bind_method("edit_foreign_resource", &EditorNode::edit_foreign_resource); ClassDB::bind_method("is_resource_read_only", &EditorNode::is_resource_read_only); - ClassDB::bind_method("_close_messages", &EditorNode::_close_messages); - ClassDB::bind_method("_show_messages", &EditorNode::_show_messages); ClassDB::bind_method("stop_child_process", &EditorNode::stop_child_process); @@ -5981,19 +5974,10 @@ void EditorNode::_bind_methods() { ClassDB::bind_method("_set_main_scene_state", &EditorNode::_set_main_scene_state); ClassDB::bind_method("_update_recent_scenes", &EditorNode::_update_recent_scenes); - ClassDB::bind_method("_clear_undo_history", &EditorNode::_clear_undo_history); - ClassDB::bind_method("edit_item_resource", &EditorNode::edit_item_resource); ClassDB::bind_method(D_METHOD("get_gui_base"), &EditorNode::get_gui_base); - ClassDB::bind_method(D_METHOD("_on_plugin_ready"), &EditorNode::_on_plugin_ready); // Still used by some connect_compat. - - ClassDB::bind_method("_screenshot", &EditorNode::_screenshot); - ClassDB::bind_method("_save_screenshot", &EditorNode::_save_screenshot); - - ClassDB::bind_method("_version_button_pressed", &EditorNode::_version_button_pressed); - ADD_SIGNAL(MethodInfo("play_pressed")); ADD_SIGNAL(MethodInfo("pause_pressed")); ADD_SIGNAL(MethodInfo("stop_pressed")); @@ -6966,19 +6950,17 @@ EditorNode::EditorNode() { HBoxContainer *right_menu_hb = memnew(HBoxContainer); menu_hb->add_child(right_menu_hb); - rendering_driver = memnew(OptionButton); - + renderer = memnew(OptionButton); // Hide the renderer selection dropdown until OpenGL support is more mature. // The renderer can still be changed in the project settings or using `--rendering-driver opengl3`. - rendering_driver->set_visible(false); + renderer->set_visible(false); + renderer->set_flat(true); + renderer->set_focus_mode(Control::FOCUS_NONE); + renderer->connect("item_selected", callable_mp(this, &EditorNode::_renderer_selected)); + renderer->add_theme_font_override("font", gui_base->get_theme_font(SNAME("bold"), SNAME("EditorFonts"))); + renderer->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"))); - rendering_driver->set_flat(true); - rendering_driver->set_focus_mode(Control::FOCUS_NONE); - rendering_driver->connect("item_selected", callable_mp(this, &EditorNode::_rendering_driver_selected)); - rendering_driver->add_theme_font_override("font", gui_base->get_theme_font(SNAME("bold"), SNAME("EditorFonts"))); - rendering_driver->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"))); - - right_menu_hb->add_child(rendering_driver); + right_menu_hb->add_child(renderer); if (can_expand) { // Add spacer to avoid other controls under the window minimize/maximize/close buttons (right side). @@ -6988,36 +6970,35 @@ EditorNode::EditorNode() { menu_hb->add_child(menu_spacer); } - // Only display the render drivers that are available for this display driver. - int display_driver_idx = OS::get_singleton()->get_display_driver_id(); - Vector<String> render_drivers = DisplayServer::get_create_function_rendering_drivers(display_driver_idx); - String current_rendering_driver = OS::get_singleton()->get_current_rendering_driver_name(); + String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method"); + + PackedStringArray renderers = ProjectSettings::get_singleton()->get_custom_property_info().get(StringName("rendering/renderer/rendering_method")).hint_string.split(",", false); // As we are doing string comparisons, keep in standard case to prevent problems with capitals // "vulkan" in particular uses lowercase "v" in the code, and uppercase in the UI. - current_rendering_driver = current_rendering_driver.to_lower(); + current_renderer = current_renderer.to_lower(); - for (int i = 0; i < render_drivers.size(); i++) { - String driver = render_drivers[i]; + for (int i = 0; i < renderers.size(); i++) { + String rendering_method = renderers[i]; - // Add the driver to the UI. - rendering_driver->add_item(driver); - rendering_driver->set_item_metadata(i, driver); + // Add the renderers name to the UI. + renderer->add_item(rendering_method); + renderer->set_item_metadata(i, rendering_method); // Lowercase for standard comparison. - driver = driver.to_lower(); + rendering_method = rendering_method.to_lower(); - if (current_rendering_driver == driver) { - rendering_driver->select(i); - rendering_driver_current = i; + if (current_renderer == rendering_method) { + renderer->select(i); + renderer_current = i; } } - _update_rendering_driver_color(); + _update_renderer_color(); video_restart_dialog = memnew(ConfirmationDialog); - video_restart_dialog->set_text(TTR("Changing the video driver requires restarting the editor.")); + video_restart_dialog->set_text(TTR("Changing the renderer requires restarting the editor.")); video_restart_dialog->set_ok_button_text(TTR("Save & Restart")); - video_restart_dialog->connect("confirmed", callable_mp(this, &EditorNode::_menu_option).bind(SET_RENDERING_DRIVER_SAVE_AND_RESTART)); + video_restart_dialog->connect("confirmed", callable_mp(this, &EditorNode::_menu_option).bind(SET_RENDERER_NAME_SAVE_AND_RESTART)); gui_base->add_child(video_restart_dialog); progress_hb = memnew(BackgroundProgress); @@ -7547,6 +7528,7 @@ EditorNode::EditorNode() { // Extend menu bar to window title. if (can_expand) { + DisplayServer::get_singleton()->window_set_window_buttons_offset(Vector2i(menu_hb->get_minimum_size().y / 2, menu_hb->get_minimum_size().y / 2), DisplayServer::MAIN_WINDOW_ID); DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE, true, DisplayServer::MAIN_WINDOW_ID); menu_hb->set_can_move_window(true); } |