summaryrefslogtreecommitdiff
path: root/tools/editor/editor_node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/editor/editor_node.cpp')
-rw-r--r--tools/editor/editor_node.cpp182
1 files changed, 136 insertions, 46 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 84321af337..92b22eb5d1 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -508,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() {
@@ -597,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;
@@ -728,9 +725,9 @@ void EditorNode::_get_scene_metadata(const String& p_file) {
}
-void EditorNode::_set_scene_metadata(const String& p_file) {
+void EditorNode::_set_scene_metadata(const String& p_file, int p_idx) {
- Node *scene = editor_data.get_edited_scene_root();
+ Node *scene = editor_data.get_edited_scene_root(p_idx);
if (!scene)
return;
@@ -743,7 +740,7 @@ void EditorNode::_set_scene_metadata(const String& p_file) {
Ref<ConfigFile> cf;
cf.instance();
- Dictionary md = editor_data.get_editor_states();
+ Dictionary md = editor_data.get_edited_scene()==p_idx?editor_data.get_editor_states():editor_data.get_scene_editor_states(p_idx);
List<Variant> keys;
md.get_key_list(&keys);
@@ -957,9 +954,9 @@ void EditorNode::_save_scene_with_preview(String p_file) {
}
-void EditorNode::_save_scene(String p_file) {
+void EditorNode::_save_scene(String p_file, int idx) {
- Node *scene = editor_data.get_edited_scene_root();
+ Node *scene = editor_data.get_edited_scene_root(idx);
if (!scene) {
@@ -973,7 +970,7 @@ void EditorNode::_save_scene(String p_file) {
editor_data.apply_changes_in_editors();
- _set_scene_metadata(p_file);
+ _set_scene_metadata(p_file,idx);
Ref<PackedScene> sdata;
@@ -1004,7 +1001,7 @@ void EditorNode::_save_scene(String p_file) {
return;
}
- sdata->set_import_metadata(editor_data.get_edited_scene_import_metadata());
+ sdata->set_import_metadata(editor_data.get_edited_scene_import_metadata(idx));
int flg=0;
if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources"))
flg|=ResourceSaver::FLAG_COMPRESS;
@@ -1020,7 +1017,10 @@ void EditorNode::_save_scene(String p_file) {
if (err==OK) {
scene->set_filename( Globals::get_singleton()->localize_path(p_file) );
//EditorFileSystem::get_singleton()->update_file(p_file,sdata->get_type());
- set_current_version(editor_data.get_undo_redo().get_version());
+ if (idx < 0 || idx == editor_data.get_edited_scene())
+ set_current_version(editor_data.get_undo_redo().get_version());
+ else
+ editor_data.set_edited_scene_version(0,idx);
_update_title();
_update_scene_tabs();
} else {
@@ -1551,9 +1551,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);
@@ -1613,6 +1614,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) {
@@ -1629,7 +1631,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);
@@ -1725,10 +1727,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);
@@ -1807,7 +1813,6 @@ void EditorNode::_run(bool p_current,const String& p_custom) {
String args;
-
if (p_current || (editor_data.get_edited_scene_root() && p_custom==editor_data.get_edited_scene_root()->get_filename())) {
Node *scene = editor_data.get_edited_scene_root();
@@ -1830,12 +1835,7 @@ void EditorNode::_run(bool p_current,const String& p_custom) {
}
- bool autosave = EDITOR_DEF("run/auto_save_before_running",true);
- if (autosave) {
-
- _menu_option(FILE_SAVE_SCENE);
- }
if (run_settings_dialog->get_run_mode()==RunSettingsDialog::RUN_LOCAL_SCENE) {
@@ -1908,7 +1908,7 @@ void EditorNode::_run(bool p_current,const String& p_custom) {
_save_scene_with_preview(scene->get_filename());
}
}
-
+ _menu_option(FILE_SAVE_ALL_SCENES);
editor_data.save_editor_external_data();
}
@@ -2129,7 +2129,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;
@@ -2165,6 +2164,19 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
} break;
+ case FILE_SAVE_ALL_SCENES: {
+ for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
+ Node *scene = editor_data.get_edited_scene_root(i);
+ if (scene && scene->get_filename()!="") {
+ // save in background if in the script editor
+ if (i != editor_data.get_edited_scene() || _get_current_main_editor() == EDITOR_SCRIPT) {
+ _save_scene(scene->get_filename(), i);
+ } else {
+ _save_scene_with_preview(scene->get_filename());
+ }
+ }// else: ignore new scenes
+ }
+ } break;
case FILE_SAVE_BEFORE_RUN: {
if (!p_confirmed) {
accept->get_ok()->set_text(TTR("Yes"));
@@ -2210,8 +2222,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);
@@ -2220,8 +2230,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;
@@ -2494,7 +2504,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: {
@@ -2665,11 +2675,16 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
} break;
case RUN_PLAY_NATIVE: {
- _menu_option_confirm(RUN_STOP,true);
- emit_signal("play_pressed");
- editor_run.run_native_notify();
-
-
+
+ bool autosave = EDITOR_DEF("run/auto_save_before_running",true);
+ if (autosave) {
+ _menu_option_confirm(FILE_SAVE_ALL_SCENES, false);
+ }
+ if (run_native->is_deploy_debug_remote_enabled()){
+ _menu_option_confirm(RUN_STOP,true);
+ emit_signal("play_pressed");
+ editor_run.run_native_notify();
+ }
} break;
case RUN_SCENE_SETTINGS: {
@@ -2782,10 +2797,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();
@@ -2846,6 +2857,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();
}
+
}
@@ -3132,6 +3144,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();
@@ -3429,7 +3446,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;
@@ -3573,7 +3593,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 ");
@@ -5115,6 +5135,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() {
@@ -5563,8 +5655,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);
@@ -5573,6 +5663,7 @@ EditorNode::EditorNode() {
p->add_separator();
p->add_shortcut(ED_SHORTCUT("editor/save_scene",TTR("Save Scene"),KEY_MASK_CMD+KEY_S),FILE_SAVE_SCENE);
p->add_shortcut(ED_SHORTCUT("editor/save_scene_as",TTR("Save Scene As.."),KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_S),FILE_SAVE_AS_SCENE);
+ p->add_shortcut(ED_SHORTCUT("editor/save_all_scenes",TTR("Save all Scenes"),KEY_MASK_ALT+KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_S),FILE_SAVE_ALL_SCENES);
p->add_separator();
p->add_shortcut(ED_SHORTCUT("editor/close_scene",TTR("Close Scene"),KEY_MASK_SHIFT+KEY_MASK_CTRL+KEY_W),FILE_CLOSE);
p->add_separator();
@@ -5765,7 +5856,8 @@ EditorNode::EditorNode() {
play_custom_scene_button->set_focus_mode(Control::FOCUS_NONE);
play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom","EditorIcons"));
play_custom_scene_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY_CUSTOM_SCENE));
- play_custom_scene_button->set_tooltip(TTR("Play custom scene")+" ("+keycode_get_string(KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_F5)+").");
+ play_custom_scene_button->set_tooltip(TTR("Play custom scene"));
+ play_custom_scene_button->set_shortcut(ED_SHORTCUT("editor/play_custom_scene",TTR("Play Custom Scene"),KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_F5));
debug_button = memnew( MenuButton );
debug_button->set_flat(true);
@@ -6213,8 +6305,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 );