Show number of challenges completed, lock challenges that can't be played yet.

This commit is contained in:
Steve 2016-02-29 09:23:41 +00:00
parent 83523f868a
commit 281dd4d7d2
1 changed files with 36 additions and 4 deletions

View File

@ -31,6 +31,8 @@ static void startChallengeMission(void);
static SDL_Texture *background;
static int startIndex;
static Widget *start;
static int completedChallenges;
static int totalChallenges;
void initChallengeHome(void)
{
@ -69,9 +71,14 @@ static void updateChallengeMissions(void)
{
Mission *m;
Challenge *c;
int i;
i = completedChallenges = totalChallenges = 0;
for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next)
{
m->available = i <= completedChallenges;
m->totalChallenges = m->completedChallenges = 0;
for (c = m->challengeHead.next ; c != NULL ; c = c->next)
@ -83,6 +90,11 @@ static void updateChallengeMissions(void)
m->completedChallenges++;
}
}
completedChallenges += m->completedChallenges;
totalChallenges += m->totalChallenges;
i++;
}
}
@ -106,10 +118,19 @@ static void doChallenges(void)
for (c = game.challengeMissionHead.next ; c != NULL ; c = c->next)
{
if (app.mouse.button[SDL_BUTTON_LEFT] && collision(app.mouse.x, app.mouse.y, 3, 3, c->rect.x, c->rect.y, c->rect.w, c->rect.h))
{
if (c->available)
{
game.currentMission = c;
}
else
{
start->enabled = 1;
game.currentMission = NULL;
}
start->enabled = c->available;
app.mouse.button[SDL_BUTTON_LEFT] = 0;
}
@ -122,6 +143,10 @@ static void draw(void)
drawStars();
drawText(SCREEN_WIDTH / 2, 50, 30, TA_CENTER, colors.white, "Challenges");
drawText(SCREEN_WIDTH / 2, 100, 24, TA_CENTER, colors.white, "%d / %d", completedChallenges, totalChallenges);
drawChallenges();
drawWidgets("challenges");
@ -134,7 +159,7 @@ static void drawChallenges(void)
int i, endIndex;
r.x = 135;
r.y = 165;
r.y = 185;
r.w = r.h = 96;
endIndex = startIndex + MAX_ITEMS;
@ -164,7 +189,14 @@ static void drawChallenges(void)
drawText(r.x + (r.w / 2), r.y + 28, 30, TA_CENTER, colors.white, "%d", i + 1);
if (c->available)
{
drawText(r.x + (r.w / 2), r.y + r.w + 5, 18, TA_CENTER, (c->completedChallenges < c->totalChallenges) ? colors.white : colors.green, "%d / %d", c->completedChallenges, c->totalChallenges);
}
else
{
drawText(r.x + (r.w / 2), r.y + r.w + 5, 18, TA_CENTER, colors.lightGrey, "[Locked]");
}
r.x += 150;