diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 128 |
1 files changed, 94 insertions, 34 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6a4e879340..6559048172 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -141,13 +141,31 @@ void EditorNode::_update_scene_tabs() { } scene_tabs->set_current_tab(editor_data.get_edited_scene()); - scene_tabs->ensure_tab_visible(editor_data.get_edited_scene()); + + int current = editor_data.get_edited_scene(); + if (scene_tabs->get_offset_buttons_visible()) { + // move add button to fixed position on the tabbar + if (scene_tab_add->get_parent() == scene_tabs) { + scene_tab_add->set_position(Point2(0, 0)); + scene_tabs->remove_child(scene_tab_add); + tabbar_container->add_child(scene_tab_add); + tabbar_container->move_child(scene_tab_add, 1); + } + } else { + // move add button to after last tab + if (scene_tab_add->get_parent() == tabbar_container) { + tabbar_container->remove_child(scene_tab_add); + scene_tabs->add_child(scene_tab_add); + } + Rect2 last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1); + scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y)); + } } void EditorNode::_update_title() { String appname = ProjectSettings::get_singleton()->get("application/config/name"); - String title = appname.empty() ? String(VERSION_FULL_NAME) : String(_MKSTR(VERSION_NAME) + String(" - ") + appname); + String title = appname.empty() ? String(VERSION_FULL_NAME) : String(VERSION_NAME + String(" - ") + appname); String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String(); if (!edited.empty()) title += " - " + String(edited.get_file()); @@ -327,6 +345,7 @@ void EditorNode::_notification(int p_what) { prev_scene->set_icon(gui_base->get_icon("PrevScene", "EditorIcons")); distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons")); + scene_tab_add->set_icon(gui_base->get_icon("Add", "EditorIcons")); resource_new_button->set_icon(gui_base->get_icon("New", "EditorIcons")); resource_load_button->set_icon(gui_base->get_icon("Load", "EditorIcons")); @@ -344,6 +363,9 @@ void EditorNode::_notification(int p_what) { dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); update_menu->set_icon(gui_base->get_icon("Progress1", "EditorIcons")); } + if (p_what = Control::NOTIFICATION_RESIZED) { + _update_scene_tabs(); + } } void EditorNode::_fs_changed() { @@ -705,7 +727,7 @@ void EditorNode::_get_scene_metadata(const String &p_file) { if (!scene) return; - String path = EditorSettings::get_singleton()->get_project_settings_path().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); + String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); Ref<ConfigFile> cf; cf.instance(); @@ -739,7 +761,7 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { scene->set_meta("__editor_run_settings__", Variant()); //clear it (no point in keeping it) scene->set_meta("__editor_plugin_states__", Variant()); - String path = EditorSettings::get_singleton()->get_project_settings_path().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); + String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); Ref<ConfigFile> cf; cf.instance(); @@ -906,27 +928,33 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); preview_size *= EDSCALE; - int width, height; - if (img->get_width() > preview_size && img->get_width() >= img->get_height()) { - width = preview_size; - height = img->get_height() * preview_size / img->get_width(); - } else if (img->get_height() > preview_size && img->get_height() >= img->get_width()) { + // consider a square region + int vp_size = MIN(img->get_width(), img->get_height()); + int x = (img->get_width() - vp_size) / 2; + int y = (img->get_height() - vp_size) / 2; - height = preview_size; - width = img->get_width() * preview_size / img->get_height(); + img->convert(Image::FORMAT_RGB8); + + if (vp_size < preview_size) { + // just square it. + img->crop_from_point(x, y, vp_size, vp_size); } else { + int ratio = vp_size / preview_size; + int size = preview_size * (ratio / 2); + + x = (img->get_width() - size) / 2; + y = (img->get_height() - size) / 2; - width = img->get_width(); - height = img->get_height(); + img->crop_from_point(x, y, size, size); + // We could get better pictures with better filters + img->resize(preview_size, preview_size, Image::INTERPOLATE_CUBIC); } - img->convert(Image::FORMAT_RGB8); - img->resize(width, height); img->flip_y(); //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 - String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String temp_path = EditorSettings::get_singleton()->get_cache_dir(); String cache_base = ProjectSettings::get_singleton()->globalize_path(p_file).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); @@ -1109,7 +1137,7 @@ void EditorNode::_dialog_action(String p_file) { _save_default_environment(); _save_scene_with_preview(p_file); - _run(true); + _run(false, p_file); } } break; @@ -1198,7 +1226,7 @@ void EditorNode::_dialog_action(String p_file) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err == ERR_CANT_OPEN) { config.instance(); // new config @@ -1209,7 +1237,7 @@ void EditorNode::_dialog_action(String p_file) { _save_docks_to_config(config, p_file); - config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + config->save(EditorSettings::get_singleton()->get_editor_layouts_config()); layout_dialog->hide(); _update_layouts_menu(); @@ -1226,7 +1254,7 @@ void EditorNode::_dialog_action(String p_file) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK || !config->has_section(p_file)) { show_warning(TTR("Layout name not found!")); @@ -1240,7 +1268,7 @@ void EditorNode::_dialog_action(String p_file) { config->set_value(p_file, E->get(), Variant()); } - config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + config->save(EditorSettings::get_singleton()->get_editor_layouts_config()); layout_dialog->hide(); _update_layouts_menu(); @@ -1759,6 +1787,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { int idx = editor_data.add_edited_scene(-1); _scene_tab_changed(idx); editor_data.clear_editor_states(); + _update_scene_tabs(); } break; case FILE_NEW_INHERITED_SCENE: @@ -3273,7 +3302,7 @@ void EditorNode::register_editor_types() { ClassDB::register_class<EditorResourceConversionPlugin>(); // FIXME: Is this stuff obsolete, or should it be ported to new APIs? - //ClassDB::register_class<EditorScenePostImport>(); + ClassDB::register_class<EditorScenePostImport>(); //ClassDB::register_type<EditorImportExport>(); } @@ -3581,7 +3610,7 @@ void EditorNode::_save_docks() { _save_docks_to_config(config, "docks"); editor_data.get_plugin_window_layout(config); - config->save(EditorSettings::get_singleton()->get_project_settings_path().plus_file("editor_layout.cfg")); + config->save(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); } void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) { @@ -3643,7 +3672,7 @@ void EditorNode::_load_docks() { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_project_settings_path().plus_file("editor_layout.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); if (err != OK) { //no config if (overridden_default_layout >= 0) { @@ -3812,7 +3841,7 @@ void EditorNode::_update_layouts_menu() { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK) { return; //no config } @@ -3860,7 +3889,7 @@ void EditorNode::_layout_menu_option(int p_id) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK) { return; //no config } @@ -3897,6 +3926,7 @@ void EditorNode::_scene_tab_closed(int p_tab) { } else { _discard_changes(); } + _update_scene_tabs(); } void EditorNode::_scene_tab_hover(int p_tab) { @@ -4276,12 +4306,19 @@ Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control * void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) { - /* - String cur_path = filesystem_dock->get_current_path(); - for(int i=0;i<EditorImportExport::get_singleton()->get_import_plugin_count();i++) { - EditorImportExport::get_singleton()->get_import_plugin(i)->import_from_drop(p_files,cur_path); + String to_path = ProjectSettings::get_singleton()->globalize_path(get_filesystem_dock()->get_current_path()); + DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + + for (int i = 0; i < p_files.size(); i++) { + + String from = p_files[i]; + if (!ResourceFormatImporter::get_singleton()->can_be_imported(from)) { + continue; + } + String to = to_path.plus_file(from.get_file()); + dir->copy(from, to); } - */ + EditorFileSystem::get_singleton()->scan_changes(); } void EditorNode::_file_access_close_error_notify(const String &p_str) { @@ -4552,6 +4589,11 @@ static Node *_resource_get_edited_scene() { return EditorNode::get_singleton()->get_edited_scene(); } +void EditorNode::_print_handler(void *p_this, const String &p_string, bool p_error) { + EditorNode *en = (EditorNode *)p_this; + en->log->add_message(p_string, p_error); +} + EditorNode::EditorNode() { Resource::_get_local_scene_func = _resource_get_edited_scene; @@ -4788,7 +4830,12 @@ EditorNode::EditorNode() { dock_tab_move_left->set_focus_mode(Control::FOCUS_NONE); dock_tab_move_left->connect("pressed", this, "_dock_move_left"); dock_hb->add_child(dock_tab_move_left); - dock_hb->add_spacer(); + + Label *dock_label = memnew(Label); + dock_label->set_text(TTR("Dock Position")); + dock_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + dock_hb->add_child(dock_label); + dock_tab_move_right = memnew(ToolButton); dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE); @@ -4858,20 +4905,28 @@ EditorNode::EditorNode() { scene_tabs->connect("mouse_exited", this, "_scene_tab_exit"); scene_tabs->connect("gui_input", this, "_scene_tab_input"); scene_tabs->connect("reposition_active_tab_request", this, "_reposition_active_tab"); + scene_tabs->connect("resized", this, "_update_scene_tabs"); - HBoxContainer *tabbar_container = memnew(HBoxContainer); + tabbar_container = memnew(HBoxContainer); scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL); srt->add_child(tabbar_container); tabbar_container->add_child(scene_tabs); distraction_free = memnew(ToolButton); - tabbar_container->add_child(distraction_free); distraction_free->set_shortcut(ED_SHORTCUT("editor/distraction_free_mode", TTR("Distraction Free Mode"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F11)); distraction_free->set_tooltip(TTR("Toggle distraction-free mode.")); distraction_free->connect("pressed", this, "_toggle_distraction_free_mode"); distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons")); distraction_free->set_toggle_mode(true); + scene_tab_add = memnew(ToolButton); + tabbar_container->add_child(scene_tab_add); + tabbar_container->add_child(distraction_free); + scene_tab_add->set_tooltip(TTR("Add a new scene.")); + scene_tab_add->set_icon(gui_base->get_icon("Add", "EditorIcons")); + scene_tab_add->add_color_override("icon_color_normal", Color(0.6f, 0.6f, 0.6f, 0.8f)); + scene_tab_add->connect("pressed", this, "_menu_option", make_binds(FILE_NEW_SCENE)); + scene_root_parent = memnew(PanelContainer); scene_root_parent->set_custom_minimum_size(Size2(0, 80) * EDSCALE); scene_root_parent->add_style_override("panel", gui_base->get_stylebox("Content", "EditorStyles")); @@ -5652,6 +5707,10 @@ EditorNode::EditorNode() { _dim_timer->connect("timeout", this, "_dim_timeout"); add_child(_dim_timer); + print_handler.printfunc = _print_handler; + print_handler.userdata = this; + add_print_handler(&print_handler); + ED_SHORTCUT("editor/editor_2d", TTR("Open 2D Editor"), KEY_F1); ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_F2); ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_F3); //hack neded for script editor F3 search to work :) Assign like this or don't use F3 @@ -5663,6 +5722,7 @@ EditorNode::EditorNode() { EditorNode::~EditorNode() { + remove_print_handler(&print_handler); memdelete(EditorHelp::get_doc_data()); memdelete(editor_selection); memdelete(editor_plugins_over); |