Added interactive dialogs, but they are not working properly yet.

This commit is contained in:
mibi88 2023-07-15 19:26:32 +02:00
parent e53c3d612d
commit f71121a79e
4 changed files with 66 additions and 43 deletions

View file

@ -6,6 +6,6 @@
#define GRAYMODEOK 1
#endif
#define USB_FEATURE 1
#define USB_FEATURE 0
#endif

View file

@ -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;i<BOX_HEIGHT;i++){
draw(game);
if(start_anim){
/* Run a little fancy animation. */
for(i=0;i<BOX_HEIGHT;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);
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;
}
}
/* 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;i<DWIDTH/8+1;i++){
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, i*(DWIDTH/8),
drect(0, BOX_HEIGHT*PXSIZE, i*(DWIDTH/8),
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE);
drect(i*(DWIDTH/8), 0, i*(DWIDTH/8)+PXSIZE,
drect(i*(DWIDTH/8), BOX_HEIGHT*PXSIZE, i*(DWIDTH/8)+PXSIZE,
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_BLACK);
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, i*(DWIDTH/8),
(BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE, C_BLACK);
@ -171,28 +176,29 @@ int _choice_call_before_end(void) {
while(game->frame_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<choices_amount;i++){
if(i == selected) dtext(i*choice_size,
BOX_HEIGHT+PXSIZE*CHOICE_BOX_PADDING_TOP,
for(i=0;i<_choices_amount;i++){
if(i == selected) dtext(i*choice_size+PXSIZE,
(BOX_HEIGHT+CHOICE_BOX_PADDING_TOP)*PXSIZE,
C_BLACK, ">");
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);
}

View file

@ -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

View file

@ -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);