From 1b5cd7a80fe625b01270b13df92403b88f3288a9 Mon Sep 17 00:00:00 2001 From: bgiraudr Date: Fri, 21 Jan 2022 21:40:12 +0100 Subject: [PATCH] =?UTF-8?q?Retour=20=C3=A0=20la=20ligne=20(experimental)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets-cg/maps/1.tmx | 2 +- assets-cg/maps/testCarte.tmx | 14 +++++++++---- include/talkable.h | 3 ++- src/talkable.c | 39 +++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/assets-cg/maps/1.tmx b/assets-cg/maps/1.tmx index a61403b..5b13992 100644 --- a/assets-cg/maps/1.tmx +++ b/assets-cg/maps/1.tmx @@ -36,7 +36,7 @@ - + diff --git a/assets-cg/maps/testCarte.tmx b/assets-cg/maps/testCarte.tmx index a1d1dcd..1be3e65 100644 --- a/assets-cg/maps/testCarte.tmx +++ b/assets-cg/maps/testCarte.tmx @@ -1,5 +1,5 @@ - + @@ -58,7 +58,7 @@ 0,743,744,745,746,274,53,54,0,275,0,53,54,274,0,0,0,0,0,0,0,0,0,0,0,0,108,0,0,0,0,0,0,0,0,111,0,0,0,0,0,0,0,113,0,656,657,658,659,108,0,0,0,378,379,380,0,0,0,0,0,0,0,0,0,0,82,138,139,0,0,0,0,0,0,0,0,0,0,0,0,303,0,722,723,724,725,0,0,0,0,0,635,636,637,638,0,245,0,0, 0,0,29,0,0,303,0,0,0,304,0,0,0,303,0,0,0,0,0,0,0,0,0,0,0,0,108,0,0,0,0,0,0,0,0,111,0,0,0,0,0,0,0,113,0,685,686,687,688,137,84,174,0,0,0,0,0,0,0,0,0,0,0,0,0,82,139,111,0,0,18,19,0,0,0,0,0,0,0,0,0,0,0,751,752,753,754,0,0,0,0,0,664,665,666,667,0,274,0,0, 0,0,58,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,635,636,637,638,0,79,142,0,0,0,0,0,0,0,0,111,0,0,0,0,0,29,0,113,0,714,715,716,717,0,137,203,138,138,84,0,0,0,0,0,0,0,82,138,138,139,0,140,81,0,47,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,25,0,0,693,694,695,696,0,303,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,664,665,666,667,0,108,0,0,0,0,0,0,0,0,0,111,0,0,0,0,0,58,0,113,0,743,744,745,746,0,0,232,0,0,137,138,138,138,138,138,138,138,139,0,0,0,0,0,111,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,53,54,0,0,722,723,724,725,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,664,665,666,667,0,108,0,0,0,0,0,0,0,0,0,111,0,239,0,0,0,58,0,113,0,743,744,745,746,0,0,232,0,0,137,138,138,138,138,138,138,138,139,0,0,0,0,0,111,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,53,54,0,0,722,723,724,725,0,0,0,0, 0,0,0,0,0,0,245,0,0,245,0,0,0,0,0,0,0,0,0,0,693,694,695,696,0,108,0,0,0,0,0,0,0,0,0,111,0,0,0,0,0,0,0,113,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,0,635,636,637,638,0,0,0,245,0,0,0,0,245,0,751,752,753,754,0,0,0,0, 0,0,320,321,322,0,274,0,0,274,0,0,0,0,0,0,0,0,0,0,722,723,724,725,0,108,0,0,0,0,0,0,0,0,0,140,141,141,141,141,141,141,141,142,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,320,321,322,0,0,0,111,0,0,323,324,325,0,0,0,0,664,665,666,667,0,0,0,274,0,323,324,325,274,0,0,0,0,0,0,0,0,0, 0,0,349,350,351,0,303,0,0,303,0,0,0,0,0,0,0,0,0,0,751,752,753,754,0,137,84,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,349,350,351,0,0,0,111,0,0,352,353,354,0,0,0,0,693,694,695,696,0,0,0,303,0,352,353,354,303,0,0,0,0,0,0,0,0,0, @@ -183,8 +183,8 @@ - - + + @@ -194,5 +194,11 @@ + + + + + + diff --git a/include/talkable.h b/include/talkable.h index 451904d..d5b8af9 100644 --- a/include/talkable.h +++ b/include/talkable.h @@ -13,4 +13,5 @@ struct Talkable { /*draw the dialog of a specified talkable tile*/ void draw_dialog(struct Talkable *character); /*find the talkable tile using the player's position*/ -struct Talkable* get_dialog_xy(struct Map *map, int x, int y); \ No newline at end of file +struct Talkable* get_dialog_xy(struct Map *map, int x, int y); +void clean(char *var); \ No newline at end of file diff --git a/src/talkable.c b/src/talkable.c index 167b622..d777d4d 100644 --- a/src/talkable.c +++ b/src/talkable.c @@ -5,6 +5,8 @@ #include "talkable.h" #include "util.h" +#define LIMIT 35 + struct Talkable default_value = { .x = 0, .y = 0, @@ -22,13 +24,48 @@ void draw_dialog(struct Talkable *talkable) { while(curr_line != NULL) { drect(20,10,370,80,C_WHITE); dprint(25,20, C_BLACK, "%s", talkable->name); - dprint(25,40, C_BLACK, "%s", curr_line); + + //TODO Il y a moyen de faire mieux avec seulement curr_line. + //Cela semble globalement fonctionner, mais j'ai pu oobserver des petites erreurs + if(strlen(curr_line) > LIMIT) { + char remain[strlen(curr_line)+1]; + char split[LIMIT+1]; + char first_part[LIMIT+1]; + + strcpy(remain, curr_line); + int indexLine = 0; + + while(strlen(remain) > LIMIT) { + clean(split); + strncpy(first_part,&remain[0],LIMIT); + + char* find = strrchr(first_part,' '); + int indexSpace = find != NULL ? (int)(find-first_part) : LIMIT-1; + strncpy(split,&remain[0],indexSpace); + strncpy(remain,&remain[indexSpace]+1,strlen(remain)); + + dprint(25,40+indexLine*15, C_BLACK, "%s", split); + indexLine++; + } + dprint(25,40+indexLine*15, C_BLACK, "%s", remain); + } else { + dprint(25,40, C_BLACK, "%s", curr_line); + } + dupdate(); curr_line = strtok(NULL, delim); wait_for_input(KEY_SHIFT); } } +void clean(char *var) { + int i = 0; + while(var[i] != '\0') { + var[i] = '\0'; + i++; + } +} + /*find the talkable tile using the player's position*/ struct Talkable* get_dialog_xy(struct Map *map, int x, int y) { int i = 0;