diff options
-rw-r--r-- | tools/editor/asset_library_editor_plugin.cpp | 26 | ||||
-rw-r--r-- | tools/editor/asset_library_editor_plugin.h | 5 | ||||
-rw-r--r-- | tools/editor/editor_node.cpp | 3 | ||||
-rw-r--r-- | tools/editor/project_manager.cpp | 217 | ||||
-rw-r--r-- | tools/editor/project_manager.h | 2 |
5 files changed, 218 insertions, 35 deletions
diff --git a/tools/editor/asset_library_editor_plugin.cpp b/tools/editor/asset_library_editor_plugin.cpp index f132e94690..4f685badfb 100644 --- a/tools/editor/asset_library_editor_plugin.cpp +++ b/tools/editor/asset_library_editor_plugin.cpp @@ -444,6 +444,13 @@ void EditorAssetLibraryItemDownload::_close() { void EditorAssetLibraryItemDownload::_install() { String file = download->get_download_file(); + + if (external_install) { + emit_signal("install_asset",file,title->get_text()); + return; + } + + asset_installer->open(file,1); } @@ -465,6 +472,8 @@ void EditorAssetLibraryItemDownload::_bind_methods() { ObjectTypeDB::bind_method("_close",&EditorAssetLibraryItemDownload::_close); ObjectTypeDB::bind_method("_make_request",&EditorAssetLibraryItemDownload::_make_request); + ADD_SIGNAL(MethodInfo("install_asset",PropertyInfo(Variant::STRING,"zip_path"),PropertyInfo(Variant::STRING,"name"))); + } EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { @@ -530,6 +539,8 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { prev_status=-1; + external_install=false; + } @@ -611,6 +622,11 @@ void EditorAssetLibrary::_install_asset() { downloads_hb->add_child(download); download->configure(description->get_title(),description->get_asset_id(),description->get_preview_icon(),description->get_download_url(),description->get_sha256()); + if (templates_only) { + download->set_external_install(true); + download->connect("install_asset",this,"_install_external_asset"); + } + } const char* EditorAssetLibrary::sort_key[SORT_MAX]={ @@ -1259,6 +1275,11 @@ void EditorAssetLibrary::_manage_plugins() { +void EditorAssetLibrary::_install_external_asset(String p_zip_path,String p_title) { + + emit_signal("install_asset",p_zip_path,p_title); +} + void EditorAssetLibrary::_bind_methods() { ObjectTypeDB::bind_method("_http_request_completed",&EditorAssetLibrary::_http_request_completed); @@ -1274,6 +1295,11 @@ void EditorAssetLibrary::_bind_methods() { ObjectTypeDB::bind_method("_repository_changed",&EditorAssetLibrary::_repository_changed); ObjectTypeDB::bind_method("_support_toggled",&EditorAssetLibrary::_support_toggled); ObjectTypeDB::bind_method("_rerun_search",&EditorAssetLibrary::_rerun_search); + ObjectTypeDB::bind_method("_install_external_asset",&EditorAssetLibrary::_install_external_asset); + + + + ADD_SIGNAL(MethodInfo("install_asset",PropertyInfo(Variant::STRING,"zip_path"),PropertyInfo(Variant::STRING,"name"))); } diff --git a/tools/editor/asset_library_editor_plugin.h b/tools/editor/asset_library_editor_plugin.h index 89663aa00b..fe40255af9 100644 --- a/tools/editor/asset_library_editor_plugin.h +++ b/tools/editor/asset_library_editor_plugin.h @@ -155,6 +155,8 @@ class EditorAssetLibraryItemDownload : public PanelContainer { int asset_id; + bool external_install; + EditorAssetInstaller *asset_installer; void _close(); @@ -168,6 +170,7 @@ protected: static void _bind_methods(); public: + void set_external_install(bool p_enable) { external_install=p_enable; } int get_asset_id() { return asset_id; } void configure(const String& p_title,int p_asset_id,const Ref<Texture>& p_preview, const String& p_download_url, const String& p_sha256_hash); EditorAssetLibraryItemDownload(); @@ -301,6 +304,8 @@ class EditorAssetLibrary : public PanelContainer { void _repository_changed(int p_repository_id); void _support_toggled(int p_support); + void _install_external_asset(String p_zip_path,String p_title); + friend class EditorAssetLibraryItemDescription; friend class EditorAssetLibraryItem; protected: diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 80fadd18bd..81f9927b92 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -5856,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); diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp index 52f6d1dd9c..25d42eb601 100644 --- a/tools/editor/project_manager.cpp +++ b/tools/editor/project_manager.cpp @@ -49,17 +49,30 @@ #include "editor_initialize_ssl.h" #include "editor_scale.h" +#include "io/zip_io.h" + class NewProjectDialog : public ConfirmationDialog { OBJ_TYPE(NewProjectDialog,ConfirmationDialog); +public: + + enum Mode { + MODE_NEW, + MODE_IMPORT, + MODE_INSTALL + }; +private: - bool import_mode; + Mode mode; Label *pp,*pn; Label *error; LineEdit *project_path; LineEdit *project_name; FileDialog *fdialog; + String zip_path; + String zip_title; + AcceptDialog *dialog_error; bool _test_path() { @@ -72,7 +85,7 @@ class NewProjectDialog : public ConfirmationDialog { return false; } - if (!import_mode) { + if (mode!=MODE_IMPORT) { if (d->file_exists("engine.cfg")) { @@ -109,7 +122,7 @@ class NewProjectDialog : public ConfirmationDialog { if (lidx!=-1) { sp=sp.substr(lidx+1,sp.length()); } - if (sp=="" && import_mode ) + if (sp=="" && mode==MODE_IMPORT ) sp=TTR("Imported Project"); project_name->set_text(sp); @@ -119,7 +132,7 @@ class NewProjectDialog : public ConfirmationDialog { void _file_selected(const String& p_path) { String p = p_path; - if (import_mode) { + if (mode==MODE_IMPORT) { if (p.ends_with("engine.cfg")) { p=p.get_base_dir(); @@ -141,7 +154,7 @@ class NewProjectDialog : public ConfirmationDialog { void _browse_path() { - if (import_mode) { + if (mode==MODE_IMPORT) { fdialog->set_mode(FileDialog::MODE_OPEN_FILE); fdialog->clear_filters(); @@ -163,7 +176,7 @@ class NewProjectDialog : public ConfirmationDialog { String dir; - if (import_mode) { + if (mode==MODE_IMPORT) { dir=project_path->get_text(); @@ -179,26 +192,130 @@ class NewProjectDialog : public ConfirmationDialog { dir=d->get_current_dir(); memdelete(d); - FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE); - if (!f) { - error->set_text(TTR("Couldn't create engine.cfg in project path.")); - } else { + if (mode==MODE_NEW) { + + + + + FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE); + if (!f) { + error->set_text(TTR("Couldn't create engine.cfg in project path.")); + } else { + + f->store_line("; Engine configuration file."); + f->store_line("; It's best to edit using the editor UI, not directly,"); + f->store_line("; becausethe parameters that go here are not obvious."); + f->store_line("; "); + f->store_line("; Format: "); + f->store_line("; [section] ; section goes between []"); + f->store_line("; param=value ; assign values to parameters"); + f->store_line("\n"); + f->store_line("[application]"); + f->store_line("name=\""+project_name->get_text()+"\""); + f->store_line("icon=\"res://icon.png\""); + + memdelete(f); + + ResourceSaver::save(dir.plus_file("/icon.png"),get_icon("DefaultProjectIcon","EditorIcons")); + } + + } else if (mode==MODE_INSTALL) { + + + FileAccess *src_f=NULL; + zlib_filefunc_def io = zipio_create_io_from_file(&src_f); + + unzFile pkg = unzOpen2(zip_path.utf8().get_data(), &io); + if (!pkg) { + + dialog_error->set_text("Error opening package file, not in zip format."); + return; + } + + int ret = unzGoToFirstFile(pkg); + + Vector<String> failed_files; + + int idx=0; + while(ret==UNZ_OK) { + + //get filename + unz_file_info info; + char fname[16384]; + ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0); + + String path=fname; + + int depth=1; //stuff from github comes with tag + bool skip=false; + while(depth>0) { + int pp = path.find("/"); + if (pp==-1) { + skip=true; + break; + } + path=path.substr(pp+1,path.length()); + depth--; + } + + + if (skip || path==String()) { + // + } else if (path.ends_with("/")) { // a dir + + path=path.substr(0,path.length()-1); + + DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + da->make_dir(dir.plus_file(path)); + memdelete(da); + + } else { + + Vector<uint8_t> data; + data.resize(info.uncompressed_size); + + //read + unzOpenCurrentFile(pkg); + unzReadCurrentFile(pkg,data.ptr(),data.size()); + unzCloseCurrentFile(pkg); + + FileAccess *f=FileAccess::open(dir.plus_file(path),FileAccess::WRITE); + + if (f) { + f->store_buffer(data.ptr(),data.size()); + memdelete(f); + } else { + failed_files.push_back(path); + } + + + } + + idx++; + ret = unzGoToNextFile(pkg); + } + + unzClose(pkg); + + if (failed_files.size()) { + String msg=TTR("The following files failed extraction from package:")+"\n\n"; + for(int i=0;i<failed_files.size();i++) { + + if (i>15) { + msg+="\nAnd "+itos(failed_files.size()-i)+" more files."; + break; + } + msg+=failed_files[i]+"\n"; + } + + dialog_error->set_text(msg); + dialog_error->popup_centered_minsize(); + + } else { + dialog_error->set_text(TTR("Package Installed Successfully!")); + dialog_error->popup_centered_minsize(); + } - f->store_line("; Engine configuration file."); - f->store_line("; It's best to edit using the editor UI, not directly,"); - f->store_line("; becausethe parameters that go here are not obvious."); - f->store_line("; "); - f->store_line("; Format: "); - f->store_line("; [section] ; section goes between []"); - f->store_line("; param=value ; assign values to parameters"); - f->store_line("\n"); - f->store_line("[application]"); - f->store_line("name=\""+project_name->get_text()+"\""); - f->store_line("icon=\"res://icon.png\""); - - memdelete(f); - - ResourceSaver::save(dir.plus_file("/icon.png"),get_icon("DefaultProjectIcon","EditorIcons")); } @@ -233,10 +350,16 @@ protected: public: + void set_zip_path(const String& p_path) { + zip_path=p_path; + } + void set_zip_title(const String& p_title) { + zip_title=p_title; + } - void set_import_mode(bool p_import ) { + void set_mode(Mode p_mode) { - import_mode=p_import; + mode=p_mode; } void show_dialog() { @@ -245,7 +368,7 @@ public: project_path->clear(); project_name->clear(); - if (import_mode) { + if (mode==MODE_IMPORT) { set_title(TTR("Import Existing Project")); get_ok()->set_text(TTR("Import")); pp->set_text(TTR("Project Path (Must Exist):")); @@ -253,9 +376,10 @@ public: pn->hide(); project_name->hide(); - popup_centered(Size2(500,125)); + popup_centered(Size2(500,125)*EDSCALE); + + } else if (mode==MODE_NEW){ - } else { set_title(TTR("Create New Project")); get_ok()->set_text(TTR("Create")); pp->set_text(TTR("Project Path:")); @@ -263,7 +387,16 @@ public: pn->show(); project_name->show(); - popup_centered(Size2(500,145)); + popup_centered(Size2(500,145)*EDSCALE); + } else if (mode==MODE_INSTALL){ + + set_title(TTR("Install Project: ")+zip_title); + get_ok()->set_text(TTR("Install")); + pp->set_text(TTR("Project Path:")); + pn->hide(); + project_name->hide(); + + popup_centered(Size2(500,125)*EDSCALE); } @@ -329,7 +462,10 @@ public: fdialog->connect("dir_selected", this,"_path_selected"); fdialog->connect("file_selected", this,"_file_selected"); set_hide_on_ok(false); - import_mode=false; + mode=MODE_NEW; + + dialog_error = memnew( AcceptDialog ); + add_child(dialog_error); } @@ -616,6 +752,8 @@ void ProjectManager::_load_recent_projects() { run_btn->set_disabled(selected_list.size()<1 || (selected_list.size()==1 && single_selected_main=="")); EditorSettings::get_singleton()->save(); + + tabs->set_current_tab(0); } void ProjectManager::_open_project_confirm() { @@ -755,14 +893,14 @@ void ProjectManager::_scan_projects() { void ProjectManager::_new_project() { - npdialog->set_import_mode(false); + npdialog->set_mode(NewProjectDialog::MODE_NEW); npdialog->show_dialog(); } void ProjectManager::_import_project() { - npdialog->set_import_mode(true); + npdialog->set_mode(NewProjectDialog::MODE_IMPORT); npdialog->show_dialog(); } @@ -800,6 +938,15 @@ void ProjectManager::_exit_dialog() { get_tree()->quit(); } + +void ProjectManager::_install_project(const String& p_zip_path,const String& p_title) { + + npdialog->set_mode(NewProjectDialog::MODE_INSTALL); + npdialog->set_zip_path(p_zip_path); + npdialog->set_zip_title(p_title); + npdialog->show_dialog(); +} + void ProjectManager::_bind_methods() { ObjectTypeDB::bind_method("_open_project",&ProjectManager::_open_project); @@ -817,6 +964,7 @@ void ProjectManager::_bind_methods() { ObjectTypeDB::bind_method("_panel_draw",&ProjectManager::_panel_draw); ObjectTypeDB::bind_method("_panel_input",&ProjectManager::_panel_input); ObjectTypeDB::bind_method("_favorite_pressed",&ProjectManager::_favorite_pressed); + ObjectTypeDB::bind_method("_install_project",&ProjectManager::_install_project); } @@ -1016,6 +1164,7 @@ ProjectManager::ProjectManager() { gui_base->add_child(multi_run_ask); + asset_library->connect("install_asset",this,"_install_project"); OS::get_singleton()->set_low_processor_usage_mode(true); diff --git a/tools/editor/project_manager.h b/tools/editor/project_manager.h index 2db1bb839e..69467f50e7 100644 --- a/tools/editor/project_manager.h +++ b/tools/editor/project_manager.h @@ -88,6 +88,8 @@ class ProjectManager : public Control { void _load_recent_projects(); void _scan_dir(DirAccess *da,float pos, float total,List<String> *r_projects); + void _install_project(const String& p_zip_path,const String& p_title); + void _panel_draw(Node *p_hb); void _panel_input(const InputEvent& p_ev,Node *p_hb); void _favorite_pressed(Node *p_hb); |