void AnimationPlayerEditor::_file_selected(String p_file) {

	ERR_FAIL_COND(!player);

	Ref<Resource> res = ResourceLoader::load(p_file,"Animation");
	ERR_FAIL_COND(res.is_null());
	ERR_FAIL_COND( !res->is_type("Animation") );
	if (p_file.find_last("/")!=-1) {

		p_file=p_file.substr( p_file.find_last("/")+1, p_file.length() );

	}
	if (p_file.find_last("\\")!=-1) {

		p_file=p_file.substr( p_file.find_last("\\")+1, p_file.length() );

	}

	if (p_file.find(".")!=-1)
		p_file=p_file.substr(0,p_file.find("."));

	undo_redo->create_action("Load Animation");
	undo_redo->add_do_method(player,"add_animation",p_file,res);
	undo_redo->add_undo_method(player,"remove_animation",p_file);
	if (player->has_animation(p_file)) {
		undo_redo->add_undo_method(player,"add_animation",p_file,player->get_animation(p_file));

	}
	undo_redo->add_do_method(this,"_animation_player_changed",player);
	undo_redo->add_undo_method(this,"_animation_player_changed",player);
	undo_redo->commit_action();

}
void AnimationPlayerEditor::_dialog_action(String p_file) {

    switch (current_option) {
    case RESOURCE_LOAD: {
        ERR_FAIL_COND(!player);

        Ref<Resource> res = ResourceLoader::load(p_file, "Animation");
        ERR_FAIL_COND(res.is_null());
        ERR_FAIL_COND(!res->is_type("Animation"));
        if (p_file.find_last("/") != -1) {

            p_file = p_file.substr(p_file.find_last("/") + 1, p_file.length());

        }
        if (p_file.find_last("\\") != -1) {

            p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length());

        }

        if (p_file.find(".") != -1)
            p_file = p_file.substr(0, p_file.find("."));

        undo_redo->create_action(TTR("Load Animation"));
        undo_redo->add_do_method(player, "add_animation", p_file, res);
        undo_redo->add_undo_method(player, "remove_animation", p_file);
        if (player->has_animation(p_file)) {
            undo_redo->add_undo_method(player, "add_animation", p_file, player->get_animation(p_file));

        }
        undo_redo->add_do_method(this, "_animation_player_changed", player);
        undo_redo->add_undo_method(this, "_animation_player_changed", player);
        undo_redo->commit_action();
        break;
    }
    case RESOURCE_SAVE: {

        String current = animation->get_item_text(animation->get_selected());
        if (current != "") {
            Ref<Animation> anim = player->get_animation(current);

            ERR_FAIL_COND(!anim->cast_to<Resource>())

            RES current_res = RES(anim->cast_to<Resource>());

            _animation_save_in_path(current_res, p_file);
        }
    }
    }
}
Example #3
0
void FileDialog::set_current_path(const String& p_path) {
	
	if (!p_path.size())
		return;
	int pos=MAX( p_path.find_last("/"), p_path.find_last("\\") );
	if (pos==-1) {
		
		set_current_file(p_path);
	} else {
		
		String dir=p_path.substr(0,pos);
		String file=p_path.substr(pos+1,p_path.length());
		set_current_dir(dir);
		set_current_file(file);
	}
}
Example #4
0
void FileDialog::set_current_file(const String &p_file) {

	file->set_text(p_file);
	update_dir();
	invalidate();
	int lp = p_file.find_last(".");
	if (lp != -1) {
		file->select(0, lp);
		file->grab_focus();
	}
}
void EditorFileDialog::set_current_file(const String& p_file) {

	file->set_text(p_file);
	update_dir();
	invalidate();
	int lp = p_file.find_last(".");
	if (lp!=-1) {
		file->select(0,lp);
		file->grab_focus();
	}

	if (is_visible())
		_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));


}
Example #6
0
String ProjectSettings::localize_path(const String &p_path) const {

	if (resource_path == "")
		return p_path; //not initialized yet

	if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
			(p_path.is_abs_path() && !p_path.begins_with(resource_path)))
		return p_path.simplify_path();

	DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);

	String path = p_path.replace("\\", "/").simplify_path();

	if (dir->change_dir(path) == OK) {

		String cwd = dir->get_current_dir();
		cwd = cwd.replace("\\", "/");

		memdelete(dir);

		if (!cwd.begins_with(resource_path)) {
			return p_path;
		};

		return cwd.replace_first(resource_path, "res:/");
	} else {

		memdelete(dir);

		int sep = path.find_last("/");
		if (sep == -1) {
			return "res://" + path;
		};

		String parent = path.substr(0, sep);

		String plocal = localize_path(parent);
		if (plocal == "") {
			return "";
		};
		return plocal + path.substr(sep, path.size() - sep);
	};
}
Example #7
0
void EditorExportPlatformAndroid::_fix_resources(Vector<uint8_t>& p_manifest) {


	const int UTF8_FLAG = 0x00000100;
	print_line("*******************GORRRGLE***********************");

	uint32_t header = decode_uint32(&p_manifest[0]);
	uint32_t filesize = decode_uint32(&p_manifest[4]);
	uint32_t string_block_len = decode_uint32(&p_manifest[16]);
	uint32_t string_count = decode_uint32(&p_manifest[20]);
	uint32_t string_flags = decode_uint32(&p_manifest[28]);
	const uint32_t string_table_begins = 40;

	Vector<String> string_table;

	printf("stirng block len: %i\n",string_block_len);
	printf("stirng count: %i\n",string_count);
	printf("flags: %x\n",string_flags);

	for(int i=0;i<string_count;i++) {

		uint32_t offset = decode_uint32(&p_manifest[string_table_begins+i*4]);
		offset+=string_table_begins+string_count*4;

		String str = _parse_string(&p_manifest[offset],string_flags&UTF8_FLAG);

		if (str.begins_with("godot-project-name")) {


			if (str=="godot-project-name") {
				//project name
				str = get_project_name();

			} else {

				String lang = str.substr(str.find_last("-")+1,str.length()).replace("-","_");
				String prop = "application/name_"+lang;
				if (Globals::get_singleton()->has(prop)) {
					str = Globals::get_singleton()->get(prop);
				} else {
					str = get_project_name();
				}
			}
		}

		string_table.push_back(str);

	}

	//write a new string table, but use 16 bits
	Vector<uint8_t> ret;
	ret.resize(string_table_begins+string_table.size()*4);

	for(int i=0;i<string_table_begins;i++) {

		ret[i]=p_manifest[i];
	}

	int ofs=0;
	for(int i=0;i<string_table.size();i++) {

		encode_uint32(ofs,&ret[string_table_begins+i*4]);
		ofs+=string_table[i].length()*2+2+2;
	}

	ret.resize(ret.size()+ofs);
	uint8_t *chars=&ret[ret.size()-ofs];
	for(int i=0;i<string_table.size();i++) {

		String s = string_table[i];
		encode_uint16(s.length(),chars);
		chars+=2;
		for(int j=0;j<s.length();j++) {
			encode_uint16(s[j],chars);
			chars+=2;
		}
		encode_uint16(0,chars);
		chars+=2;
	}

	//pad
	while(ret.size()%4)
		ret.push_back(0);

	//change flags to not use utf8
	encode_uint32(string_flags&~0x100,&ret[28]);
	//change length
	encode_uint32(ret.size()-12,&ret[16]);
	//append the rest...
	int rest_from = 12+string_block_len;
	int rest_to = ret.size();
	int rest_len = (p_manifest.size() - rest_from);
	ret.resize(ret.size() + (p_manifest.size() - rest_from) );
	for(int i=0;i<rest_len;i++) {
		ret[rest_to+i]=p_manifest[rest_from+i];
	}
	//finally update the size
	encode_uint32(ret.size(),&ret[4]);


	p_manifest=ret;
	printf("end\n");
}
void EditorAssetInstaller::open(const String& p_path,int p_depth) {


	package_path=p_path;
	Set<String> files_sorted;

	FileAccess *src_f=NULL;
	zlib_filefunc_def io = zipio_create_io_from_file(&src_f);

	unzFile pkg = unzOpen2(p_path.utf8().get_data(), &io);
	if (!pkg) {

		error->set_text("Error opening package file, not in zip format.");
		return;
	}

	int ret = unzGoToFirstFile(pkg);


	while(ret==UNZ_OK) {

		//get filename
		unz_file_info info;
		char fname[16384];
		ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0);

		String name=fname;
		files_sorted.insert(name);

		ret = unzGoToNextFile(pkg);
	}


	Map<String,Ref<Texture> > extension_guess;
	{
		extension_guess["png"]=get_icon("Texture","EditorIcons");
		extension_guess["jpg"]=get_icon("Texture","EditorIcons");
		extension_guess["tex"]=get_icon("Texture","EditorIcons");
		extension_guess["atex"]=get_icon("Texture","EditorIcons");
		extension_guess["dds"]=get_icon("Texture","EditorIcons");
		extension_guess["scn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["tscn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["xml"]=get_icon("PackedScene","EditorIcons");
		extension_guess["xscn"]=get_icon("PackedScene","EditorIcons");
		extension_guess["mtl"]=get_icon("Material","EditorIcons");
		extension_guess["shd"]=get_icon("Shader","EditorIcons");
		extension_guess["gd"]=get_icon("GDScript","EditorIcons");
	}

	Ref<Texture> generic_extension = get_icon("Object","EditorIcons");


	unzClose(pkg);

	updating=true;
	tree->clear();
	TreeItem *root=tree->create_item();
	root->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
	root->set_checked(0,true);
	root->set_icon(0,get_icon("folder","FileDialog"));
	root->set_text(0,"res://");
	root->set_editable(0,true);
	Map<String,TreeItem*> dir_map;

	for(Set<String>::Element *E=files_sorted.front();E;E=E->next()) {

		String path = E->get();
		int depth=p_depth;
		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())
			continue;

		bool isdir=false;

		if (path.ends_with("/")) {
			//a directory
			path=path.substr(0,path.length()-1);
			isdir=true;
		}

		int pp = path.find_last("/");


		TreeItem *parent;
		if (pp==-1) {
			parent=root;
		} else {
			String ppath=path.substr(0,pp);
			print_line("PPATH IS: "+ppath);
			ERR_CONTINUE(!dir_map.has(ppath));
			parent=dir_map[ppath];

		}

		TreeItem *ti = tree->create_item(parent);
		ti->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
		ti->set_checked(0,true);
		ti->set_editable(0,true);
		if (isdir) {
			dir_map[path]=ti;
			ti->set_text(0,path.get_file()+"/");
			ti->set_icon(0,get_icon("folder","FileDialog"));
		} else {
			String file = path.get_file();
			String extension = file.extension().to_lower();
			if (extension_guess.has(extension)) {
				ti->set_icon(0,extension_guess[extension]);
			} else {
				ti->set_icon(0,generic_extension);
			}
			ti->set_text(0,file);


			String res_path = "res://"+path;
			if (FileAccess::exists(res_path)) {
				ti->set_custom_color(0,Color(1,0.3,0.2));
				ti->set_tooltip(0,res_path+" (Already Exists)");
				ti->set_checked(0,false);
			} else {
				ti->set_tooltip(0,res_path);

			}

			ti->set_metadata(0,res_path);

		}

		status_map[E->get()]=ti;



	}
	popup_centered_ratio();
	updating=false;

}
void EditorFileSystem::_scan_scenes() {

	ERR_FAIL_COND(!scanning || scandir);

	//read .fscache
	HashMap<String,FileCache> file_cache;
	HashMap<String,DirCache> dir_cache;
	DirCache *dc=NULL;
	String cpath;

	sources_changed.clear();



	String project=Globals::get_singleton()->get_resource_path();
	FileAccess *f =FileAccess::open(project+"/.fscache",FileAccess::READ);

	if (f) {
		//read the disk cache
		while(!f->eof_reached()) {

			String l = f->get_line().strip_edges();
			if (l==String())
				continue;

			if (l.begins_with("::")) {
				Vector<String> split = l.split("::");
				ERR_CONTINUE( split.size() != 3);
				String name = split[1];

				dir_cache[name]=DirCache();
				dc=&dir_cache[name];
				dc->modification_time=split[2].to_int64();

				if (name!="res://") {

					cpath=name+"/";

					int sp=name.find_last("/");
					if (sp==5)
						sp=6;
					String pd = name.substr(0,sp);
					DirCache *dcp = dir_cache.getptr(pd);
					ERR_CONTINUE(!dcp);
					dcp->subdirs.insert(name.get_file());
				} else {

					cpath=name;
				}


			} else {
				Vector<String> split = l.split("::");
				ERR_CONTINUE( split.size() != 4);
				String name = split[0];
				String file;

				if (!name.begins_with("res://")) {
					file=name;
					name=cpath+name;
				} else {
					file=name.get_file();
				}

				FileCache fc;
				fc.type=split[1];
				fc.modification_time=split[2].to_int64();
				String meta = split[3].strip_edges();
				fc.meta.enabled=false;
				if (meta.find("<>")!=-1){
					Vector<String> spl = meta.split("<>");
					int sc = spl.size()-1;
					if (sc%3==0){
						fc.meta.enabled=true;
						fc.meta.import_editor=spl[0];
						fc.meta.sources.resize(sc/3);
						for(int i=0;i<fc.meta.sources.size();i++) {
							fc.meta.sources[i].path=spl[1+i*3+0];
							fc.meta.sources[i].md5=spl[1+i*3+1];
							fc.meta.sources[i].modified_time=spl[1+i*3+2].to_int64();
						}

					}

				}
				file_cache[name]=fc;

				ERR_CONTINUE(!dc);
				dc->files.insert(file);
			}

		}

		f->close();
		memdelete(f);
	}






	total=0;
	DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	//da->change_dir( Globals::get_singleton()->get_resource_path() );


	List<String> extensionsl;
	ResourceLoader::get_recognized_extensions_for_type("",&extensionsl);
	Set<String> extensions;
	for(List<String>::Element *E = extensionsl.front();E;E=E->next()) {

		extensions.insert(E->get());
	}

	EditorProgressBG scan_progress("efs","ScanFS",100);

	md_count=0;
	scandir=_scan_dir(da,extensions,"",0,1,"",file_cache,dir_cache,scan_progress);
	memdelete(da);
	if (abort_scan && scandir) {
		memdelete(scandir);
		scandir=NULL;

	}


	//save back the findings
	f=FileAccess::open(project+"/.fscache",FileAccess::WRITE);
	_save_type_cache_fs(scandir,f);
	f->close();
	memdelete(f);

	scanning=false;

}