Пример #1
0
/**
 * @brief Adds UI Keybindings to the list for the Keylist UI
 * @param[in,out] list Linked list of strings to add to
 */
static inline void CLMN_AddUIBindings (linkedList_t **list)
{
	int i;

	for (i = 0; i < UI_GetKeyBindingCount(); i++) {
		const uiKeyBinding_t* binding = UI_GetKeyBindingByIndex(i);

		if (binding == NULL)
			continue;
		if (binding->inherited)
			continue;
		if (!Q_strvalid(binding->description))
			continue;

		LIST_AddString(list, va("%s\t%s", Key_KeynumToString(binding->key), _(binding->description)));
	}
}
Пример #2
0
/**
 * @brief Adds UI Keybindings to the list for the Keylist UI
 */
static inline int CLMN_AddUIBindings (keyBindSpace_t scope)
{
	int cnt = 0;
	const int num = UI_GetKeyBindingCount();
	for (int i = 0; i < num; i++) {
		const uiKeyBinding_t* binding = UI_GetKeyBindingByIndex(i);
		if (binding == nullptr)
			continue;
		if (binding->inherited)
			continue;
		if (!Q_strvalid(binding->description))
			continue;

		UI_ExecuteConfunc("keybinding_add %i %i \"%s\" \"%s\"", cnt++, scope, Key_KeynumToString(binding->key), _(binding->description));
	}
	return cnt;
}
Пример #3
0
/**
 * @brief Writes lines containing "bind key value"
 * @param[in] filename Path to print the keybinding too
 * @sa Com_WriteConfigToFile
 */
void Key_WriteBindings (const char* filename)
{
	int i;
	/* this gets true in case of an error */
	qboolean deleteFile = qfalse;
	qFILE f;
	int cnt = 0;

	OBJZERO(f);
	FS_OpenFile(filename, &f, FILE_WRITE);
	if (!f.f) {
		Com_Printf("Couldn't write %s.\n", filename);
		return;
	}

	FS_Printf(&f, "// generated by ufo, do not modify\n");
	FS_Printf(&f, "// If you want to know the keyname of a specific key - set in_debug cvar to 1 and press the key\n");
	FS_Printf(&f, "unbindallmenu\n");
	FS_Printf(&f, "unbindall\n");
	FS_Printf(&f, "unbindallbattle\n");
	/* failfast, stops loop for first occurred error in fprintf */
	for (i = 0; i < K_LAST_KEY && !deleteFile; i++)
		if (menuKeyBindings[i] && menuKeyBindings[i][0]) {
			if (FS_Printf(&f, "bindmenu %s \"%s\"\n", Key_KeynumToString(i), menuKeyBindings[i]) < 0)
				deleteFile = qtrue;
			cnt++;
		}
	for (i = 0; i < K_LAST_KEY && !deleteFile; i++)
		if (keyBindings[i] && keyBindings[i][0]) {
			if (FS_Printf(&f, "bind %s \"%s\"\n", Key_KeynumToString(i), keyBindings[i]) < 0)
				deleteFile = qtrue;
			cnt++;
		}
	for (i = 0; i < K_LAST_KEY && !deleteFile; i++)
		if (battleKeyBindings[i] && battleKeyBindings[i][0]) {
			if (FS_Printf(&f, "bindbattle %s \"%s\"\n", Key_KeynumToString(i), battleKeyBindings[i]) < 0)
				deleteFile = qtrue;
			cnt++;
		}

	for (i = 0; i < UI_GetKeyBindingCount(); i++) {
		const char *path;
		uiKeyBinding_t*binding = UI_GetKeyBindingByIndex (i);
		if (binding->node == NULL)
			continue;
		if (binding->property == NULL)
			path = va("%s", UI_GetPath(binding->node));
		else
			path = va("%s@%s", UI_GetPath(binding->node), binding->property->string);

		if (FS_Printf(&f, "bindui %s \"%s\"\n", Key_KeynumToString(binding->key), path) < 0)
			deleteFile = qtrue;
	}

	FS_CloseFile(&f);
	if (!deleteFile && cnt)
		Com_Printf("Wrote %s\n", filename);
	else
		/* error in writing the keys.cfg - remove the file again */
		FS_RemoveFile(va("%s/%s", FS_Gamedir(), filename));
}