From 01ec3ceb7bb44332c6ac716a756833e581fab53a Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 23 Dec 2015 19:22:31 +0000 Subject: [PATCH] Stats bug fixes. --- src/galaxy/stats.c | 13 ++++++++++--- src/system/load.c | 8 +++++++- src/system/lookup.c | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/galaxy/stats.c b/src/galaxy/stats.c index 6046408..b2cfe61 100644 --- a/src/galaxy/stats.c +++ b/src/galaxy/stats.c @@ -62,10 +62,11 @@ static Widget *next; void initStatsDisplay(void) { page = 0; - maxPages = (STAT_MAX / MAX_STAT_ITEMS); + maxPages = ceil(STAT_TIME / MAX_STAT_ITEMS); prev = getWidget("prev", "stats"); prev->action = prevPage; + prev->visible = 0; next = getWidget("next", "stats"); next->action = nextPage; @@ -94,7 +95,7 @@ void drawStats(void) drawText(SCREEN_WIDTH / 2, 70, 28, TA_CENTER, colors.white, "Stats"); - drawText(SCREEN_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, "Page %d / %d", page + 1, maxPages + 1); + drawText(SCREEN_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, "Page %d / %d", page + 1, maxPages); y = 170; @@ -125,10 +126,16 @@ void drawStats(void) static void nextPage(void) { - page = MIN(page + 1, maxPages); + page = MIN(page + 1, maxPages - 1); + + next->visible = page < maxPages - 1; + prev->visible = 1; } static void prevPage(void) { page = MAX(0, page - 1); + + next->visible = 1; + prev->visible = page > 0; } diff --git a/src/system/load.c b/src/system/load.c index 3dbc458..994b58d 100644 --- a/src/system/load.c +++ b/src/system/load.c @@ -100,9 +100,15 @@ static void loadChallenges(Mission *mission, cJSON *challengesCJSON) static void loadStats(cJSON *stats) { int i; + char *statName; for (i = 0 ; i < STAT_MAX ; i++) { - game.stats[i] = cJSON_GetObjectItem(stats, getLookupName("STAT_", i))->valueint; + statName = getLookupName("STAT_", i); + + if (statName && cJSON_GetObjectItem(stats, statName)) + { + game.stats[i] = cJSON_GetObjectItem(stats, statName)->valueint; + } } } diff --git a/src/system/lookup.c b/src/system/lookup.c index 9c01b14..8a319d1 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -117,6 +117,8 @@ void initLookups(void) addLookup("STAT_MISSIONS_COMPLETED", STAT_MISSIONS_COMPLETED); addLookup("STAT_SHOTS_FIRED", STAT_SHOTS_FIRED); addLookup("STAT_SHOTS_HIT", STAT_SHOTS_HIT); + addLookup("STAT_ROCKETS_FIRED", STAT_ROCKETS_FIRED); + addLookup("STAT_ROCKETS_HIT", STAT_ROCKETS_HIT); addLookup("STAT_MISSILES_FIRED", STAT_MISSILES_FIRED); addLookup("STAT_MISSILES_HIT", STAT_MISSILES_HIT); addLookup("STAT_ENEMIES_KILLED", STAT_ENEMIES_KILLED);