diff options
Diffstat (limited to 'tools/editor/editor_node.cpp')
-rw-r--r-- | tools/editor/editor_node.cpp | 379 |
1 files changed, 283 insertions, 96 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 7fa85c4476..02b0e9447a 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -61,6 +61,7 @@ #include "plugins/sprite_frames_editor_plugin.h" #include "plugins/sprite_region_editor_plugin.h" #include "plugins/canvas_item_editor_plugin.h" +#include "addon_editor_plugin.h" #include "plugins/spatial_editor_plugin.h" #include "plugins/sample_editor_plugin.h" #include "plugins/sample_library_editor_plugin.h" @@ -106,7 +107,7 @@ #include "tools/editor/io_plugins/editor_export_scene.h" #include "plugins/editor_preview_plugins.h" - +#include "editor_initialize_ssl.h" #include "script_editor_debugger.h" EditorNode *EditorNode::singleton=NULL; @@ -204,8 +205,8 @@ void EditorNode::_notification(int p_what) { log->deinit(); // do not get messages anymore } if (p_what==NOTIFICATION_PROCESS) { - - //force the whole tree viewport + + //force the whole tree viewport #if 0 { Rect2 grect = scene_root_base->get_global_rect(); @@ -274,13 +275,13 @@ void EditorNode::_notification(int p_what) { } } - + } if (p_what==NOTIFICATION_ENTER_TREE) { //MessageQueue::get_singleton()->push_call(this,"_get_scene_metadata"); - get_tree()->set_editor_hint(true); + get_tree()->set_editor_hint(true); get_tree()->get_root()->set_as_audio_listener(false); get_tree()->get_root()->set_as_audio_listener_2d(false); get_tree()->set_auto_accept_quit(false); @@ -568,12 +569,12 @@ void EditorNode::save_resource_as(const Ref<Resource>& p_resource) { void EditorNode::_menu_option(int p_option) { - + _menu_option_confirm(p_option,false); } void EditorNode::_menu_confirm_current() { - + _menu_option_confirm(current_option,true); } @@ -582,27 +583,27 @@ void EditorNode::_dialog_display_file_error(String p_file,Error p_error) { if (p_error) { - + current_option=-1; //accept->"()->hide(); accept->get_ok()->set_text("I see.."); - + switch(p_error) { - + case ERR_FILE_CANT_WRITE: { accept->set_text("Can't open file for writing: "+p_file.extension()); } break; case ERR_FILE_UNRECOGNIZED: { - + accept->set_text("File format requested unknown: "+p_file.extension()); } break; default: { - + accept->set_text("Error Saving."); }break; } - + accept->popup_centered_minsize(); } @@ -980,11 +981,6 @@ void EditorNode::_save_scene(String p_file) { editor_data.apply_changes_in_editors(); - if (editor_plugin_screen) { - scene->set_meta("__editor_plugin_screen__",editor_plugin_screen->get_name()); - } - - _set_scene_metadata(p_file); @@ -1148,10 +1144,10 @@ void EditorNode::_import(const String &p_file) { } void EditorNode::_dialog_action(String p_file) { - + switch(current_option) { - + case RESOURCE_LOAD: { RES res = ResourceLoader::load(p_file); @@ -1166,7 +1162,7 @@ void EditorNode::_dialog_action(String p_file) { push_item(res.operator->() ); - } break; + } break; case FILE_NEW_INHERITED_SCENE: { @@ -1271,23 +1267,20 @@ void EditorNode::_dialog_action(String p_file) { if (FileAccess::exists(p_file)) { ml=ResourceLoader::load(p_file,"TileSet"); - if (!file_export_lib_merge->is_pressed()) { + if (ml.is_null()) { + if (file_export_lib_merge->is_pressed()) { + current_option=-1; + //accept->get_cancel()->hide(); + accept->get_ok()->set_text("I see.."); + accept->set_text("Can't load TileSet for merging!."); + accept->popup_centered_minsize(); + return; + } + } else if (!file_export_lib_merge->is_pressed()) { ml->clear(); } - } - - if (ml.is_null()) { - - if (file_export_lib_merge->is_pressed()) { - current_option=-1; - //accept->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("Can't load TileSet for merging!."); - accept->popup_centered_minsize(); - return; - } - + } else { ml = Ref<TileSet>( memnew( TileSet )); } @@ -1452,13 +1445,13 @@ void EditorNode::_dialog_action(String p_file) { } break; default: { //save scene? - + if (file->get_mode()==FileDialog::MODE_SAVE_FILE) { //_save_scene(p_file); _save_scene_with_preview(p_file); } - + } break; } } @@ -1552,13 +1545,13 @@ void EditorNode::_property_editor_forward() { if (editor_history.next()) _edit_current(); - + } void EditorNode::_property_editor_back() { - + if (editor_history.previous()) _edit_current(); - + } @@ -1588,7 +1581,7 @@ void EditorNode::_hide_top_editors() { } void EditorNode::_edit_current() { - + uint32_t current = editor_history.get_current(); Object *current_obj = current>0 ? ObjectDB::get_instance(current) : NULL; @@ -1600,7 +1593,7 @@ void EditorNode::_edit_current() { if (!current_obj) { - + scene_tree_dock->set_selected(NULL); property_editor->edit( NULL ); object_menu->set_disabled(true); @@ -1774,7 +1767,7 @@ void EditorNode::_resource_created() { } void EditorNode::_resource_selected(const RES& p_res,const String& p_property) { - + if (p_res.is_null()) return; @@ -1967,13 +1960,13 @@ void EditorNode::_cleanup_scene() { } } - + _update_title(); #endif } void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { - + //print_line("option "+itos(p_option)+" confirm "+itos(p_confirmed)); if (!p_confirmed) //this may be a hack.. current_option=(MenuOptions)p_option; @@ -1998,12 +1991,12 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //_cleanup_scene(); - + } break; case FILE_NEW_INHERITED_SCENE: case FILE_OPEN_SCENE: { - - + + //print_tree(); file->set_mode(EditorFileDialog::MODE_OPEN_FILE); //not for now? @@ -2011,10 +2004,10 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { 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(); @@ -2023,7 +2016,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { }; file->set_title(p_option==FILE_OPEN_SCENE?"Open Scene":"Open Base Scene"); file->popup_centered_ratio(); - + } break; case FILE_QUICK_OPEN_SCENE: { @@ -2090,19 +2083,19 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { // fallthrough to save_as }; case FILE_SAVE_AS_SCENE: { - + Node *scene = editor_data.get_edited_scene_root(); - + if (!scene) { - + current_option=-1; //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done without a tree root."); accept->popup_centered_minsize(); - break; + break; } - + file->set_mode(EditorFileDialog::MODE_SAVE_FILE); bool relpaths = (scene->has_meta("__editor_relpaths__") && scene->get_meta("__editor_relpaths__").operator bool()); @@ -2115,7 +2108,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); } - + //file->set_current_path(current_path); if (scene->get_filename()!="") { file->set_current_path(scene->get_filename()); @@ -2136,7 +2129,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } file->popup_centered_ratio(); file->set_title("Save Scene As.."); - + } break; case FILE_SAVE_BEFORE_RUN: { @@ -2316,7 +2309,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case FILE_QUIT: { - + if (!p_confirmed) { @@ -2330,7 +2323,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { _menu_option_confirm(RUN_STOP,true); get_tree()->quit(); - + } break; case FILE_EXTERNAL_OPEN_SCENE: { @@ -2539,13 +2532,13 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case OBJECT_COPY_PARAMS: { - + editor_data.apply_changes_in_editors();; if (current) editor_data.copy_object_params(current); } break; case OBJECT_PASTE_PARAMS: { - + editor_data.apply_changes_in_editors();; if (current) editor_data.paste_object_params(current); @@ -2593,7 +2586,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case OBJECT_CALL_METHOD: { - + editor_data.apply_changes_in_editors();; call_dialog->set_object(current); call_dialog->popup_centered_ratio(); @@ -2671,8 +2664,9 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { String exec = OS::get_singleton()->get_executable_path(); List<String> args; - args.push_back ( "-path" ); - args.push_back (exec.get_base_dir() ); + //args.push_back ( "-path" ); + //args.push_back (exec.get_base_dir() ); + args.push_back("-pm"); OS::ProcessID pid=0; Error err = OS::get_singleton()->execute(exec,args,false,&pid); @@ -2837,7 +2831,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; default: { - + if (p_option>=OBJECT_METHOD_BASE) { ERR_FAIL_COND(!current); @@ -2861,12 +2855,12 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } } - } + } } Control* EditorNode::get_viewport() { - + return viewport; } @@ -2911,7 +2905,7 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor) { if (p_editor->has_main_screen()) { - + ToolButton *tb = memnew( ToolButton ); tb->set_toggle_mode(true); tb->connect("pressed",singleton,"_editor_select",varray(singleton->main_editor_buttons.size())); @@ -2951,16 +2945,109 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) { void EditorNode::add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) { + ERR_FAIL_COND( p_editor_import.is_null() ); editor_import_export->add_import_plugin(p_editor_import); _rebuild_import_menu(); } void EditorNode::remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) { + ERR_FAIL_COND( p_editor_import.is_null() ); editor_import_export->remove_import_plugin(p_editor_import); _rebuild_import_menu(); } + +void EditorNode::_update_addon_config() { + + if (_initializing_addons) + return; + + Vector<String> enabled_addons; + + for(Map<String,EditorPlugin*>::Element *E=plugin_addons.front();E;E=E->next()) { + enabled_addons.push_back(E->key()); + } + + if (enabled_addons.size()==0) { + Globals::get_singleton()->set("editor_plugins/enabled",Variant()); + Globals::get_singleton()->set_persisting("editor_plugins/enabled",false); + } else { + Globals::get_singleton()->set("editor_plugins/enabled",enabled_addons); + Globals::get_singleton()->set_persisting("editor_plugins/enabled",true); + } + + project_settings->queue_save(); + +} + +void EditorNode::set_addon_plugin_enabled(const String& p_addon,bool p_enabled) { + + ERR_FAIL_COND(p_enabled && plugin_addons.has(p_addon)); + ERR_FAIL_COND(!p_enabled && !plugin_addons.has(p_addon)); + + if (!p_enabled) { + + EditorPlugin *addon = plugin_addons[p_addon]; + memdelete(addon); //bye + plugin_addons.erase(p_addon); + _update_addon_config(); + return; + } + + + Ref<ConfigFile> cf; + cf.instance(); + String addon_path = "res://addons/"+p_addon+"/plugin.cfg"; + Error err = cf->load(addon_path); + if (err!=OK) { + show_warning("Unable to enable addon plugin at: '"+addon_path+"' parsing of config failed."); + return; + } + + if (!cf->has_section_key("plugin","script")) { + show_warning("Unable to find script field for addon plugin at: 'res://addons/"+p_addon+"''."); + return; + } + + String path = cf->get_value("plugin","script"); + path="res://addons/"+p_addon+"/"+path; + + Ref<Script> script = ResourceLoader::load(path); + + + if (script.is_null()) { + show_warning("Unable to load addon script from path: '"+path+"'."); + return; + } + + //could check inheritance.. + if (String(script->get_instance_base_type())!="EditorPlugin") { + show_warning("Unable to load addon script from path: '"+path+"' Base type is not EditorPlugin."); + return; + } + + if (!script->is_tool()) { + show_warning("Unable to load addon script from path: '"+path+"' Script is does not support tool mode."); + return; + } + + EditorPlugin *ep = memnew( EditorPlugin ); + ep->set_script(script.get_ref_ptr()); + plugin_addons[p_addon]=ep; + add_editor_plugin(ep); + + _update_addon_config(); + + +} + +bool EditorNode::is_addon_plugin_enabled(const String& p_addon) const { + + return plugin_addons.has(p_addon); +} + + void EditorNode::_remove_edited_scene() { int new_index = editor_data.get_edited_scene(); int old_index=new_index; @@ -3006,9 +3093,9 @@ void EditorNode::set_edited_scene(Node *p_scene) { if (get_editor_data().get_edited_scene_root()->get_parent()==scene_root) scene_root->remove_child(get_editor_data().get_edited_scene_root()); - } + } get_editor_data().set_edited_scene_root(p_scene); - + if (p_scene && p_scene->cast_to<Popup>()) p_scene->cast_to<Popup>()->show(); //show popups scene_tree_dock->set_edited_scene(p_scene); @@ -3577,7 +3664,7 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo if (p_set_inherited) { Ref<SceneState> state = sdata->get_state(); - state->set_path(lpath); + state->set_path(lpath); new_scene->set_scene_inherited_state(state); new_scene->set_filename(String()); //if (new_scene->get_scene_instance_state().is_valid()) @@ -3597,26 +3684,12 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo */ editor_data.set_edited_scene_import_metadata( sdata->get_import_metadata() ); - // editor_data.get_undo_redo().clear_history(); saved_version=editor_data.get_undo_redo().get_version(); _update_title(); _update_scene_tabs(); _add_to_recent_scenes(lpath); - if (new_scene->has_meta("__editor_plugin_screen__")) { - - String editor = new_scene->get_meta("__editor_plugin_screen__"); - - for(int i=0;i<editor_table.size();i++) { - - if (editor_table[i]->get_name()==editor) { - _editor_select(i); - break; - } - } - } - prev_scene->set_disabled(previous_scenes.size()==0); opening_prev=false; @@ -3728,7 +3801,7 @@ void EditorNode::animation_editor_make_visible(bool p_visible) { if (p_visible) { - animation_editor->show(); + animation_editor->show(); animation_vb->get_parent_control()->minimum_size_changed(); //pd_anim->show(); top_split->set_collapsed(false); @@ -3949,10 +4022,14 @@ void EditorNode::register_editor_types() { ObjectTypeDB::register_type<EditorPlugin>(); ObjectTypeDB::register_type<EditorImportPlugin>(); + ObjectTypeDB::register_type<EditorExportPlugin>(); ObjectTypeDB::register_type<EditorScenePostImport>(); ObjectTypeDB::register_type<EditorScript>(); + ObjectTypeDB::register_type<EditorSelection>(); ObjectTypeDB::register_type<EditorFileDialog>(); - ObjectTypeDB::register_type<UndoRedo>(); + //ObjectTypeDB::register_type<EditorImportExport>(); + ObjectTypeDB::register_type<EditorSettings>(); + ObjectTypeDB::register_type<EditorSpatialGizmo>(); //ObjectTypeDB::register_type<EditorImporter>(); @@ -4068,9 +4145,10 @@ Error EditorNode::export_platform(const String& p_platform, const String& p_path return OK; } -void EditorNode::show_warning(const String& p_text) { +void EditorNode::show_warning(const String& p_text, const String &p_title) { warning->set_text(p_text); + warning->set_title(p_title); warning->popup_centered_minsize(); } @@ -4146,7 +4224,7 @@ void EditorNode::_dock_popup_exit() { } void EditorNode::_dock_pre_popup(int p_which) { - + dock_popup_selected=p_which; } @@ -4355,6 +4433,51 @@ void EditorNode::_load_docks() { } + +void EditorNode::_update_dock_slots_visibility() { + + VSplitContainer*splits[DOCK_SLOT_MAX/2]={ + left_l_vsplit, + left_r_vsplit, + right_l_vsplit, + right_r_vsplit, + }; + + + HSplitContainer*h_splits[4]={ + left_l_hsplit, + left_r_hsplit, + main_hsplit, + right_hsplit, + }; + + for(int i=0;i<DOCK_SLOT_MAX;i++) { + + if (dock_slot[i]->get_tab_count()) + dock_slot[i]->show(); + else + dock_slot[i]->hide(); + + } + + + for(int i=0;i<DOCK_SLOT_MAX/2;i++) { + bool in_use = dock_slot[i*2+0]->get_tab_count() || dock_slot[i*2+1]->get_tab_count(); + if (in_use) + splits[i]->show(); + else + splits[i]->hide(); + } + + for(int i=0;i<DOCK_SLOT_MAX;i++) { + + if (!dock_slot[i]->is_hidden() && dock_slot[i]->get_tab_count()) { + dock_slot[i]->set_current_tab(0); + } + } +} + + void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String& p_section) { for(int i=0;i<DOCK_SLOT_MAX;i++) { @@ -4539,7 +4662,7 @@ void EditorNode::_scene_tab_closed(int p_tab) { } else { _remove_scene(p_tab); - //_update_scene_tabs(); + _update_scene_tabs(); } } @@ -4667,6 +4790,28 @@ void EditorNode::raise_bottom_panel_item(Control *p_item) { } +void EditorNode::remove_bottom_panel_item(Control *p_item) { + + for(int i=0;i<bottom_panel_items.size();i++) { + + if (bottom_panel_items[i].control==p_item) { + if (p_item->is_visible()) { + _bottom_panel_switch(false,0); + } + bottom_panel_vb->remove_child(bottom_panel_items[i].control); + bottom_panel_hb->remove_child(bottom_panel_items[i].button); + memdelete( bottom_panel_items[i].button ); + bottom_panel_items.remove(i); + break; + } + } + + for(int i=0;i<bottom_panel_items.size();i++) { + bottom_panel_items[i].button->disconnect("toggled",this,"_bottom_panel_switch"); + bottom_panel_items[i].button->connect("toggled",this,"_bottom_panel_switch",varray(i)); + } +} + void EditorNode::_bottom_panel_switch(bool p_enable,int p_idx) { ERR_FAIL_INDEX(p_idx,bottom_panel_items.size()); @@ -4692,6 +4837,31 @@ void EditorNode::_bottom_panel_switch(bool p_enable,int p_idx) { } } + +void EditorNode::add_control_to_dock(DockSlot p_slot,Control* p_control) { + ERR_FAIL_INDEX(p_slot,DOCK_SLOT_MAX); + dock_slot[p_slot]->add_child(p_control); + _update_dock_slots_visibility(); + +} + +void EditorNode::remove_control_from_dock(Control* p_control) { + + Control *dock=NULL; + for(int i=0;i<DOCK_SLOT_MAX;i++) { + if (p_control->get_parent()==dock_slot[i]) { + dock=dock_slot[i]; + break; + } + } + + ERR_EXPLAIN("Control was not in dock"); + ERR_FAIL_COND(!dock); + + dock->remove_child(p_control); + _update_dock_slots_visibility(); +} + void EditorNode::_bind_methods() { @@ -4781,6 +4951,8 @@ EditorNode::EditorNode() { EditorHelp::generate_doc(); //before any editor classes are crated SceneState::set_disable_placeholders(true); + editor_initialize_certificates(); //for asset sharing + InputDefault *id = Input::get_singleton()->cast_to<InputDefault>(); @@ -4797,6 +4969,7 @@ EditorNode::EditorNode() { singleton=this; last_checked_version=0; changing_scene=false; + _initializing_addons=false; FileAccess::set_backup_save(true); @@ -5692,7 +5865,7 @@ EditorNode::EditorNode() { - + call_dialog = memnew( CallDialog ); call_dialog->hide(); gui_base->add_child( call_dialog ); @@ -5745,7 +5918,7 @@ EditorNode::EditorNode() { dependency_fixer = memnew( DependencyEditor ); gui_base->add_child( dependency_fixer ); - + settings_config_dialog = memnew( EditorSettingsDialog ); gui_base->add_child(settings_config_dialog); @@ -5855,7 +6028,7 @@ EditorNode::EditorNode() { property_forward->connect("pressed", this,"_property_editor_forward"); property_back->connect("pressed", this,"_property_editor_back"); - + file_menu->get_popup()->connect("item_pressed", this,"_menu_option"); @@ -5901,6 +6074,7 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) ); add_editor_plugin( memnew( SpatialEditorPlugin(this) ) ); add_editor_plugin( memnew( ScriptEditorPlugin(this) ) ); + //add_editor_plugin( memnew( AddonEditorPlugin(this) ) ); //more visually meaningful to have this later raise_bottom_panel_item(AnimationPlayerEditor::singleton); @@ -6056,7 +6230,7 @@ EditorNode::EditorNode() { } - EditorSettings::get_singleton()->enable_plugins(); + Node::set_human_readable_collision_renaming(true); @@ -6072,13 +6246,26 @@ EditorNode::EditorNode() { editor_data.set_edited_scene(0); _update_scene_tabs(); + { + + _initializing_addons=true; + Vector<String> addons = Globals::get_singleton()->get("editor_plugins/enabled"); + + for(int i=0;i<addons.size();i++) { + set_addon_plugin_enabled(addons[i],true); + } + _initializing_addons=false; + } + + + _load_docks(); } -EditorNode::~EditorNode() { +EditorNode::~EditorNode() { memdelete( EditorHelp::get_doc_data() ); |