Show number of challenges completed, lock challenges that can't be played yet.
This commit is contained in:
parent
83523f868a
commit
281dd4d7d2
|
@ -31,6 +31,8 @@ static void startChallengeMission(void);
|
||||||
static SDL_Texture *background;
|
static SDL_Texture *background;
|
||||||
static int startIndex;
|
static int startIndex;
|
||||||
static Widget *start;
|
static Widget *start;
|
||||||
|
static int completedChallenges;
|
||||||
|
static int totalChallenges;
|
||||||
|
|
||||||
void initChallengeHome(void)
|
void initChallengeHome(void)
|
||||||
{
|
{
|
||||||
|
@ -69,9 +71,14 @@ static void updateChallengeMissions(void)
|
||||||
{
|
{
|
||||||
Mission *m;
|
Mission *m;
|
||||||
Challenge *c;
|
Challenge *c;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = completedChallenges = totalChallenges = 0;
|
||||||
|
|
||||||
for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next)
|
for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next)
|
||||||
{
|
{
|
||||||
|
m->available = i <= completedChallenges;
|
||||||
|
|
||||||
m->totalChallenges = m->completedChallenges = 0;
|
m->totalChallenges = m->completedChallenges = 0;
|
||||||
|
|
||||||
for (c = m->challengeHead.next ; c != NULL ; c = c->next)
|
for (c = m->challengeHead.next ; c != NULL ; c = c->next)
|
||||||
|
@ -83,6 +90,11 @@ static void updateChallengeMissions(void)
|
||||||
m->completedChallenges++;
|
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)
|
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 (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;
|
game.currentMission = c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
start->enabled = 1;
|
|
||||||
|
game.currentMission = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
start->enabled = c->available;
|
||||||
|
|
||||||
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +143,10 @@ static void draw(void)
|
||||||
|
|
||||||
drawStars();
|
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();
|
drawChallenges();
|
||||||
|
|
||||||
drawWidgets("challenges");
|
drawWidgets("challenges");
|
||||||
|
@ -134,7 +159,7 @@ static void drawChallenges(void)
|
||||||
int i, endIndex;
|
int i, endIndex;
|
||||||
|
|
||||||
r.x = 135;
|
r.x = 135;
|
||||||
r.y = 165;
|
r.y = 185;
|
||||||
r.w = r.h = 96;
|
r.w = r.h = 96;
|
||||||
|
|
||||||
endIndex = startIndex + MAX_ITEMS;
|
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 + 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);
|
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;
|
r.x += 150;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue