Exemplo n.º 1
0
void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) {

	if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) {
		PoolStringArray arr = get_script_instance()->call("get_breakpoints");
		for (int i = 0; i < arr.size(); i++)
			p_breakpoints->push_back(arr[i]);
	}
}
Exemplo n.º 2
0
void ProjectManager::_files_dropped(PoolStringArray p_files, int p_screen) {
	Set<String> folders_set;
	DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	for (int i = 0; i < p_files.size(); i++) {
		String file = p_files[i];
		folders_set.insert(da->dir_exists(file) ? file : file.get_base_dir());
	}
	memdelete(da);
	if (folders_set.size()>0) {
		PoolStringArray folders;
		for (Set<String>::Element *E=folders_set.front();E;E=E->next()) {
			folders.append(E->get());
		}

		bool confirm = true;
		if (folders.size()==1) {
			DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
			if (dir->change_dir(folders[0])==OK) {
				dir->list_dir_begin();
				String file = dir->get_next();
				while(confirm && file!=String()) {
					if (!dir->current_is_dir() && file.ends_with("godot.cfg")) {
						confirm = false;
					}
					file = dir->get_next();
				}
				dir->list_dir_end();
			}
			memdelete(dir);
		}
		if (confirm) {
			multi_scan_ask->get_ok()->disconnect("pressed", this, "_scan_multiple_folders");
			multi_scan_ask->get_ok()->connect("pressed", this, "_scan_multiple_folders", varray(folders));
			multi_scan_ask->set_text(vformat(TTR("You are about the scan %s folders for existing Godot projects. Do you confirm?"), folders.size()));
			multi_scan_ask->popup_centered_minsize();
		} else {
			_scan_multiple_folders(folders);
		}
	}
}
Exemplo n.º 3
0
void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {

	if (get_script_instance() && get_script_instance()->has_method("get_dependencies")) {
		PoolStringArray deps = get_script_instance()->call("get_dependencies", p_path, p_add_types);

		{
			PoolStringArray::Read r = deps.read();
			for (int i = 0; i < deps.size(); ++i) {
				p_dependencies->push_back(r[i]);
			}
		}
	}
}
Exemplo n.º 4
0
void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const {

	if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) {
		PoolStringArray exts = get_script_instance()->call("get_recognized_extensions");

		{
			PoolStringArray::Read r = exts.read();
			for (int i = 0; i < exts.size(); ++i) {
				p_extensions->push_back(r[i]);
			}
		}
	}
}
Exemplo n.º 5
0
void PluginScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
	if (_desc.debug_get_globals) {
		PoolStringArray locals;
		Array values;
		_desc.debug_get_globals(_data, (godot_pool_string_array *)&locals, (godot_array *)&values, p_max_subitems, p_max_depth);
		for (int i = 0; i < locals.size(); i++) {
			p_locals->push_back(locals[i]);
		}
		for (int i = 0; i < values.size(); i++) {
			p_values->push_back(values[i]);
		}
	}
}
Exemplo n.º 6
0
void PluginScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
	if (_desc.debug_get_stack_level_members) {
		PoolStringArray members;
		Array values;
		_desc.debug_get_stack_level_members(_data, p_level, (godot_pool_string_array *)&members, (godot_array *)&values, p_max_subitems, p_max_depth);
		for (int i = 0; i < members.size(); i++) {
			p_members->push_back(members[i]);
		}
		for (int i = 0; i < values.size(); i++) {
			p_values->push_back(values[i]);
		}
	}
}
Exemplo n.º 7
0
Variant EditorAutoloadSettings::get_drag_data_fw(const Point2& p_point, Control *p_control) {

	if (autoload_cache.size() <= 1)
		return false;

	PoolStringArray autoloads;

	TreeItem *next = tree->get_next_selected(NULL);

	while (next) {
		autoloads.push_back(next->get_text(0));
		next = tree->get_next_selected(next);
	}

	if (autoloads.size() == 0 || autoloads.size() == autoload_cache.size())
		return Variant();

	VBoxContainer *preview = memnew( VBoxContainer );

	int max_size = MIN(PREVIEW_LIST_MAX_SIZE, autoloads.size());

	for (int i = 0; i < max_size; i++) {
		Label *label = memnew( Label(autoloads[i]) );
		label->set_self_modulate(Color(1,1,1,Math::lerp(1, 0, float(i)/PREVIEW_LIST_MAX_SIZE)));

		preview->add_child(label);
	}

	tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
	tree->set_drag_preview(preview);

	Dictionary drop_data;
	drop_data["type"] = "autoload";
	drop_data["autoloads"] = autoloads;

	return drop_data;
}
Exemplo n.º 8
0
bool PluginScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const {
	PoolStringArray functions;
	if (_desc.validate) {
		bool ret = _desc.validate(
				_data,
				(godot_string *)&p_script,
				&r_line_error,
				&r_col_error,
				(godot_string *)&r_test_error,
				(godot_string *)&p_path,
				(godot_pool_string_array *)&functions);
		for (int i = 0; i < functions.size(); i++) {
			r_functions->push_back(functions[i]);
		}
		return ret;
	}
	return true;
}
Exemplo n.º 9
0
void EditorAutoloadSettings::drop_data_fw(const Point2& p_point, const Variant& p_data, Control *p_control) {

	TreeItem *ti = tree->get_item_at_pos(p_point);

	if (!ti)
		return;

	int section = tree->get_drop_section_at_pos(p_point);

	if (section < -1)
		return;

	String name;
	bool move_to_back = false;

	if (section < 0) {
		name = ti->get_text(0);
	} else if (ti->get_next()) {
		name = ti->get_next()->get_text(0);
	} else {
		name = ti->get_text(0);
		move_to_back = true;
	}

	int order = GlobalConfig::get_singleton()->get_order("autoload/" + name);

	AutoLoadInfo aux;
	List<AutoLoadInfo>::Element *E = NULL;

	if (!move_to_back) {
		aux.order = order;
		E = autoload_cache.find(aux);
	}

	Dictionary drop_data = p_data;
	PoolStringArray autoloads = drop_data["autoloads"];

	Vector<int> orders;
	orders.resize(autoload_cache.size());

	for (int i = 0; i < autoloads.size(); i++) {
		aux.order = GlobalConfig::get_singleton()->get_order("autoload/" + autoloads[i]);

		List<AutoLoadInfo>::Element *I = autoload_cache.find(aux);

		if (move_to_back) {
			autoload_cache.move_to_back(I);
		} else if (E != I) {
			autoload_cache.move_before(I, E);
		} else if (E->next()) {
			E = E->next();
		} else {
			break;
		}
	}

	int i = 0;

	for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) {
		orders[i++] = E->get().order;
	}

	orders.sort();

	UndoRedo *undo_redo = EditorNode::get_undo_redo();

	undo_redo->create_action(TTR("Rearrange Autoloads"));

	i = 0;

	for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) {
		undo_redo->add_do_method(GlobalConfig::get_singleton(), "set_order", E->get().name, orders[i++]);
		undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_order", E->get().name, E->get().order);
	}

	orders.clear();

	undo_redo->add_do_method(this, "update_autoload");
	undo_redo->add_undo_method(this, "update_autoload");

	undo_redo->add_do_method(this, "emit_signal", autoload_changed);
	undo_redo->add_undo_method(this, "emit_signal", autoload_changed);

	undo_redo->commit_action();
}
Exemplo n.º 10
0
Variant _jobject_to_variant(JNIEnv *env, jobject obj) {

	if (obj == NULL) {
		return Variant();
	}

	jclass c = env->GetObjectClass(obj);
	bool array;
	String name = _get_class_name(env, c, &array);
	//print_line("name is " + name + ", array "+Variant(array));

	print_line("ARGNAME: " + name);
	if (name == "java.lang.String") {

		return String::utf8(env->GetStringUTFChars((jstring)obj, NULL));
	};

	if (name == "[Ljava.lang.String;") {

		jobjectArray arr = (jobjectArray)obj;
		int stringCount = env->GetArrayLength(arr);
		//print_line("String array! " + String::num(stringCount));
		PoolVector<String> sarr;

		for (int i = 0; i < stringCount; i++) {
			jstring string = (jstring)env->GetObjectArrayElement(arr, i);
			sarr.push_back(String::utf8(env->GetStringUTFChars(string, NULL)));
			env->DeleteLocalRef(string);
		}

		return sarr;
	};

	if (name == "java.lang.Boolean") {

		jmethodID boolValue = env->GetMethodID(c, "booleanValue", "()Z");
		bool ret = env->CallBooleanMethod(obj, boolValue);
		return ret;
	};

	if (name == "java.lang.Integer") {

		jclass nclass = env->FindClass("java/lang/Number");
		jmethodID intValue = env->GetMethodID(nclass, "intValue", "()I");
		int ret = env->CallIntMethod(obj, intValue);
		return ret;
	};

	if (name == "[I") {

		jintArray arr = (jintArray)obj;
		int fCount = env->GetArrayLength(arr);
		PoolVector<int> sarr;
		sarr.resize(fCount);

		PoolVector<int>::Write w = sarr.write();
		env->GetIntArrayRegion(arr, 0, fCount, w.ptr());
		w = PoolVector<int>::Write();
		return sarr;
	};

	if (name == "[B") {

		jbyteArray arr = (jbyteArray)obj;
		int fCount = env->GetArrayLength(arr);
		PoolVector<uint8_t> sarr;
		sarr.resize(fCount);

		PoolVector<uint8_t>::Write w = sarr.write();
		env->GetByteArrayRegion(arr, 0, fCount, reinterpret_cast<signed char *>(w.ptr()));
		w = PoolVector<uint8_t>::Write();
		return sarr;
	};

	if (name == "java.lang.Float" || name == "java.lang.Double") {

		jclass nclass = env->FindClass("java/lang/Number");
		jmethodID doubleValue = env->GetMethodID(nclass, "doubleValue", "()D");
		double ret = env->CallDoubleMethod(obj, doubleValue);
		return ret;
	};

	if (name == "[D") {

		jdoubleArray arr = (jdoubleArray)obj;
		int fCount = env->GetArrayLength(arr);
		PoolRealArray sarr;
		sarr.resize(fCount);

		PoolRealArray::Write w = sarr.write();

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

			double n;
			env->GetDoubleArrayRegion(arr, i, 1, &n);
			w.ptr()[i] = n;
		};
		return sarr;
	};

	if (name == "[F") {

		jfloatArray arr = (jfloatArray)obj;
		int fCount = env->GetArrayLength(arr);
		PoolRealArray sarr;
		sarr.resize(fCount);

		PoolRealArray::Write w = sarr.write();

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

			float n;
			env->GetFloatArrayRegion(arr, i, 1, &n);
			w.ptr()[i] = n;
		};
		return sarr;
	};

	if (name == "[Ljava.lang.Object;") {

		jobjectArray arr = (jobjectArray)obj;
		int objCount = env->GetArrayLength(arr);
		Array varr;

		for (int i = 0; i < objCount; i++) {
			jobject jobj = env->GetObjectArrayElement(arr, i);
			Variant v = _jobject_to_variant(env, jobj);
			varr.push_back(v);
			env->DeleteLocalRef(jobj);
		}

		return varr;
	};

	if (name == "java.util.HashMap" || name == "org.godotengine.godot.Dictionary") {

		Dictionary ret;
		jclass oclass = c;
		jmethodID get_keys = env->GetMethodID(oclass, "get_keys", "()[Ljava/lang/String;");
		jobjectArray arr = (jobjectArray)env->CallObjectMethod(obj, get_keys);

		PoolStringArray keys = _jobject_to_variant(env, arr);
		env->DeleteLocalRef(arr);

		jmethodID get_values = env->GetMethodID(oclass, "get_values", "()[Ljava/lang/Object;");
		arr = (jobjectArray)env->CallObjectMethod(obj, get_values);

		Array vals = _jobject_to_variant(env, arr);
		env->DeleteLocalRef(arr);

		//print_line("adding " + String::num(keys.size()) + " to Dictionary!");
		for (int i = 0; i < keys.size(); i++) {

			ret[keys[i]] = vals[i];
		};

		return ret;
	};

	env->DeleteLocalRef(c);

	return Variant();
}
Exemplo n.º 11
0
void ProjectManager::_scan_multiple_folders(PoolStringArray p_files)
{
	for (int i = 0; i < p_files.size(); i++) {
		_scan_begin(p_files.get(i));
	}
}