From 281dd4d7d2d44c0d40010abc7b765a8adecc0496 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 29 Feb 2016 09:23:41 +0000 Subject: [PATCH] Show number of challenges completed, lock challenges that can't be played yet. --- src/challenges/challengeHome.c | 40 ++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/challenges/challengeHome.c b/src/challenges/challengeHome.c index 7ded962..e23b535 100644 --- a/src/challenges/challengeHome.c +++ b/src/challenges/challengeHome.c @@ -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++; } } @@ -107,9 +119,18 @@ static void doChallenges(void) { 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)) { - game.currentMission = c; + if (c->available) + { + game.currentMission = c; + } + else + { + + + game.currentMission = NULL; + } - start->enabled = 1; + 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); - 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); + 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;