Example #1
0
void TranslationServer::setup() {

	String test = GLOBAL_DEF("locale/test","");
	test=test.strip_edges();
	if (test!="")
		set_locale( test );
	else
		set_locale( OS::get_singleton()->get_locale() );
	fallback = GLOBAL_DEF("locale/fallback","en");
#ifdef TOOLS_ENABLED

	{
		String options="";
		int idx=0;
		while(locale_list[idx]) {
			if (idx>0)
				options+=", ";
			options+=locale_list[idx];
			idx++;
		}
		Globals::get_singleton()->set_custom_property_info("locale/fallback",PropertyInfo(Variant::STRING,"locale/fallback",PROPERTY_HINT_ENUM,options));
	}
#endif
	//load translations

}
Example #2
0
void GroupsEditor::_add_group(const String &p_group) {

	if (!node)
		return;

	String name = group_name->get_text();
	if (name.strip_edges() == "")
		return;

	if (node->is_in_group(name))
		return;

	undo_redo->create_action(TTR("Add to Group"));

	undo_redo->add_do_method(node, "add_to_group", name, true);
	undo_redo->add_do_method(this, "update_tree");
	undo_redo->add_undo_method(node, "remove_from_group", name);
	undo_redo->add_undo_method(this, "update_tree");
	undo_redo->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); //to force redraw of scene tree
	undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); //to force redraw of scene tree

	undo_redo->commit_action();

	group_name->clear();
}
Example #3
0
String OS_X11::get_system_dir(SystemDir p_dir) const {


	String xdgparam;

	switch(p_dir) {
		case SYSTEM_DIR_DESKTOP: {

			xdgparam="DESKTOP";
		} break;
		case SYSTEM_DIR_DCIM: {

			xdgparam="PICTURES";

		} break;
		case SYSTEM_DIR_DOCUMENTS: {

			xdgparam="DOCUMENTS";

		} break;
		case SYSTEM_DIR_DOWNLOADS: {

			xdgparam="DOWNLOAD";

		} break;
		case SYSTEM_DIR_MOVIES: {

			xdgparam="VIDEOS";

		} break;
		case SYSTEM_DIR_MUSIC: {

			xdgparam="MUSIC";

		} break;
		case SYSTEM_DIR_PICTURES: {

			xdgparam="PICTURES";

		} break;
		case SYSTEM_DIR_RINGTONES: {

			xdgparam="MUSIC";

		} break;
	}

	String pipe;
	List<String> arg;
	arg.push_back(xdgparam);
	Error err = const_cast<OS_X11*>(this)->execute("/usr/bin/xdg-user-dir",arg,true,NULL,&pipe);
	if (err!=OK)
		return ".";
	return pipe.strip_edges();
}
Example #4
0
void ScriptEditor::edit(const Ref<Script>& p_script) {

	if (p_script.is_null())
		return;

	// see if already has it

	if (p_script->get_path().is_resource_file() && bool(EditorSettings::get_singleton()->get("external_editor/use_external_editor"))) {

		String path = EditorSettings::get_singleton()->get("external_editor/exec_path");
		String flags = EditorSettings::get_singleton()->get("external_editor/exec_flags");
		List<String> args;
		flags=flags.strip_edges();
		if (flags!=String()) {
			Vector<String> flagss = flags.split(" ",false);
			for(int i=0;i<flagss.size();i++)
				args.push_back(flagss[i]);
		}

		args.push_back(Globals::get_singleton()->globalize_path(p_script->get_path()));
		Error err = OS::get_singleton()->execute(path,args,false);
		if (err==OK)
			return;
		WARN_PRINT("Couldn't open external text editor, using internal");
	}


	for(int i=0;i<tab_container->get_child_count();i++) {

		ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
		if (!ste)
			continue;

		if (ste->get_edited_script()==p_script) {

			if (tab_container->get_current_tab()!=i)
				tab_container->set_current_tab(i);
			ste->get_text_edit()->grab_focus();
			return;
		}
	}

	// doesn't have it, make a new one

	ScriptTextEditor *ste = memnew( ScriptTextEditor );
	ste->set_edited_script(p_script);
	ste->get_text_edit()->set_tooltip_request_func(this,"_get_debug_tooltip",ste);
	tab_container->add_child(ste);
	tab_container->set_current_tab(tab_container->get_tab_count()-1);

	_update_window_menu();
	_save_files_state();

}
Example #5
0
void GroupDialog::_add_group(String p_name) {

	String name = p_name.strip_edges();
	if (name == "" || groups->search_item_text(name)) {
		return;
	}

	TreeItem *new_group = groups->create_item(groups_root);
	new_group->set_text(0, name);
	new_group->add_button(0, get_icon("Remove", "EditorIcons"), 0);
	new_group->set_editable(0, true);
}
Error EditorSceneImporterFBXConv::_parse_fbx(State& state,const String& p_path) {

	state.base_path=p_path.get_base_dir();

	if (p_path.to_lower().ends_with("g3dj")) {
		return _parse_json(state,p_path.basename()+".g3dj");
	}

	String tool = EDITOR_DEF("fbxconv/path","");
	ERR_FAIL_COND_V( !FileAccess::exists(tool),ERR_UNCONFIGURED);
	String wine = EDITOR_DEF("fbxconv/use_wine","");

	List<String> args;
	String path=p_path;
	if (wine!="") {
		List<String> wpargs;
		wpargs.push_back("-w");
		wpargs.push_back(p_path);
		String pipe; //winepath to convert to windows path
		int wpres;
		Error wperr = OS::get_singleton()->execute(wine+"path",wpargs,true,NULL,&pipe,&wpres);
		ERR_FAIL_COND_V(wperr!=OK,ERR_CANT_CREATE);
		ERR_FAIL_COND_V(wpres!=0,ERR_CANT_CREATE);
		path=pipe.strip_edges();
		args.push_back(tool);
		tool=wine;
	}

	args.push_back("-o");
	args.push_back("G3DJ");
	args.push_back(path);

	int res;
	Error err = OS::get_singleton()->execute(tool,args,true,NULL,NULL,&res);
	ERR_FAIL_COND_V(err!=OK,ERR_CANT_CREATE);
	ERR_FAIL_COND_V(res!=0,ERR_CANT_CREATE);

	return _parse_json(state,p_path.basename()+".g3dj");


}
Example #7
0
String FindInFilesDialog::get_folder() const {
	String text = _folder_line_edit->get_text();
	return text.strip_edges();
}
Example #8
0
String FindInFilesDialog::get_search_text() const {
	String text = _search_text_line_edit->get_text();
	return text.strip_edges();
}
Example #9
0
RES ResourceFormatLoaderShader::load(const String &p_path,const String& p_original_path) {

    String fragment_code;
    String vertex_code;
    String light_code;

    int mode=-1;

    Error err;
    FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err);


    ERR_EXPLAIN("Unable to open shader file: "+p_path);
    ERR_FAIL_COND_V(err,RES());
    String base_path = p_path.get_base_dir();


    Ref<Shader> shader;//( memnew( Shader ) );

    int line=0;

    while(!f->eof_reached()) {

        String l = f->get_line();
        line++;

        if (mode<=0) {
            l = l.strip_edges();
            int comment = l.find(";");
            if (comment!=-1)
                l=l.substr(0,comment);
        }

        if (mode<1)
            vertex_code+="\n";
        if (mode<2)
            fragment_code+="\n";

        if (mode < 1 && l=="")
            continue;

        if (l.begins_with("[")) {
            l=l.strip_edges();
            if (l=="[params]") {
                if (mode>=0) {
                    memdelete(f);
                    ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [params] section.");
                    ERR_FAIL_V(RES());
                }
                mode=0;
            }  else if (l=="[vertex]") {
                if (mode>=1) {
                    memdelete(f);
                    ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [vertex] section.");
                    ERR_FAIL_V(RES());
                }
                mode=1;
            }  else if (l=="[fragment]") {
                if (mode>=2) {
                    memdelete(f);
                    ERR_EXPLAIN(p_path+":"+itos(line)+": Misplaced [fragment] section.");
                    ERR_FAIL_V(RES());
                }
                mode=1;
            } else {
                memdelete(f);
                ERR_EXPLAIN(p_path+":"+itos(line)+": Unknown section type: '"+l+"'.");
                ERR_FAIL_V(RES());
            }
            continue;
        }

        if (mode==0) {

            int eqpos = l.find("=");
            if (eqpos==-1) {
                memdelete(f);
                ERR_EXPLAIN(p_path+":"+itos(line)+": Expected '='.");
                ERR_FAIL_V(RES());
            }


            String right=l.substr(eqpos+1,l.length()).strip_edges();
            if (right=="") {
                memdelete(f);
                ERR_EXPLAIN(p_path+":"+itos(line)+": Expected value after '='.");
                ERR_FAIL_V(RES());
            }

            Variant value;

            if (right=="true") {
                value = true;
            } else if (right=="false") {
                value = false;
            } else if (right.is_valid_float()) {
                //is number
                value = right.to_double();
            } else if (right.is_valid_html_color()) {
                //is html color
                value = Color::html(right);
            } else {
                //attempt to parse a constructor
                int popenpos = right.find("(");

                if (popenpos==-1) {
                    memdelete(f);
                    ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor syntax: "+right);
                    ERR_FAIL_V(RES());
                }

                int pclosepos = right.find_last(")");

                if (pclosepos==-1) {
                    ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor parameter syntax: "+right);
                    ERR_FAIL_V(RES());

                }

                String type = right.substr(0,popenpos);
                String param = right.substr(popenpos+1,pclosepos-popenpos-1).strip_edges();


                if (type=="tex") {

                    if (param=="") {

                        value=RID();
                    } else {

                        String path;

                        if (param.is_abs_path())
                            path=param;
                        else
                            path=base_path+"/"+param;

                        Ref<Texture> texture = ResourceLoader::load(path);
                        if (!texture.is_valid()) {
                            memdelete(f);
                            ERR_EXPLAIN(p_path+":"+itos(line)+": Couldn't find icon at path: "+path);
                            ERR_FAIL_V(RES());
                        }

                        value=texture;
                    }

                } else if (type=="vec3") {

                    if (param=="") {
                        value=Vector3();
                    } else {
                        Vector<String> params = param.split(",");
                        if (params.size()!=3) {
                            memdelete(f);
                            ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid param count for vec3(): '"+right+"'.");
                            ERR_FAIL_V(RES());

                        }

                        Vector3 v;
                        for(int i=0; i<3; i++)
                            v[i]=params[i].to_double();
                        value=v;
                    }


                } else if (type=="xform") {

                    if (param=="") {
                        value=Transform();
                    } else {

                        Vector<String> params = param.split(",");
                        if (params.size()!=12) {
                            memdelete(f);
                            ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid param count for xform(): '"+right+"'.");
                            ERR_FAIL_V(RES());

                        }

                        Transform t;
                        for(int i=0; i<9; i++)
                            t.basis[i%3][i/3]=params[i].to_double();
                        for(int i=0; i<3; i++)
                            t.origin[i]=params[i-9].to_double();

                        value=t;
                    }

                } else {
                    memdelete(f);
                    ERR_EXPLAIN(p_path+":"+itos(line)+": Invalid constructor type: '"+type+"'.");
                    ERR_FAIL_V(RES());

                }

            }

            String left= l.substr(0,eqpos);

//			shader->set_param(left,value);
        } else if (mode==1) {

            vertex_code+=l;

        } else if (mode==2) {

            fragment_code+=l;
        }
    }

    shader->set_code(vertex_code,fragment_code,light_code);

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

    return shader;
}
Example #10
0
RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const String &p_path) {

	enum Status {

		STATUS_NONE,
		STATUS_READING_ID,
		STATUS_READING_STRING,
	};

	Status status = STATUS_NONE;

	String msg_id;
	String msg_str;
	String config;

	if (r_error)
		*r_error = ERR_FILE_CORRUPT;

	Ref<Translation> translation = Ref<Translation>(memnew(Translation));
	int line = 1;
	bool skip_this;
	bool skip_next;

	while (true) {

		String l = f->get_line();

		if (f->eof_reached()) {

			if (status == STATUS_READING_STRING) {

				if (msg_id != "") {
					if (!skip_this)
						translation->add_message(msg_id, msg_str);
				} else if (config == "")
					config = msg_str;
				break;

			} else if (status == STATUS_NONE)
				break;

			memdelete(f);
			ERR_EXPLAIN(p_path + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: ");
			ERR_FAIL_V(RES());
		}

		l = l.strip_edges();

		if (l.begins_with("msgid")) {

			if (status == STATUS_READING_ID) {

				memdelete(f);
				ERR_EXPLAIN(p_path + ":" + itos(line) + " Unexpected 'msgid', was expecting 'msgstr' while parsing: ");
				ERR_FAIL_V(RES());
			}

			if (msg_id != "") {
				if (!skip_this)
					translation->add_message(msg_id, msg_str);
			} else if (config == "")
				config = msg_str;

			l = l.substr(5, l.length()).strip_edges();
			status = STATUS_READING_ID;
			msg_id = "";
			msg_str = "";
			skip_this = skip_next;
			skip_next = false;
		}

		if (l.begins_with("msgstr")) {

			if (status != STATUS_READING_ID) {

				memdelete(f);
				ERR_EXPLAIN(p_path + ":" + itos(line) + " Unexpected 'msgstr', was expecting 'msgid' while parsing: ");
				ERR_FAIL_V(RES());
			}

			l = l.substr(6, l.length()).strip_edges();
			status = STATUS_READING_STRING;
		}

		if (l == "" || l.begins_with("#")) {
			if (l.find("fuzzy") != -1) {
				skip_next = true;
			}
			line++;
			continue; //nothing to read or comment
		}

		if (!l.begins_with("\"") || status == STATUS_NONE) {
			//not a string? failure!
			ERR_EXPLAIN(p_path + ":" + itos(line) + " Invalid line '" + l + "' while parsing: ");
			ERR_FAIL_V(RES());
		}

		l = l.substr(1, l.length());
		//find final quote
		int end_pos = -1;
		for (int i = 0; i < l.length(); i++) {

			if (l[i] == '"' && (i == 0 || l[i - 1] != '\\')) {
				end_pos = i;
				break;
			}
		}

		if (end_pos == -1) {
			ERR_EXPLAIN(p_path + ":" + itos(line) + " Expected '\"' at end of message while parsing file: ");
			ERR_FAIL_V(RES());
		}

		l = l.substr(0, end_pos);
		l = l.c_unescape();

		if (status == STATUS_READING_ID)
			msg_id += l;
		else
			msg_str += l;

		line++;
	}

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

	if (config == "") {
		ERR_EXPLAIN("No config found in file: " + p_path);
		ERR_FAIL_V(RES());
	}

	Vector<String> configs = config.split("\n");
	for (int i = 0; i < configs.size(); i++) {

		String c = configs[i].strip_edges();
		int p = c.find(":");
		if (p == -1)
			continue;
		String prop = c.substr(0, p).strip_edges();
		String value = c.substr(p + 1, c.length()).strip_edges();

		if (prop == "X-Language") {
			translation->set_locale(value);
		}
	}

	if (r_error)
		*r_error = OK;

	return translation;
}