diff options
Diffstat (limited to 'tools/editor/editor_node.cpp')
-rw-r--r-- | tools/editor/editor_node.cpp | 193 |
1 files changed, 161 insertions, 32 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index f6278e350a..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()) { @@ -504,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() { @@ -593,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; @@ -1161,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: { @@ -1543,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); @@ -1605,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) { @@ -1621,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); @@ -1717,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); @@ -1850,12 +1861,31 @@ 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; + + } + } @@ -2102,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; @@ -2183,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); @@ -2193,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; @@ -2467,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: { @@ -2755,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(); @@ -2769,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); @@ -2782,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; @@ -2793,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(); } + } @@ -3079,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(); @@ -3376,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; @@ -3520,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 "); @@ -5062,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() { @@ -5510,8 +5640,6 @@ EditorNode::EditorNode() { ED_SHORTCUT("editor/prev_tab", TTR("Previous tab"), KEY_MASK_CMD+KEY_MASK_SHIFT+KEY_TAB); - Separator *vs=NULL; - file_menu->set_tooltip(TTR("Operations with scene files.")); p=file_menu->get_popup(); p->add_shortcut(ED_SHORTCUT("editor/new_scene",TTR("New Scene")),FILE_NEW_SCENE); @@ -6160,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 ); @@ -6432,7 +6558,7 @@ EditorNode::EditorNode() { 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 ))); @@ -6457,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() ); |