Determine width of trophy alert based on title and description length.

This commit is contained in:
Steve 2016-05-14 17:35:57 +01:00
parent 8a363137a5
commit 6e0cbba3d8
2 changed files with 5 additions and 13 deletions

View File

@ -263,7 +263,7 @@ void doTrophyAlerts(void)
static void nextAlert(void) static void nextAlert(void)
{ {
int h; int w, h;
Trophy *t; Trophy *t;
for (t = game.trophyHead.next ; t != NULL ; t = t->next) for (t = game.trophyHead.next ; t != NULL ; t = t->next)
@ -282,8 +282,10 @@ static void nextAlert(void)
playSound(SND_TROPHY); playSound(SND_TROPHY);
textSize(alertTrophy->title, 30, &alertRect.w, &h); textSize(alertTrophy->title, 30, &alertRect.w, &h);
textSize(alertTrophy->description, 20, &w, &h);
alertRect.w = MAX(alertRect.w, w);
alertRect.w += 125; alertRect.w += 125;
alertRect.w = MAX(alertRect.w, 500);
alertRect.x = -alertRect.w; alertRect.x = -alertRect.w;
} }
} }
@ -307,7 +309,7 @@ void drawTrophyAlert(void)
SDL_RenderDrawRect(app.renderer, &alertRect); SDL_RenderDrawRect(app.renderer, &alertRect);
drawText(alertRect.x + 15, alertRect.y + 5, 30, TA_LEFT, colors.white, alertTrophy->title); 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); drawText(alertRect.x + 15, alertRect.y + 45, 20, TA_LEFT, colors.white, alertTrophy->description);
setSparkleColor(alertTrophy); setSparkleColor(alertTrophy);
@ -359,18 +361,9 @@ static void loadTrophyData(char *filename)
STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH); STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH);
STRNCPY(t->title, _(cJSON_GetObjectItem(node, "title")->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); STRNCPY(t->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH);
STRNCPY(t->shortDescription, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_NAME_LENGTH);
t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring); t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring);
t->hidden = getJSONValue(node, "hidden", 0); t->hidden = getJSONValue(node, "hidden", 0);
if (strlen(t->description) > MAX_NAME_LENGTH)
{
t->shortDescription[MAX_NAME_LENGTH - 1] = '.';
t->shortDescription[MAX_NAME_LENGTH - 2] = '.';
t->shortDescription[MAX_NAME_LENGTH - 3] = '.';
t->shortDescription[MAX_NAME_LENGTH - 4] = ' ';
}
t->stat = -1; t->stat = -1;
/* can't use the getJSONValue here, as it could lead to false positives */ /* can't use the getJSONValue here, as it could lead to false positives */

View File

@ -377,7 +377,6 @@ struct Trophy {
char id[MAX_NAME_LENGTH]; char id[MAX_NAME_LENGTH];
char title[MAX_DESCRIPTION_LENGTH]; char title[MAX_DESCRIPTION_LENGTH];
char description[MAX_DESCRIPTION_LENGTH]; char description[MAX_DESCRIPTION_LENGTH];
char shortDescription[MAX_NAME_LENGTH];
char awardDateStr[MAX_NAME_LENGTH]; char awardDateStr[MAX_NAME_LENGTH];
int value; int value;
int hidden; int hidden;