Dynamically choose the number of credits by checking the number of lines.
That's the last of our FIXME, XXX, and TODO! Woohoo! ^o^
This commit is contained in:
parent
919a8da5d0
commit
a2d9120903
26
src/title.c
26
src/title.c
|
@ -598,7 +598,7 @@ void title_showCredits()
|
||||||
gfx_free();
|
gfx_free();
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int lastCredit = -1;
|
int lastCredit;
|
||||||
|
|
||||||
int yPos = 0;
|
int yPos = 0;
|
||||||
int yPos2 = screen->h;
|
int yPos2 = screen->h;
|
||||||
|
@ -606,6 +606,7 @@ void title_showCredits()
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
TextObject *credit;
|
TextObject *credit;
|
||||||
|
int nCredit;
|
||||||
|
|
||||||
screen_clear(black);
|
screen_clear(black);
|
||||||
renderer_update();
|
renderer_update();
|
||||||
|
@ -616,24 +617,39 @@ void title_showCredits()
|
||||||
audio_playMusic("music/rise_of_spirit.ogg", 1);
|
audio_playMusic("music/rise_of_spirit.ogg", 1);
|
||||||
|
|
||||||
fp = fopen("data/credits.txt", "rb");
|
fp = fopen("data/credits.txt", "rb");
|
||||||
// FIXME: It would be nice for the size of this array to be determined
|
|
||||||
// by the number of lines in the text file. I'm not sure how to do
|
nCredit = 0;
|
||||||
// that at the moment, so just giving it a very large number for now.
|
while (fscanf(fp, "%d %[^\n]%*c", &yPos, text) == 2)
|
||||||
credit = malloc(300 * sizeof(*credit));
|
{
|
||||||
|
nCredit++;
|
||||||
|
}
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
|
||||||
|
credit = malloc(nCredit * sizeof(*credit));
|
||||||
if (credit == NULL)
|
if (credit == NULL)
|
||||||
{
|
{
|
||||||
engine_warn("Failed to allocate memory for credits");
|
engine_warn("Failed to allocate memory for credits");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastCredit = -1;
|
||||||
while (fscanf(fp, "%d %[^\n]%*c", &yPos, text) == 2)
|
while (fscanf(fp, "%d %[^\n]%*c", &yPos, text) == 2)
|
||||||
{
|
{
|
||||||
lastCredit++;
|
lastCredit++;
|
||||||
|
if (lastCredit < nCredit)
|
||||||
|
{
|
||||||
credit[lastCredit].image = gfx_createTextSurface(text, FONT_WHITE);
|
credit[lastCredit].image = gfx_createTextSurface(text, FONT_WHITE);
|
||||||
credit[lastCredit].x = (screen->w - credit[lastCredit].image->w) / 2;
|
credit[lastCredit].x = (screen->w - credit[lastCredit].image->w) / 2;
|
||||||
yPos2 += yPos;
|
yPos2 += yPos;
|
||||||
credit[lastCredit].y = yPos2;
|
credit[lastCredit].y = yPos2;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
engine_warn("Credit size reached, but still scanning the file!");
|
||||||
|
lastCredit--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue