diff options
Diffstat (limited to 'tools/editor/editor_node.cpp')
-rw-r--r-- | tools/editor/editor_node.cpp | 236 |
1 files changed, 212 insertions, 24 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 7fa85c4476..24df4544ec 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" @@ -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); @@ -2671,8 +2667,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); @@ -2951,16 +2948,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; @@ -3597,26 +3687,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; @@ -3949,10 +4025,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>(); @@ -4355,6 +4435,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 +4664,7 @@ void EditorNode::_scene_tab_closed(int p_tab) { } else { _remove_scene(p_tab); - //_update_scene_tabs(); + _update_scene_tabs(); } } @@ -4667,6 +4792,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 +4839,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() { @@ -4782,6 +4954,7 @@ EditorNode::EditorNode() { EditorHelp::generate_doc(); //before any editor classes are crated SceneState::set_disable_placeholders(true); + InputDefault *id = Input::get_singleton()->cast_to<InputDefault>(); if (id) { @@ -4797,6 +4970,7 @@ EditorNode::EditorNode() { singleton=this; last_checked_version=0; changing_scene=false; + _initializing_addons=false; FileAccess::set_backup_save(true); @@ -5901,6 +6075,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 +6231,7 @@ EditorNode::EditorNode() { } - EditorSettings::get_singleton()->enable_plugins(); + Node::set_human_readable_collision_renaming(true); @@ -6072,6 +6247,19 @@ 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(); |