Пример #1
0
void saveObtainedMedals()
{
	int i, medalCount;
	char medalFile[MAX_PATH_LENGTH];
	Medal *medal;
	FILE *fp;

	snprintf(medalFile, MAX_PATH_LENGTH, "%smedals", gameSavePath);

	fp = fopen(medalFile, "wb");

	if (fp == NULL)
	{
		showErrorAndExit("Could not save Medal data: %s", strerror(errno));
	}

	medalCount = getMedalCount();

	medal = getMedals();

	for (i=0;i<medalCount;i++)
	{
		if (medal[i].obtained == TRUE)
		{
			fprintf(fp, "%s\n", medal[i].code);
		}
	}

	fclose(fp);

	#if DEV == 1
		copyFile(medalFile, "medaldata");
	#endif

	compressFile(medalFile);
}
Пример #2
0
static void loadMenuLayout()
{
	Medal *medal;
	int i, width, medalCount;
	Texture *texture;

	medal = getMedals();

	medalCount = getMedalCount();

	i = 0;

	width = 0;

	menu.w = 0;

	menu.h = 0;

	menu.startY = 0;

	menu.endY = 0;

	menu.widgetCount = medalCount;

	menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount);

	if (menu.widgets == NULL)
	{
		showErrorAndExit("Ran out of memory when creating Medals Menu");
	}

	for (i=0;i<menu.widgetCount;i++)
	{
		if (medal[i].hidden == TRUE && medal[i].obtained == FALSE)
		{
			menu.widgets[i] = createWidget(_("Hidden Medal"), NULL, NULL, NULL, NULL, 10, 20 + i * 40, FALSE, 255, 255, 255);
		}

		else
		{
			if (medal[i].obtained == TRUE)
			{
				menu.widgets[i] = createWidget(_(medal[i].description), NULL, NULL, NULL, NULL, 10, 20 + i * 40, FALSE, 0, 200, 0);
			}

			else
			{
				menu.widgets[i] = createWidget(_(medal[i].description), NULL, NULL, NULL, NULL, 10, 20 + i * 40, FALSE, 255, 255, 255);
			}
		}

		if (width < menu.widgets[i]->x + menu.widgets[i]->normalState->w)
		{
			width = menu.widgets[i]->x + menu.widgets[i]->normalState->w;
		}

		texture = getMedalImage(medal[i].medalType, medal[i].obtained);

		menu.widgets[i]->label = createImageLabel(texture, menu.widgets[i]->x, menu.widgets[i]->y);

		menu.widgets[i]->label->y = menu.widgets[i]->y + menu.widgets[i]->normalState->h / 2 - menu.widgets[i]->label->text->h / 2;

		menu.endY = menu.widgets[i]->y + menu.widgets[i]->normalState->h - menu.h;
	}

	width += 15;

	menu.h = SCREEN_HEIGHT - BUTTON_PADDING;

	for (i=0;i<menu.widgetCount;i++)
	{
		if (menu.widgets[i]->label != NULL)
		{
			menu.widgets[i]->label->x = width;

			if (menu.w < menu.widgets[i]->label->x + menu.widgets[i]->label->text->w)
			{
				menu.w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w;
			}
		}
	}

	menu.background = addBorder(createSurface(menu.w, menu.h, FALSE), 255, 255, 255, 0, 0, 0);

	menu.x = (SCREEN_WIDTH - menu.background->w) / 2;
	menu.y = (SCREEN_HEIGHT - menu.background->h) / 2;
}