From 3ce51feb9c132a426a20f1b32cbe52ee03068873 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 24 Apr 2016 13:00:27 +0100 Subject: [PATCH] Various trophy tweaks. --- data/trophies/trophies.json | 20 ++++++++++---------- src/galaxy/galacticMap.c | 4 ++-- src/game/trophies.c | 37 ++++++++++++++++++++++++------------- src/game/trophies.h | 4 +++- src/structs.h | 1 + src/system/load.c | 23 +++++++++++++++++++++++ src/system/load.h | 1 + src/system/save.c | 26 ++++++++++++++++++++++++++ 8 files changed, 90 insertions(+), 26 deletions(-) diff --git a/data/trophies/trophies.json b/data/trophies/trophies.json index 3d529d1..f0f04e2 100644 --- a/data/trophies/trophies.json +++ b/data/trophies/trophies.json @@ -14,43 +14,43 @@ { "id" : "CAMPAIGN_10", "title" : "1st Lieutenant", - "description" : "Complete 10% of all missions", + "description" : "Complete 10%% of all missions", "value" : "TROPHY_BRONZE" }, { "id" : "CAMPAIGN_20", "title" : "Lieutenant Commander", - "description" : "Complete 20% of all missions", + "description" : "Complete 20%% of all missions", "value" : "TROPHY_BRONZE" }, { "id" : "CAMPAIGN_40", "title" : "Commander", - "description" : "Complete 40% of all missions", + "description" : "Complete 40%% of all missions", "value" : "TROPHY_BRONZE" }, { "id" : "CAMPAIGN_50", "title" : "Captain", - "description" : "Complete 50% of all missions", + "description" : "Complete 50%% of all missions", "value" : "TROPHY_SILVER" }, { "id" : "CAMPAIGN_60", "title" : "Commodore", - "description" : "Complete 60% of all missions", + "description" : "Complete 60%% of all missions", "value" : "TROPHY_SILVER" }, { "id" : "CAMPAIGN_80", "title" : "Rear Admiral", - "description" : "Complete 80% of all missions", + "description" : "Complete 80%% of all missions", "value" : "TROPHY_SILVER" }, { "id" : "CAMPAIGN_90", "title" : "Admiral", - "description" : "Complete 90% of all missions", + "description" : "Complete 90%% of all missions", "value" : "TROPHY_GOLD" }, { @@ -147,19 +147,19 @@ { "id" : "CHALLENGE_25", "title" : "", - "description" : "Complete 25% of all challenges", + "description" : "Complete 25%% of all challenges", "value" : "TROPHY_BRONZE" }, { "id" : "CHALLENGE_50", "title" : "", - "description" : "Complete 50% of all challenges", + "description" : "Complete 50%% of all challenges", "value" : "TROPHY_SILVER" }, { "id" : "CHALLENGE_100", "title" : "", - "description" : "Complete 100% of all challenges", + "description" : "Complete 100%% of all challenges", "value" : "TROPHY_GOLD" }, { diff --git a/src/galaxy/galacticMap.c b/src/galaxy/galacticMap.c index dac56d4..b0a57cc 100644 --- a/src/galaxy/galacticMap.c +++ b/src/galaxy/galacticMap.c @@ -174,9 +174,9 @@ static void logic(void) arrowPulse += 0.1; - doTrophies(); - doWidgets(); + + doTrophies(); } static void doStarSystems(void) diff --git a/src/game/trophies.c b/src/game/trophies.c index f7e93ac..bd51af3 100644 --- a/src/game/trophies.c +++ b/src/game/trophies.c @@ -73,12 +73,14 @@ void doTrophies(void) alertRect.x += alertDX; - if (alertRect.x > -50) + if (alertRect.x > -150) { alertDX *= 0.9; + + alertTimer--; } - if (--alertTimer <= 0) + if (alertTimer <= 0) { t->notify = 0; resetAlert(); @@ -91,12 +93,12 @@ void doTrophies(void) static void resetAlert(void) { - alertRect.w = 300; - alertRect.h = 100; + alertRect.w = 500; + alertRect.h = 90; alertRect.x = -alertRect.w; alertRect.y = 10; - alertDX = 3; + alertDX = 12; alertTimer = FPS * 3; } @@ -110,10 +112,10 @@ void drawTrophyAlert(void) 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); + drawText(alertRect.x + 15, alertRect.y + 5, 30, TA_LEFT, colors.white, alertTrophy->title); + drawText(alertRect.x + 15, alertRect.y + 45, 20, TA_LEFT, colors.white, alertTrophy->shortDescription); - blit(trophyIcons[alertTrophy->value], alertRect.x + alertRect.w - 64, alertRect.y + 10, 0); + blitScaled(trophyIcons[alertTrophy->value], alertRect.x + alertRect.w - 64, alertRect.y + 16, 48, 48); } } @@ -138,7 +140,6 @@ Trophy *getTrophy(char *id) static void loadTrophyData(char *filename) { - /* cJSON *root, *node; char *text; Trophy *t, *tail; @@ -158,10 +159,20 @@ static void loadTrophyData(char *filename) 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->shortDescription, _(cJSON_GetObjectItem(node, "description")->valuestring), SHORT_DESCRIPTION_LENGTH); t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring); t->hidden = getJSONValue(node, "hidden", 0); - - // can't use the getJSONValue here, as it could lead to false positives + + if (strlen(t->description) > SHORT_DESCRIPTION_LENGTH) + { + t->shortDescription[SHORT_DESCRIPTION_LENGTH - 1] = '.'; + t->shortDescription[SHORT_DESCRIPTION_LENGTH - 2] = '.'; + t->shortDescription[SHORT_DESCRIPTION_LENGTH - 3] = '.'; + } + + t->stat = -1; + + /* can't use the getJSONValue here, as it could lead to false positives */ if (cJSON_GetObjectItem(node, "stat")) { t->stat = lookup(cJSON_GetObjectItem(node, "stat")->valuestring); @@ -174,7 +185,6 @@ static void loadTrophyData(char *filename) cJSON_Delete(root); free(text); - */ } void awardStatsTrophies(void) @@ -183,7 +193,7 @@ void awardStatsTrophies(void) for (t = game.trophyHead.next ; t != NULL ; t = t->next) { - if (!t->awarded && game.stats[t->stat] >= t->statValue) + if (t->stat != -1 && !t->awarded && game.stats[t->stat] >= t->statValue) { t->awarded = 1; t->awardDate = time(NULL); @@ -217,6 +227,7 @@ void awardCampaignTrophies(void) { name[i] = toupper(starSystem->name[i]); } + sprintf(trophyId, "CAMPAIGN_%s", name); awardTrophy(trophyId); } diff --git a/src/game/trophies.h b/src/game/trophies.h index ef5b084..319a92f 100644 --- a/src/game/trophies.h +++ b/src/game/trophies.h @@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define SHORT_DESCRIPTION_LENGTH 40 + #include "../common.h" #include "../json/cJSON.h" @@ -28,7 +30,7 @@ extern char *readFile(char *filename); extern int getJSONValue(cJSON *node, char *name, int defValue); extern int getPercent(float current, float total); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); -extern void blit(SDL_Texture *t, int x, int y, int center); +extern void blitScaled(SDL_Texture *t, int x, int y, int w, int h); extern char *getTranslatedString(char *string); extern SDL_Texture *getTexture(char *filename); extern void playSound(int id); diff --git a/src/structs.h b/src/structs.h index ca87ab3..04099fa 100644 --- a/src/structs.h +++ b/src/structs.h @@ -370,6 +370,7 @@ struct Trophy { char id[MAX_NAME_LENGTH]; char title[MAX_DESCRIPTION_LENGTH]; char description[MAX_DESCRIPTION_LENGTH]; + char shortDescription[MAX_DESCRIPTION_LENGTH]; int value; int hidden; int stat; diff --git a/src/system/load.c b/src/system/load.c index 1e527e8..67beeb8 100644 --- a/src/system/load.c +++ b/src/system/load.c @@ -24,6 +24,7 @@ static void loadStats(cJSON *statsJSON); static void loadStarSystems(cJSON *starSystemsJSON); static void loadMissions(cJSON *missionsCJSON); static void loadChallenges(cJSON *challengesCJSON); +static void loadTrophies(cJSON *trophiesJSON); void loadGame(void) { @@ -42,6 +43,8 @@ void loadGame(void) loadChallenges(cJSON_GetObjectItem(gameJSON, "challenges")); loadStats(cJSON_GetObjectItem(gameJSON, "stats")); + + loadTrophies(cJSON_GetObjectItem(gameJSON, "trophies")); cJSON_Delete(root); free(text); @@ -118,3 +121,23 @@ static void loadStats(cJSON *statsJSON) } } } + +static void loadTrophies(cJSON *trophiesJSON) +{ + Trophy *t; + cJSON *trophyJSON; + + if (trophiesJSON) + { + for (trophyJSON = trophiesJSON->child ; trophyJSON != NULL ; trophyJSON = trophyJSON->next) + { + t = getTrophy(cJSON_GetObjectItem(trophyJSON, "id")->valuestring); + + if (t) + { + t->awardDate = cJSON_GetObjectItem(trophyJSON, "awardDate")->valueint; + t->awarded = 1; + } + } + } +} diff --git a/src/system/load.h b/src/system/load.h index b0543fe..262578a 100644 --- a/src/system/load.h +++ b/src/system/load.h @@ -29,5 +29,6 @@ extern int lookup(char *lookup); extern char *getSaveFilePath(char *filename); extern char *getLookupName(char *prefix, long num); extern StarSystem *getStarSystem(char *name); +extern Trophy *getTrophy(char *id); extern Game game; diff --git a/src/system/save.c b/src/system/save.c index 3b568d2..0c85c32 100644 --- a/src/system/save.c +++ b/src/system/save.c @@ -24,6 +24,7 @@ static void saveStarSystems(cJSON *gameJSON); static void saveChallenges(cJSON *gameJSON); static cJSON *getMissionsJSON(StarSystem *starSystem); static void saveStats(cJSON *gameJSON); +static void saveTrophies(cJSON *gameJSON); void saveGame(void) { @@ -43,6 +44,8 @@ void saveGame(void) saveChallenges(gameJSON); saveStats(gameJSON); + + saveTrophies(gameJSON); out = cJSON_Print(root); @@ -146,3 +149,26 @@ static void saveStats(cJSON *gameJSON) cJSON_AddItemToObject(gameJSON, "stats", stats); } + +static void saveTrophies(cJSON *gameJSON) +{ + Trophy *t; + cJSON *trophiesJSON, *trophyJSON; + + trophiesJSON = cJSON_CreateArray(); + + for (t = game.trophyHead.next ; t != NULL ; t = t->next) + { + if (t->awarded) + { + trophyJSON = cJSON_CreateObject(); + + cJSON_AddStringToObject(trophyJSON, "id", t->id); + cJSON_AddNumberToObject(trophyJSON, "awardDate", t->awardDate); + + cJSON_AddItemToArray(trophiesJSON, trophyJSON); + } + } + + cJSON_AddItemToObject(gameJSON, "trophies", trophiesJSON); +}