bool _test_path() { error->set_text(""); get_ok()->set_disabled(true); DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (project_path->get_text() != "" && d->change_dir(project_path->get_text())!=OK) { error->set_text(TTR("Invalid project path, the path must exist!")); memdelete(d); return false; } if (mode!=MODE_IMPORT) { if (d->file_exists("engine.cfg")) { error->set_text(TTR("Invalid project path, engine.cfg must not exist.")); memdelete(d); return false; } } else { if (project_path->get_text() != "" && !d->file_exists("engine.cfg")) { error->set_text(TTR("Invalid project path, engine.cfg must exist.")); memdelete(d); return false; } } memdelete(d); get_ok()->set_disabled(false); return true; }
void EditorSceneImportDialog::_browse_target() { if (save_path->get_text()!="") save_select->set_current_path(save_path->get_text()); save_select->popup_centered_ratio(); }
bool _test_path() { error->set_text(""); get_ok()->set_disabled(true); DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (project_path->get_text() != "" && d->change_dir(project_path->get_text())!=OK) { error->set_text("Invalid Path for Project, Path Must Exist!"); memdelete(d); return false; } if (!import_mode) { if (d->file_exists("engine.cfg")) { error->set_text("Invalid Project Path (engine.cfg must not exist)."); memdelete(d); return false; } } else { if (project_path->get_text() != "" && !d->file_exists("engine.cfg")) { error->set_text("Invalid Project Path (engine.cfg must exist)."); memdelete(d); return false; } } memdelete(d); get_ok()->set_disabled(false); return true; }
void _import() { Vector<String> samples = import_path->get_text().split(","); if (samples.size()==0) { error_dialog->set_text(TTR("No samples to import!")); error_dialog->popup_centered(Size2(200,100)); } if (save_path->get_text().strip_edges()=="") { error_dialog->set_text(TTR("Target path is empty.")); error_dialog->popup_centered_minsize(); return; } if (!save_path->get_text().begins_with("res://")) { error_dialog->set_text(TTR("Target path must be full resource path.")); error_dialog->popup_centered_minsize(); return; } if (!DirAccess::exists(save_path->get_text())) { error_dialog->set_text(TTR("Target path must exist.")); error_dialog->popup_centered_minsize(); return; } for(int i=0;i<samples.size();i++) { Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); List<PropertyInfo> pl; options->_get_property_list(&pl); for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) { Variant v; String opt=E->get().name; options->_get(opt,v); imd->set_option(opt,v); } imd->add_source(EditorImportPlugin::validate_source_path(samples[i])); String dst = save_path->get_text(); if (dst=="") { error_dialog->set_text(TTR("Save path is empty!")); error_dialog->popup_centered(Size2(200,100)); } dst = dst.plus_file(samples[i].get_file().basename()+".smp"); Error err = plugin->import(dst,imd); } hide(); }
void _import() { Vector<String> bitmasks = import_path->get_text().split(","); if (bitmasks.size() == 0) { error_dialog->set_text(TTR("No bit masks to import!")); error_dialog->popup_centered(Size2(200, 100)*EDSCALE); } if (save_path->get_text().strip_edges() == "") { error_dialog->set_text(TTR("Target path is empty.")); error_dialog->popup_centered_minsize(); return; } if (!save_path->get_text().begins_with("res://")) { error_dialog->set_text(TTR("Target path must be a complete resource path.")); error_dialog->popup_centered_minsize(); return; } if (!DirAccess::exists(save_path->get_text())) { error_dialog->set_text(TTR("Target path must exist.")); error_dialog->popup_centered_minsize(); return; } for (int i = 0; i<bitmasks.size(); i++) { Ref<ResourceImportMetadata> imd = memnew(ResourceImportMetadata); imd->add_source(EditorImportPlugin::validate_source_path(bitmasks[i])); String dst = save_path->get_text(); if (dst == "") { error_dialog->set_text(TTR("Save path is empty!")); error_dialog->popup_centered(Size2(200, 100)*EDSCALE); } dst = dst.plus_file(bitmasks[i].get_file().get_basename() + ".pbm"); plugin->import(dst, imd); } hide(); }
String _test_path() { error->set_text(""); get_ok()->set_disabled(true); DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String valid_path; if (d->change_dir(project_path->get_text())==OK){ valid_path=project_path->get_text(); } else if (d->change_dir(project_path->get_text().strip_edges())==OK) { valid_path=project_path->get_text().strip_edges(); } if (valid_path == "") { error->set_text(TTR("Invalid project path, the path must exist!")); memdelete(d); return ""; } if (mode!=MODE_IMPORT) { if (d->file_exists("godot.cfg")) { error->set_text(TTR("Invalid project path, godot.cfg must not exist.")); memdelete(d); return ""; } } else { if (valid_path != "" && !d->file_exists("godot.cfg")) { error->set_text(TTR("Invalid project path, godot.cfg must exist.")); memdelete(d); return ""; } } memdelete(d); get_ok()->set_disabled(false); return valid_path; }
void _import() { if (items.size()==0) { error_dialog->set_text(TTR("No items to import!")); error_dialog->popup_centered(Size2(200,100)); } if (!save_path->get_text().begins_with("res://")) { error_dialog->set_text(TTR("No target path!")); error_dialog->popup_centered(Size2(200,100)); } EditorProgress progress("import_xl",TTR("Import Translations"),items.size()); for(int i=0;i<items.size();i++) { progress.step(items[i]->get_metadata(1),i); if (!items[i]->is_checked(0)) continue; String locale = TranslationServer::get_all_locales()[items[i]->get_range(1)]; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); imd->add_source(EditorImportPlugin::validate_source_path(import_path->get_text())); imd->set_option("locale",locale); imd->set_option("index",i); imd->set_option("skip_first",ignore_first->is_pressed()); imd->set_option("compress",compress->is_pressed()); String savefile = save_path->get_text().plus_file(import_path->get_text().get_file().basename()+"."+locale+".xl"); Error err = plugin->import(savefile,imd); if (err!=OK) { error_dialog->set_text(TTR("Couldn't import!")); error_dialog->popup_centered(Size2(200,100)); } else if (add_to_project->is_pressed()) { ProjectSettings::get_singleton()->add_translation(savefile); } } hide(); }
void _import() { Vector<String> meshes = import_path->get_text().split(","); if (meshes.size()==0) { error_dialog->set_text(TTR("No meshes to import!")); error_dialog->popup_centered_minsize(); return; } String dst = save_path->get_text(); if (dst=="") { error_dialog->set_text(TTR("Save path is empty!")); error_dialog->popup_centered_minsize(); return; } for(int i=0;i<meshes.size();i++) { Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); List<PropertyInfo> pl; options->_get_property_list(&pl); for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) { Variant v; String opt=E->get().name; options->_get(opt,v); imd->set_option(opt,v); } imd->add_source(EditorImportPlugin::validate_source_path(meshes[i])); String file_path = dst.plus_file(meshes[i].get_file().get_basename()+".msh"); plugin->import(file_path,imd); } hide(); }
void EditorSceneImportDialog::_import(bool p_and_open) { wip_open=p_and_open; //' ImportMonitorBlock imb; if (import_path->get_text()=="") { error_dialog->set_text("Source path is empty."); error_dialog->popup_centered(Size2(200,100)); return; } if (save_path->get_text()=="") { error_dialog->set_text("Target path is empty."); error_dialog->popup_centered(Size2(200,100)); return; } String dst_path; if (texture_action->get_selected()==0) dst_path=save_path->get_text();//.get_base_dir(); else dst_path=Globals::get_singleton()->get("import/shared_textures"); uint32_t flags=0; for(int i=0;i<scene_flags.size();i++) { if (scene_flags[i]->is_checked(0)) { int md = scene_flags[i]->get_metadata(0); flags|=md; } } Ref<EditorScenePostImport> pi; if (script_path->get_text()!="") { Ref<Script> scr = ResourceLoader::load(script_path->get_text()); if (!scr.is_valid()) { error_dialog->set_text("Couldn't load Post-Import Script."); error_dialog->popup_centered(Size2(200,100)); return; } pi = Ref<EditorScenePostImport>( memnew( EditorScenePostImport ) ); pi->set_script(scr.get_ref_ptr()); if (!pi->get_script_instance()) { error_dialog->set_text("Invalid/Broken Script for Post-Import."); error_dialog->popup_centered(Size2(200,100)); return; } } String save_file = save_path->get_text().plus_file(import_path->get_text().get_file().basename()+".scn"); print_line("Saving to: "+save_file); Node *scene=NULL; Ref<ResourceImportMetadata> rim = memnew( ResourceImportMetadata ); rim->add_source(EditorImportPlugin::validate_source_path(import_path->get_text())); rim->set_option("flags",flags); rim->set_option("texture_flags",texture_options->get_flags()); rim->set_option("texture_format",texture_options->get_format()); rim->set_option("texture_quality",texture_options->get_quality()); rim->set_option("animation_flags",animation_options->get_flags()); rim->set_option("post_import_script",script_path->get_text()!=String()?EditorImportPlugin::validate_source_path(script_path->get_text()):String()); rim->set_option("reimport",true); List<String> missing; Error err = plugin->import1(rim,&scene,&missing); if (err) { error_dialog->set_text("Error importing scene."); error_dialog->popup_centered(Size2(200,100)); return; } if (missing.size()) { missing_files->clear(); for(List<String>::Element *E=missing.front();E;E=E->next()) { missing_files->add_text(E->get()); missing_files->add_newline(); } wip_import=scene; wip_rimd=rim; wip_save_file=save_file; confirm_import->popup_centered_ratio(); return; } else { err = plugin->import2(scene,save_file,rim); if (err) { error_dialog->set_text("Error importing scene."); error_dialog->popup_centered(Size2(200,100)); return; } if (wip_open) EditorNode::get_singleton()->load_scene(save_file); } hide(); /* editor->clear_scene(); Error err = EditorImport::import_scene(import_path->get_text(),save_file,dst_path,flags,texture_options->get_format(),compression,texture_options->get_flags(),texture_options->get_quality(),animation_options->get_flags(), &scene,pi); if (err) { error_dialog->set_text("Error importing scene."); error_dialog->popup_centered(Size2(200,100)); return; } editor->save_import_export(); if (scene) editor->set_edited_scene(scene); hide(); */ };
void ok_pressed() { if (!_test_path()) return; String dir; if (import_mode) { dir=project_path->get_text(); } else { DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (d->change_dir(project_path->get_text())!=OK) { error->set_text("Invalid Path for Project (changed anything?)"); memdelete(d); return; } dir=d->get_current_dir(); memdelete(d); FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE); if (!f) { error->set_text("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=\"icon.png\""); memdelete(f); ResourceSaver::save(dir.plus_file("/icon.png"),get_icon("DefaultProjectIcon","EditorIcons")); } } dir=dir.replace("\\","/"); if (dir.ends_with("/")) dir=dir.substr(0,dir.length()-1); String proj=dir.replace("/","::"); EditorSettings::get_singleton()->set("projects/"+proj,dir); EditorSettings::get_singleton()->save(); hide(); emit_signal("project_created"); }
void _update_text() { test_label->set_text(""); test_label->set_text(test_string->get_text()); test_label->add_color_override("font_color",test_color->get_color()); }
void ok_pressed() { if (!_test_path()) return; String dir; if (mode==MODE_IMPORT) { dir=project_path->get_text(); } else { DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (d->change_dir(project_path->get_text())!=OK) { error->set_text(TTR("Invalid project path (changed anything?).")); memdelete(d); return; } dir=d->get_current_dir(); memdelete(d); 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 edited using the editor UI and not directly,"); f->store_line("; since the parameters that go here are not all 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("\n"); 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(); } } } dir=dir.replace("\\","/"); if (dir.ends_with("/")) dir=dir.substr(0,dir.length()-1); String proj=dir.replace("/","::"); EditorSettings::get_singleton()->set("projects/"+proj,dir); EditorSettings::get_singleton()->save(); hide(); emit_signal("project_created"); }
void EditorTextureImportDialog::_import() { // ImportMonitorBlock imb; Vector<String> files=import_path->get_text().split(","); if (!files.size()) { error_dialog->set_text("Please specify some files!"); error_dialog->popup_centered(Size2(200,100)); return; } String dst_path=save_path->get_text(); if (save_path->get_text().strip_edges()=="") { error_dialog->set_text("Target path is empty."); error_dialog->popup_centered_minsize(); return; } if (!save_path->get_text().begins_with("res://")) { error_dialog->set_text("Target path must be full resource path."); error_dialog->popup_centered_minsize(); return; } if (!atlas && !large && !DirAccess::exists(save_path->get_text())) { error_dialog->set_text("Target path must exist."); error_dialog->popup_centered_minsize(); return; } if (atlas) { //atlas if (files.size()==0) { error_dialog->set_text("At least one file needed for Atlas."); error_dialog->popup_centered(Size2(200,100)); return; } String dst_file = dst_path; //dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); for(int i=0;i<files.size();i++) { imd->add_source(EditorImportPlugin::validate_source_path(files[i])); } imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",true); imd->set_option("atlas_size",int(size->get_val())); imd->set_option("large",false); imd->set_option("crop",crop_source->is_pressed()); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } else if (large) { //atlas if (files.size()!=1) { error_dialog->set_text("Only one file is required for large texture"); error_dialog->popup_centered(Size2(200,100)); return; } String dst_file = dst_path; //dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); for(int i=0;i<files.size();i++) { imd->add_source(EditorImportPlugin::validate_source_path(files[i])); } imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",false); imd->set_option("large",true); imd->set_option("large_cell_size",int(size->get_val())); imd->set_option("crop",crop_source->is_pressed()); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } else { for(int i=0;i<files.size();i++) { String dst_file = dst_path.plus_file(files[i].get_file()); dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); imd->add_source(EditorImportPlugin::validate_source_path(files[i])); imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",false); imd->set_option("large",false); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } } hide(); }
void EditorTextureImportDialog::_import() { // ImportMonitorBlock imb; Vector<String> files=import_path->get_text().split(","); if (!files.size()) { error_dialog->set_text("Please specify some files!"); error_dialog->popup_centered(Size2(200,100)); return; } String dst_path=save_path->get_text(); if (dst_path.empty()) { error_dialog->set_text("Please specify a valid target import path!"); error_dialog->popup_centered(Size2(200,100)); return; } if (atlas) { //atlas if (files.size()==0) { error_dialog->set_text("At least one file needed for Atlas."); error_dialog->popup_centered(Size2(200,100)); return; } String dst_file = dst_path; //dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); for(int i=0;i<files.size();i++) { imd->add_source(EditorImportPlugin::validate_source_path(files[i])); } imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",true); imd->set_option("crop",crop_source->is_pressed()); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } else { for(int i=0;i<files.size();i++) { String dst_file = dst_path.plus_file(files[i].get_file()); dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); imd->add_source(EditorImportPlugin::validate_source_path(files[i])); imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",false); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } } hide(); }