diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 178 |
1 files changed, 112 insertions, 66 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index ab41019ac3..8e6668bc89 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -49,16 +49,44 @@ #include "core/version.h" #include "main/input_default.h" #include "main/main.h" +#include "scene/gui/center_container.h" +#include "scene/gui/control.h" +#include "scene/gui/dialogs.h" +#include "scene/gui/file_dialog.h" +#include "scene/gui/menu_button.h" +#include "scene/gui/panel.h" +#include "scene/gui/panel_container.h" +#include "scene/gui/split_container.h" +#include "scene/gui/tab_container.h" +#include "scene/gui/tabs.h" +#include "scene/gui/texture_progress.h" +#include "scene/gui/tool_button.h" #include "scene/resources/packed_scene.h" #include "servers/physics_2d_server.h" +#include "editor/audio_stream_preview.h" +#include "editor/dependency_editor.h" +#include "editor/editor_about.h" #include "editor/editor_audio_buses.h" +#include "editor/editor_export.h" +#include "editor/editor_feature_profile.h" #include "editor/editor_file_system.h" #include "editor/editor_help.h" +#include "editor/editor_inspector.h" +#include "editor/editor_layouts_dialog.h" +#include "editor/editor_log.h" +#include "editor/editor_plugin.h" #include "editor/editor_properties.h" +#include "editor/editor_resource_preview.h" +#include "editor/editor_run_native.h" +#include "editor/editor_run_script.h" +#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_spin_slider.h" #include "editor/editor_themes.h" +#include "editor/export_template_manager.h" +#include "editor/fileserver/editor_file_server.h" +#include "editor/filesystem_dock.h" #include "editor/import/editor_import_collada.h" #include "editor/import/editor_scene_importer_gltf.h" #include "editor/import/resource_importer_bitmask.h" @@ -71,7 +99,11 @@ #include "editor/import/resource_importer_texture.h" #include "editor/import/resource_importer_texture_atlas.h" #include "editor/import/resource_importer_wav.h" +#include "editor/import_dock.h" #include "editor/multi_node_edit.h" +#include "editor/node_dock.h" +#include "editor/pane_drag.h" +#include "editor/plugin_config_dialog.h" #include "editor/plugins/animation_blend_space_1d_editor.h" #include "editor/plugins/animation_blend_space_2d_editor.h" #include "editor/plugins/animation_blend_tree_editor_plugin.h" @@ -128,11 +160,18 @@ #include "editor/plugins/tile_set_editor_plugin.h" #include "editor/plugins/version_control_editor_plugin.h" #include "editor/plugins/visual_shader_editor_plugin.h" +#include "editor/progress_dialog.h" +#include "editor/project_export.h" +#include "editor/project_settings_editor.h" #include "editor/pvrtc_compress.h" +#include "editor/quick_open.h" #include "editor/register_exporters.h" +#include "editor/run_settings_dialog.h" #include "editor/script_editor_debugger.h" +#include "editor/settings_config_dialog.h" #include <stdio.h> +#include <stdlib.h> EditorNode *EditorNode::singleton = NULL; @@ -535,11 +574,13 @@ void EditorNode::_fs_changed() { if (preset.is_null()) { String errstr = "Unknown export preset: " + export_defer.preset; ERR_PRINTS(errstr); + OS::get_singleton()->set_exit_code(EXIT_FAILURE); } else { Ref<EditorExportPlatform> platform = preset->get_platform(); if (platform.is_null()) { String errstr = "Preset \"" + export_defer.preset + "\" doesn't have a platform."; ERR_PRINTS(errstr); + OS::get_singleton()->set_exit_code(EXIT_FAILURE); } else { // ensures export_project does not loop infinitely, because notifications may // come during the export @@ -556,6 +597,7 @@ void EditorNode::_fs_changed() { } if (err != OK) { ERR_PRINTS(vformat(TTR("Project export failed with error code %d."), (int)err)); + OS::get_singleton()->set_exit_code(EXIT_FAILURE); } } } @@ -630,7 +672,7 @@ void EditorNode::_editor_select_next() { } else { editor++; } - } while (main_editor_buttons[editor]->is_visible()); + } while (!main_editor_buttons[editor]->is_visible()); _editor_select(editor); } @@ -645,7 +687,7 @@ void EditorNode::_editor_select_prev() { } else { editor--; } - } while (main_editor_buttons[editor]->is_visible()); + } while (!main_editor_buttons[editor]->is_visible()); _editor_select(editor); } @@ -963,7 +1005,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> int len = varray.size(); for (int i = 0; i < len; i++) { - Variant v = varray.get(i); + const Variant &v = varray.get(i); RES res = v; if (_find_and_save_resource(res, processed, flags)) ret_changed = true; @@ -1021,74 +1063,75 @@ void EditorNode::_find_node_types(Node *p_node, int &count_2d, int &count_3d) { void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { EditorProgress save("save", TTR("Saving Scene"), 4); - save.step(TTR("Analyzing"), 0); - int c2d = 0; - int c3d = 0; - _find_node_types(editor_data.get_edited_scene_root(), c2d, c3d); + if (editor_data.get_edited_scene_root() != NULL) { + save.step(TTR("Analyzing"), 0); - RID viewport; - bool is2d; - if (c3d < c2d) { - viewport = scene_root->get_viewport_rid(); - is2d = true; - } else { - viewport = SpatialEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_viewport_rid(); - is2d = false; - } - save.step(TTR("Creating Thumbnail"), 1); - //current view? + int c2d = 0; + int c3d = 0; - Ref<Image> img; - if (is2d) { - img = scene_root->get_texture()->get_data(); - } else { - img = SpatialEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data(); - } + _find_node_types(editor_data.get_edited_scene_root(), c2d, c3d); - if (img.is_valid()) { + bool is2d; + if (c3d < c2d) { + is2d = true; + } else { + is2d = false; + } + save.step(TTR("Creating Thumbnail"), 1); + //current view? - img = img->duplicate(); + Ref<Image> img; + if (is2d) { + img = scene_root->get_texture()->get_data(); + } else { + img = SpatialEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data(); + } - save.step(TTR("Creating Thumbnail"), 2); - save.step(TTR("Creating Thumbnail"), 3); + if (img.is_valid()) { - int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - preview_size *= EDSCALE; + img = img->duplicate(); - // 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; + save.step(TTR("Creating Thumbnail"), 2); + save.step(TTR("Creating Thumbnail"), 3); - 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 * MAX(1, ratio / 2); + int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + preview_size *= EDSCALE; - x = (img->get_width() - size) / 2; - y = (img->get_height() - size) / 2; + // 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; - img->crop_from_point(x, y, size, size); - img->resize(preview_size, preview_size, Image::INTERPOLATE_LANCZOS); - } - 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 * MAX(1, ratio / 2); + + x = (img->get_width() - size) / 2; + y = (img->get_height() - size) / 2; - img->flip_y(); + img->crop_from_point(x, y, size, size); + img->resize(preview_size, preview_size, Image::INTERPOLATE_LANCZOS); + } + img->convert(Image::FORMAT_RGB8); - //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 - 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); + img->flip_y(); - //does not have it, try to load a cached thumbnail + //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 + 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); - String file = cache_base + ".png"; + //does not have it, try to load a cached thumbnail - post_process_preview(img); - img->save_png(file); + String file = cache_base + ".png"; + + post_process_preview(img); + img->save_png(file); + } } save.step(TTR("Saving Scene"), 4); @@ -1282,7 +1325,6 @@ void EditorNode::restart_editor() { } _exit_editor(); - String exec = OS::get_singleton()->get_executable_path(); List<String> args; args.push_back("--path"); @@ -2049,14 +2091,17 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: case FILE_CLOSE: { - if (!p_confirmed && (unsaved_cache || p_option == FILE_CLOSE_ALL_AND_QUIT || p_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER)) { + if (!p_confirmed) { tab_closing = p_option == FILE_CLOSE ? editor_data.get_edited_scene() : _next_unsaved_scene(false); - String scene_filename = editor_data.get_edited_scene_root(tab_closing)->get_filename(); - save_confirmation->get_ok()->set_text(TTR("Save & Close")); - save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene_filename != "" ? scene_filename : "unsaved scene")); - save_confirmation->popup_centered_minsize(); - break; - } else { + + if (unsaved_cache || p_option == FILE_CLOSE_ALL_AND_QUIT || p_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER) { + String scene_filename = editor_data.get_edited_scene_root(tab_closing)->get_filename(); + save_confirmation->get_ok()->set_text(TTR("Save & Close")); + save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene_filename != "" ? scene_filename : "unsaved scene")); + save_confirmation->popup_centered_minsize(); + break; + } + } else if (p_option == FILE_CLOSE) { tab_closing = editor_data.get_edited_scene(); } if (!editor_data.get_edited_scene_root(tab_closing)) { @@ -5829,6 +5874,7 @@ EditorNode::EditorNode() { Label *dock_label = memnew(Label); dock_label->set_text(TTR("Dock Position")); dock_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + dock_label->set_align(Label::ALIGN_CENTER); dock_hb->add_child(dock_label); dock_tab_move_right = memnew(ToolButton); @@ -6479,7 +6525,7 @@ EditorNode::EditorNode() { file_templates->set_mode(EditorFileDialog::MODE_OPEN_FILE); file_templates->set_access(EditorFileDialog::ACCESS_FILESYSTEM); file_templates->clear_filters(); - file_templates->add_filter("*.tpz ; Template Package"); + file_templates->add_filter("*.tpz ; " + TTR("Template Package")); file = memnew(EditorFileDialog); gui_base->add_child(file); |