diff --git a/src/config.h b/src/config.h index 6afe302..c434419 100644 --- a/src/config.h +++ b/src/config.h @@ -6,6 +6,6 @@ #define GRAYMODEOK 1 #endif -#define USB_FEATURE 1 +#define USB_FEATURE 0 #endif diff --git a/src/dialogs.c b/src/dialogs.c index 392ef73..09dcd87 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -35,26 +35,29 @@ void blit() int showtext_opt(Game *game, bopti_image_t *face, char *text, - int call_before_end(void), bool start_anim, bool end_anim) { + int call_before_end(Game *game), bool start_anim, + bool end_anim) { dfont(&FONT_USED); unsigned int i, n, y = PXSIZE, l = 0; int line_max_chars, return_int = 0; unsigned int max_lines_amount = (BOX_HEIGHT-2)*PXSIZE/ (FONT_USED.line_height+PXSIZE); const char *c; - /* Run a little fancy animation. */ - for(i=0;iframe_duration < 20) sleep(); - game->frame_duration = 0; + while(game->frame_duration < 20) sleep(); + game->frame_duration = 0; + } } /* We should start to drawint the text on the x axis at BOX_HEIGHT to avoid * drawing on the face. */ @@ -86,7 +89,7 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, */ /* Make a little animation :). */ blit(); - while(game->frame_duration < 1000) sleep(); + while(game->frame_duration < 100) sleep(); game->frame_duration = 0; /* Ask the user to press EXE to continue. */ dtext(BOX_HEIGHT*PXSIZE, y, C_BLACK, "[EXE] to continue ..."); @@ -103,7 +106,7 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, l = 0; } else{ - while(game->frame_duration < 1000) sleep(); + while(game->frame_duration < 100) sleep(); game->frame_duration = 0; } } @@ -111,26 +114,28 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text, /* If we have not filled everthing with text at the end. */ /* Make a little animation :). */ blit(); - while(game->frame_duration < 1000) sleep(); + while(game->frame_duration < 100) sleep(); game->frame_duration = 0; /* Ask the user to press EXE to continue. */ dtext(BOX_HEIGHT*PXSIZE, y, C_BLACK, "[EXE] to continue ..."); blit(); while(getkey().key != KEY_EXE) sleep(); } - if(call_before_end) return_int = call_before_end(); - /* Run another little fancy animation. */ - for(i=40;i>0;i--){ - draw(game); - drect(0, 0, DWIDTH, i*PXSIZE, C_WHITE); - drect(0, i*PXSIZE, DWIDTH, (i+1)*PXSIZE, C_BLACK); - dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, (i-8)*PXSIZE, - DIMAGE_NONE); + if(call_before_end) return_int = call_before_end(game); + if(end_anim){ + /* Run another little fancy animation. */ + for(i=40;i>0;i--){ + draw(game); + drect(0, 0, DWIDTH, i*PXSIZE, C_WHITE); + drect(0, i*PXSIZE, DWIDTH, (i+1)*PXSIZE, C_BLACK); + dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, (i-8)*PXSIZE, + DIMAGE_NONE); - dupdate(); + dupdate(); - while(game->frame_duration < 20) sleep(); - game->frame_duration = 0; + while(game->frame_duration < 20) sleep(); + game->frame_duration = 0; + } } return return_int; } @@ -154,16 +159,16 @@ void showtext_dialog_end(Game *game, bopti_image_t *face, char *text) { #define CHOICE_BOX_HEIGHT 10 #define CHOICE_BOX_PADDING_TOP 3 -char **choices; -int choices_amount, default_choice; +char *_choices; +int _choices_amount, _default_choice; -int _choice_call_before_end(void) { +int _choice_call_before_end(Game *game) { int i, key; /* Make a little animation because we looove little animations ;) */ for(i=0;iframe_duration < 20) sleep(); game->frame_duration = 0; } - const int choice_size = DWIDTH/choices_amount; - int arrow_width, selected = default_choice; - dsize(">", FONT_USED, &arrow_width, NULL); + const int choice_size = DWIDTH/_choices_amount; + int arrow_width, selected = _default_choice, pos = 0; + dsize(">", &FONT_USED, &arrow_width, NULL); do{ /* Clear the box. */ drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, (DWIDTH/8)*(DWIDTH/8), (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE); - for(i=0;i"); - dtext(i*choice_size+arrow_width, - BOX_HEIGHT+PXSIZE*CHOICE_BOX_PADDING_TOP, C_BLACK, - choices[i]); + pos += strlen(_choices); + dtext(i*choice_size+arrow_width+PXSIZE, + (BOX_HEIGHT+CHOICE_BOX_PADDING_TOP)*PXSIZE, C_BLACK, + &(_choices+pos)[i]); } blit(); key = getkey().key; if(key == KEY_LEFT && selected > 0) selected--; - else if(key == KEY_RIGHT && selected < choices_amount) selected++; + else if(key == KEY_RIGHT && selected < _choices_amount) selected++; }while(key != KEY_EXE); /* Make a little animation because we looove little animations ;) */ - for(i=DWIDTH/8+1;i>0;i++){ + for(i=DWIDTH/8+1;i>0;i--){ drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, i*(DWIDTH/8), (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE); drect(i*(DWIDTH/8), 0, i*(DWIDTH/8)+PXSIZE, @@ -205,3 +211,12 @@ int _choice_call_before_end(void) { } return selected; } + +int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start, + bool end, char *choices, int choices_amount, + int default_choice) { + _choices = choices; + _choices_amount = choices_amount; + _default_choice = default_choice; + return showtext_opt(game, face, text, _choice_call_before_end, start, end); +} diff --git a/src/dialogs.h b/src/dialogs.h index 62c9a6e..7e9e7e4 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -10,7 +10,8 @@ #define F_HEIGHT (32*PXSIZE) int showtext_opt(Game *game, bopti_image_t *face, char *text, - int call_before_end(void), bool start_anim, bool end_anim); + int call_before_end(Game *game), bool start_anim, + bool end_anim); void showtext(Game *game, bopti_image_t *face, char *text); @@ -20,4 +21,8 @@ void showtext_dialog_mid(Game *game, bopti_image_t *face, char *text); void showtext_dialog_end(Game *game, bopti_image_t *face, char *text); +int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start, + bool end, char *choices, int choices_amount, + int default_choice); + #endif diff --git a/src/main.c b/src/main.c index 121a2ee..95397f2 100644 --- a/src/main.c +++ b/src/main.c @@ -100,6 +100,9 @@ int main(void) { #endif showtext(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet."); + int in = showtext_dialog_ask(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, false, "Lorem\0ipsum", 2, 0); + if(in) showtext_dialog_end(&game, &player_face_img, "You choosed ipsum"); + else showtext_dialog_end(&game, &player_face_img, "You choosed Lorem"); do{ /* clear screen */ dclear(C_WHITE);