diff --git a/src/battle/battle.c b/src/battle/battle.c index e2028fa..3dacb1e 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -132,9 +132,9 @@ static void doBattle(void) battle.planet.x -= ssx * 0.05; battle.planet.y -= ssy * 0.05; - + doObjectives(); - + doChallenges(); doHud(); @@ -160,9 +160,9 @@ static void doBattle(void) if (battle.status == MS_IN_PROGRESS) { doScript(); - + battle.stats[STAT_TIME]++; - + if (battle.stats[STAT_TIME] % FPS == 0) { runScriptFunction("TIME %d", battle.stats[STAT_TIME] / 60); @@ -367,7 +367,7 @@ static void postBattle(void) game.stats[i] += battle.stats[i]; } } - + updateAccuracyStats(game.stats); if (!game.currentMission->challengeData.isChallenge) @@ -375,6 +375,11 @@ static void postBattle(void) if (game.currentMission && !game.currentMission->completed) { game.currentMission->completed = (battle.status == MS_COMPLETE || !battle.numObjectivesTotal); + + if (game.currentMission->completed && game.currentMission->trophyId) + { + awardTrophy(game.currentMission->trophyId); + } } } } diff --git a/src/defs.h b/src/defs.h index fdc7800..9efe424 100644 --- a/src/defs.h +++ b/src/defs.h @@ -334,3 +334,12 @@ enum STAT_TIME, STAT_MAX }; + +enum +{ + TROPHY_BRONZE, + TROPHY_SILVER, + TROPHY_GOLD, + TROPHY_PLATINUM, + TROPHY_MAX +}; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 8c3ea1c..4e4766a 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -61,6 +61,8 @@ Mission *loadMissionMeta(char *filename) mission->requires = getJSONValue(root, "requires", 0); + mission->trophyId = getJSONValueStr(root, "trophyId", NULL); + if (cJSON_GetObjectItem(root, "epic")) { mission->epic = 1; diff --git a/src/game/trophies.c b/src/game/trophies.c index 6c79e78..ed4e0c2 100644 --- a/src/game/trophies.c +++ b/src/game/trophies.c @@ -20,14 +20,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "trophies.h" -static int recentlyAwarded; static void loadTrophyData(char *filename); +static void resetAlert(void); + +static Trophy *alertTrophy; +static SDL_Texture *trophyIcons[TROPHY_MAX]; +static SDL_Rect alertRect; +static float alertDX; +static int alertTimer; void initTrophies(void) { - recentlyAwarded = 0; - loadTrophyData("data/trophies/trophies.json"); + + trophyIcons[TROPHY_BRONZE] = getTexture("gfx/trophies/bronze.png"); + trophyIcons[TROPHY_SILVER] = getTexture("gfx/trophies/silver.png"); + trophyIcons[TROPHY_GOLD] = getTexture("gfx/trophies/gold.png"); + trophyIcons[TROPHY_PLATINUM] = getTexture("gfx/trophies/platinum.png"); + + resetAlert(); } void awardTrophy(char *id) @@ -41,29 +52,70 @@ void awardTrophy(char *id) t->awarded = 1; t->awardDate = time(NULL); t->notify = 1; - - recentlyAwarded++; } } } -void drawTrophyAlerts(void) +void doTrophies(void) { Trophy *t; - if (recentlyAwarded) + for (t = game.trophyHead.next ; t != NULL ; t = t->next) { - for (t = game.trophyHead.next ; t != NULL ; t = t->next) + if (t->notify) { - if (t->notify) + if (alertTrophy != t) { - /* handle notification */ - return; + alertTrophy = t; + playSound(SND_TROPHY); } + + alertRect.x += alertDX; + + if (alertRect.x > -50) + { + alertDX *= 0.95; + } + + if (--alertTimer <= 0) + { + t->notify = 0; + resetAlert(); + } + + return; } } } +static void resetAlert(void) +{ + alertRect.w = 300; + alertRect.h = 100; + alertRect.x = -alertRect.w; + alertRect.y = 10; + + alertDX = 3; + alertTimer = FPS * 3; +} + +void drawTrophyAlert(void) +{ + if (alertTrophy) + { + SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); + SDL_RenderFillRect(app.renderer, &alertRect); + + SDL_SetRenderDrawColor(app.renderer, 64, 64, 64, SDL_ALPHA_OPAQUE); + SDL_RenderDrawRect(app.renderer, &alertRect); + + drawText(alertRect.x + 5, alertRect.y + 5, 30, TA_LEFT, colors.white, alertTrophy->title); + drawText(alertRect.x + 5, alertRect.y + 45, 20, TA_LEFT, colors.white, alertTrophy->description); + + blit(trophyIcons[alertTrophy->value], alertRect.x + alertRect.w - 64, alertRect.y + 10, 0); + } +} + void drawTrophies(void) { } @@ -102,8 +154,8 @@ static void loadTrophyData(char *filename) memset(t, 0, sizeof(Trophy)); STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH); - STRNCPY(t->title, cJSON_GetObjectItem(node, "title")->valuestring, MAX_DESCRIPTION_LENGTH); - STRNCPY(t->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH); + STRNCPY(t->title, _(cJSON_GetObjectItem(node, "title")->valuestring), MAX_DESCRIPTION_LENGTH); + STRNCPY(t->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH); t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring); t->hidden = getJSONValue(node, "hidden", 0); diff --git a/src/system/lookup.c b/src/system/lookup.c index 0f146ca..84509fe 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -168,6 +168,11 @@ void initLookups(void) addLookup("STAT_CAPITAL_SHIPS_DESTROYED", STAT_CAPITAL_SHIPS_DESTROYED); addLookup("STAT_CAPITAL_SHIPS_LOST", STAT_CAPITAL_SHIPS_LOST); addLookup("STAT_TIME", STAT_TIME); + + addLookup("TROPHY_BRONZE", TROPHY_BRONZE); + addLookup("TROPHY_SILVER", TROPHY_SILVER); + addLookup("TROPHY_GOLD", TROPHY_GOLD); + addLookup("TROPHY_PLATINUM", TROPHY_PLATINUM); } static void addLookup(char *name, long value)