diff options
Diffstat (limited to 'tools/editor/editor_node.cpp')
-rw-r--r-- | tools/editor/editor_node.cpp | 243 |
1 files changed, 192 insertions, 51 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 5a3e3069e4..c0887d7b71 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -168,6 +168,10 @@ void EditorNode::_update_title() { void EditorNode::_unhandled_input(const InputEvent& p_event) { + if (Node::get_viewport()->get_modal_stack_top()) + return; //ignore because of modal window + + if (p_event.type==InputEvent::KEY && p_event.key.pressed && !p_event.key.echo && !gui_base->get_viewport()->gui_has_modal_stack()) { @@ -182,6 +186,16 @@ void EditorNode::_unhandled_input(const InputEvent& p_event) { if (ED_IS_SHORTCUT("editor/distraction_free_mode", p_event)) { set_distraction_free_mode(!get_distraction_free_mode()); } + if (ED_IS_SHORTCUT("editor/next_tab", p_event)) { + int next_tab = editor_data.get_edited_scene() + 1; + next_tab %= editor_data.get_edited_scene_count(); + _scene_tab_changed(next_tab); + } + if (ED_IS_SHORTCUT("editor/prev_tab", p_event)) { + int next_tab = editor_data.get_edited_scene() - 1; + next_tab = next_tab >= 0 ? next_tab : editor_data.get_edited_scene_count() - 1; + _scene_tab_changed(next_tab); + } switch(p_event.key.scancode) { @@ -205,18 +219,7 @@ void EditorNode::_unhandled_input(const InputEvent& p_event) { case KEY_F6: _menu_option_confirm(RUN_PLAY_SCENE,true); break; //case KEY_F7: _menu_option_confirm(RUN_PAUSE,true); break; case KEY_F8: _menu_option_confirm(RUN_STOP,true); break;*/ - case KEY_TAB: - if (p_event.key.mod.command) { - int current_tab = editor_data.get_edited_scene(); - int tab_offset = 1; - if (p_event.key.mod.shift) - tab_offset = -1; - int next_tab = current_tab + tab_offset; - next_tab = next_tab >= 0 ? next_tab : editor_data.get_edited_scene_count() - 1; - next_tab %= editor_data.get_edited_scene_count(); - _scene_tab_changed(next_tab); - } - break; + } } @@ -505,8 +508,6 @@ void EditorNode::_rebuild_import_menu() for (int i = 0; i < editor_import_export->get_import_plugin_count(); i++) { p->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(), IMPORT_PLUGIN_BASE + i); } - //p->add_separator(); - //p->add_item(TTR("Re-Import.."), SETTINGS_IMPORT); } void EditorNode::_node_renamed() { @@ -594,7 +595,6 @@ void EditorNode::save_resource(const Ref<Resource>& p_resource) { void EditorNode::save_resource_as(const Ref<Resource>& p_resource,const String& p_at_path) { file->set_mode(EditorFileDialog::MODE_SAVE_FILE); - bool relpaths = (p_resource->has_meta("__editor_relpaths__") && p_resource->get_meta("__editor_relpaths__").operator bool()); current_option=RESOURCE_SAVE_AS; List<String> extensions; @@ -1162,7 +1162,11 @@ void EditorNode::_dialog_action(String p_file) { load_scene(p_file); } break; + case SETTINGS_PICK_MAIN_SCENE: { + Globals::get_singleton()->set("application/main_scene",p_file); + //would be nice to show the project manager opened with the hilighted field.. + } break; case FILE_SAVE_OPTIMIZED: { @@ -1544,9 +1548,10 @@ void EditorNode::_property_editor_back() { void EditorNode::_imported(Node *p_node) { - Node *scene = editor_data.get_edited_scene_root(); -// add_edited_scene(p_node); /* + Node *scene = editor_data.get_edited_scene_root(); + add_edited_scene(p_node); + if (scene) { String path = scene->get_filename(); p_node->set_filename(path); @@ -1606,6 +1611,7 @@ void EditorNode::_edit_current() { object_menu->set_disabled(true); bool is_resource = current_obj->is_type("Resource"); + bool is_node = current_obj->is_type("Node"); resource_save_button->set_disabled(!is_resource); if (is_resource) { @@ -1622,7 +1628,7 @@ void EditorNode::_edit_current() { //top_pallete->set_current_tab(1); - } else if (current_obj->is_type("Node")) { + } else if (is_node) { Node * current_node = current_obj->cast_to<Node>(); ERR_FAIL_COND(!current_node); @@ -1718,10 +1724,14 @@ void EditorNode::_edit_current() { p->add_shortcut(ED_SHORTCUT("property_editor/copy_resource",TTR("Copy Resource")),RESOURCE_COPY); p->add_shortcut(ED_SHORTCUT("property_editor/unref_resource",TTR("Make Built-In")),RESOURCE_UNREF); } - p->add_separator(); - p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique",TTR("Make Sub-Resources Unique")),OBJECT_UNIQUE_RESOURCES); - p->add_separator(); - p->add_icon_shortcut(gui_base->get_icon("Help","EditorIcons"),ED_SHORTCUT("property_editor/open_help",TTR("Open in Help")),OBJECT_REQUEST_HELP); + + if (is_resource || is_node) { + p->add_separator(); + p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique",TTR("Make Sub-Resources Unique")),OBJECT_UNIQUE_RESOURCES); + p->add_separator(); + p->add_icon_shortcut(gui_base->get_icon("Help","EditorIcons"),ED_SHORTCUT("property_editor/open_help",TTR("Open in Help")),OBJECT_REQUEST_HELP); + } + List<MethodInfo> methods; current_obj->get_method_list(&methods); @@ -1851,10 +1861,29 @@ void EditorNode::_run(bool p_current,const String& p_custom) { current_option=-1; //accept->get_cancel()->hide(); - accept->get_ok()->set_text(TTR("I see..")); - accept->set_text(TTR("No main scene has ever been defined.\nSelect one from \"Project Settings\" under the 'application' category.")); - accept->popup_centered_minsize(); + pick_main_scene->set_text(TTR("No main scene has ever been defined, select one?\nYou can change it later in later in \"Project Settings\" under the 'application' category.")); + pick_main_scene->popup_centered_minsize(); + return; + } + + if (!FileAccess::exists(run_filename)) { + + current_option=-1; + //accept->get_cancel()->hide(); + pick_main_scene->set_text(vformat(TTR("Selected scene '%s' does not exist, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), run_filename)); + pick_main_scene->popup_centered_minsize(); return; + + } + + if (ResourceLoader::get_resource_type(run_filename)!="PackedScene") { + + current_option=-1; + //accept->get_cancel()->hide(); + pick_main_scene->set_text(vformat(TTR("Selected scene '%s' is not a scene file, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), run_filename)); + pick_main_scene->popup_centered_minsize(); + return; + } } @@ -2103,7 +2132,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } file->set_mode(EditorFileDialog::MODE_SAVE_FILE); - bool relpaths = (scene->has_meta("__editor_relpaths__") && scene->get_meta("__editor_relpaths__").operator bool()); List<String> extensions; @@ -2184,8 +2212,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } - bool relpaths = (scene->has_meta("__editor_relpaths__") && scene->get_meta("__editor_relpaths__").operator bool()); - file->set_mode(EditorFileDialog::MODE_SAVE_FILE); file->set_current_path(cpath); @@ -2194,8 +2220,8 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case FILE_SAVE_OPTIMIZED: { - Node *scene = editor_data.get_edited_scene_root(); #if 0 + Node *scene = editor_data.get_edited_scene_root(); if (!scene) { current_option=-1; @@ -2468,7 +2494,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { #endif case RESOURCE_NEW: { - create_dialog->popup_centered_ratio(); + create_dialog->popup(true); } break; case RESOURCE_LOAD: { @@ -2756,10 +2782,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { settings_config_dialog->popup_edit_settings(); } break; - case SETTINGS_IMPORT: { - - import_settings->popup_import_settings(); - } break; case SETTINGS_OPTIMIZED_PRESETS: { //optimized_presets->popup_centered_ratio(); @@ -2770,6 +2792,30 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { file_templates->popup_centered_ratio(); } break; + case SETTINGS_PICK_MAIN_SCENE: { + + + //print_tree(); + file->set_mode(EditorFileDialog::MODE_OPEN_FILE); + //not for now? + List<String> extensions; + ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions); + file->clear_filters(); + for(int i=0;i<extensions.size();i++) { + + file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); + } + + + //file->set_current_path(current_path); + Node *scene = editor_data.get_edited_scene_root(); + if (scene) { + file->set_current_path(scene->get_filename()); + }; + file->set_title(TTR("Pick a Main Scene")); + file->popup_centered_ratio(); + + } break; case SETTINGS_ABOUT: { about->popup_centered(Size2(500,130)*EDSCALE); @@ -2783,10 +2829,12 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { List<Ref<Resource> > cached; ResourceCache::get_cached_resources(&cached); - + //this should probably be done in a thread.. for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) { - if (!E->get()->can_reload_from_file()) + if (!E->get()->editor_can_reload_from_file()) + continue; + if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path()) continue; if (!FileAccess::exists(E->get()->get_path())) continue; @@ -2794,6 +2842,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { if (mt!=E->get()->get_last_modified_time()) { E->get()->reload_from_file(); } + } @@ -2952,6 +3001,9 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) { //singleton->main_editor_tabs->add_tab(p_editor->get_name()); singleton->editor_table.erase(p_editor); } + p_editor->make_visible(false); + p_editor->clear(); + singleton->editor_plugins_over->get_plugins_list().erase(p_editor); singleton->remove_child(p_editor); singleton->editor_data.remove_editor_plugin( p_editor ); @@ -3004,7 +3056,7 @@ void EditorNode::set_addon_plugin_enabled(const String& p_addon,bool p_enabled) if (!p_enabled) { EditorPlugin *addon = plugin_addons[p_addon]; - editor_data.remove_editor_plugin( addon ); + remove_editor_plugin(addon); memdelete(addon); //bye plugin_addons.erase(p_addon); _update_addon_config(); @@ -3077,6 +3129,11 @@ void EditorNode::_remove_edited_scene() { new_index=1; } + + + if (editor_data.get_scene_path(old_index)!=String()) { + ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(editor_data.get_scene_path(old_index)); + } _scene_tab_changed(new_index); editor_data.remove_scene(old_index); editor_data.get_undo_redo().clear_history(); @@ -3374,7 +3431,10 @@ Dictionary EditorNode::_get_main_scene_state() { return state; } -void EditorNode::_set_main_scene_state(Dictionary p_state) { +void EditorNode::_set_main_scene_state(Dictionary p_state,Node* p_for_scene) { + + if (get_edited_scene()!=p_for_scene && p_for_scene!=NULL) + return; //not for this scene //print_line("set current 7 "); changing_scene=false; @@ -3518,7 +3578,7 @@ void EditorNode::set_current_scene(int p_idx) { }*/ //_set_main_scene_state(state); - call_deferred("_set_main_scene_state",state); //do after everything else is done setting up + call_deferred("_set_main_scene_state",state,get_edited_scene()); //do after everything else is done setting up //print_line("set current 6 "); @@ -3538,7 +3598,7 @@ void EditorNode::fix_dependencies(const String& p_for_file) { dependency_fixer->edit(p_for_file); } -Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bool p_set_inherited) { +Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bool p_set_inherited,bool p_clear_errors) { if (!is_inside_tree()) { defer_load_scene = p_scene; @@ -3557,7 +3617,9 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo } - load_errors->clear(); + if (p_clear_errors) + load_errors->clear(); + String lpath = Globals::get_singleton()->localize_path(p_scene); if (!lpath.begins_with("res://")) { @@ -3994,15 +4056,17 @@ bool EditorNode::_find_editing_changed_scene(Node *p_from) { void EditorNode::add_io_error(const String& p_error) { - CharString err_ut = p_error.utf8(); - ERR_PRINT(err_ut.get_data()); + //CharString err_ut = p_error.utf8(); + //ERR_PRINT(!err_ut.get_data()); _load_error_notify(singleton,p_error); } void EditorNode::_load_error_notify(void* p_ud,const String& p_text) { + EditorNode*en=(EditorNode*)p_ud; - en->load_errors->set_text(en->load_errors->get_text()+p_text+"\n"); + en->load_errors->add_image(en->gui_base->get_icon("Error","EditorIcons")); + en->load_errors->add_text(p_text+"\n"); en->load_error_dialog->popup_centered_ratio(0.5); } @@ -5056,6 +5120,78 @@ void EditorNode::_file_access_close_error_notify(const String& p_str) { add_io_error("Unable to write to file '"+p_str+"', file in use, locked or lacking permissions."); } + +void EditorNode::reload_scene(const String& p_path) { + + + //first of all, reload textures as they might have changed on disk + + List<Ref<Resource> > cached; + ResourceCache::get_cached_resources(&cached); + List<Ref<Resource> > to_clear; //clear internal resources from previous scene from being used + for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) { + + if (E->get()->get_path().begins_with(p_path+"::")) //subresources of existing scene + to_clear.push_back(E->get()); + + if (!E->get()->cast_to<Texture>()) + continue; + if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path()) + continue; + if (!FileAccess::exists(E->get()->get_path())) + continue; + uint64_t mt = FileAccess::get_modified_time(E->get()->get_path()); + if (mt!=E->get()->get_last_modified_time()) { + E->get()->reload_from_file(); + } + } + + //so reload reloads everything, clear subresources of previous scene + while(to_clear.front()) { + to_clear.front()->get()->set_path(""); + to_clear.pop_front(); + } + + int scene_idx=-1; + for(int i=0;i<editor_data.get_edited_scene_count();i++) { + + if (editor_data.get_scene_path(i)==p_path) { + scene_idx=i; + break; + } + } + + int current_tab = editor_data.get_edited_scene(); + + + if (scene_idx==-1) { + if (get_edited_scene()) { + //scene is not open, so at it might be instanced, just refresh, set tab to itself and it will reload + set_current_scene(current_tab); + editor_data.get_undo_redo().clear_history(); + } + return; + } + + + if (current_tab==scene_idx) { + editor_data.apply_changes_in_editors(); + _set_scene_metadata(p_path); + + } + //remove scene + _remove_scene(scene_idx); + //reload scene + load_scene(p_path); + //adjust index so tab is back a the previous position + editor_data.move_edited_scene_to_index(scene_idx); + get_undo_redo()->clear_history(); + //recover the tab + scene_tabs->set_current_tab(current_tab); + _scene_tab_changed(current_tab); +} + + void EditorNode::_bind_methods() { @@ -5499,7 +5635,10 @@ EditorNode::EditorNode() { ED_SHORTCUT("editor/fullscreen_mode",TTR("Fullscreen Mode"),KEY_MASK_SHIFT|KEY_F11); ED_SHORTCUT("editor/distraction_free_mode",TTR("Distraction Free Mode"),KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_F11); - Separator *vs=NULL; + + ED_SHORTCUT("editor/next_tab", TTR("Next tab"), KEY_MASK_CMD+KEY_TAB); + ED_SHORTCUT("editor/prev_tab", TTR("Previous tab"), KEY_MASK_CMD+KEY_MASK_SHIFT+KEY_TAB); + file_menu->set_tooltip(TTR("Operations with scene files.")); p=file_menu->get_popup(); @@ -6149,8 +6288,6 @@ EditorNode::EditorNode() { open_recent_confirmation->connect("confirmed",this,"_open_recent_scene_confirm"); - import_settings= memnew(ImportSettingsDialog(this)); - gui_base->add_child(import_settings); run_settings_dialog = memnew( RunSettingsDialog ); gui_base->add_child( run_settings_dialog ); @@ -6414,13 +6551,14 @@ EditorNode::EditorNode() { set_process_unhandled_input(true); _playing_edited=false; - load_errors = memnew( TextEdit ); - load_errors->set_readonly(true); +// Panel *errors = memnew( Panel ); + load_errors = memnew( RichTextLabel ); +// load_errors->set_readonly(true); load_error_dialog = memnew( AcceptDialog ); load_error_dialog->add_child(load_errors); load_error_dialog->set_title(TTR("Load Errors")); load_error_dialog->set_child_rect(load_errors); - add_child(load_error_dialog); + gui_base->add_child(load_error_dialog); //EditorImport::add_importer( Ref<EditorImporterCollada>( memnew(EditorImporterCollada ))); @@ -6445,7 +6583,10 @@ EditorNode::EditorNode() { Node::set_human_readable_collision_renaming(true); - + pick_main_scene = memnew( ConfirmationDialog ); + gui_base->add_child(pick_main_scene); + pick_main_scene->get_ok()->set_text("Select"); + pick_main_scene->connect("confirmed",this,"_menu_option",varray(SETTINGS_PICK_MAIN_SCENE)); // Ref<ImageTexture> it = gui_base->get_icon("logo","Icons"); // OS::get_singleton()->set_icon( it->get_data() ); |