2023-07-09 22:02:59 +02:00
|
|
|
#include "dialogs.h"
|
|
|
|
|
|
|
|
#include <gint/keyboard.h>
|
|
|
|
#include <gint/cpu.h>
|
|
|
|
|
|
|
|
#define BOX_HEIGHT (F_HEIGHT/PXSIZE+8)
|
|
|
|
|
2023-07-10 20:55:27 +02:00
|
|
|
extern font_t fontRPG;
|
2023-07-11 11:23:27 +02:00
|
|
|
#define FONT_USED fontRPG
|
2023-07-10 20:55:27 +02:00
|
|
|
|
2023-07-09 22:02:59 +02:00
|
|
|
void showtext(Game *game, bopti_image_t *face, char *text) {
|
2023-07-11 11:23:27 +02:00
|
|
|
dfont(&FONT_USED);
|
|
|
|
unsigned int i, n, y = 1, l = 0;
|
|
|
|
int line_max_chars;
|
2023-07-11 13:29:48 +02:00
|
|
|
unsigned int max_lines_amount = BOX_HEIGHT/FONT_USED.line_height;
|
|
|
|
const char *c;
|
2023-07-11 11:23:27 +02:00
|
|
|
/* Run a little fancy animation. */
|
2023-07-09 22:02:59 +02:00
|
|
|
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);
|
|
|
|
dupdate();
|
|
|
|
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. */
|
|
|
|
/* Show a little message that showing text in dialogs is not implemented
|
|
|
|
* yet. */
|
|
|
|
for(i=0;i<strlen(text);i++){
|
2023-07-11 11:23:27 +02:00
|
|
|
/* Get how many chars we can draw on screen with a padding on the left
|
2023-07-11 13:29:48 +02:00
|
|
|
* of BOX_HEIGHT px and on the right of 1 px. */
|
|
|
|
c = drsize(text+i, &FONT_USED, DWIDTH-(BOX_HEIGHT*PXSIZE+PXSIZE), NULL);
|
|
|
|
/* c is a pointer to the last char that can be drawn. So: */
|
|
|
|
line_max_chars = c-(text+i);
|
2023-07-11 11:23:27 +02:00
|
|
|
/* TODO: Handle lines that are longer than what I can draw. */
|
|
|
|
/* Loop from the end to the start for word wrap. */
|
|
|
|
for(n=line_max_chars; n>0; n--) {
|
|
|
|
/* If we found a space, we can draw this line and do the same for
|
|
|
|
* the next line. */
|
|
|
|
if(text[i+n] == ' '){
|
2023-07-11 13:29:48 +02:00
|
|
|
dtext_opt(BOX_HEIGHT, y, C_BLACK, C_NONE, DTEXT_TOP, DTEXT_LEFT,
|
|
|
|
text+i, n); /* Draw everything. */
|
|
|
|
/* Increment y by the line height. */
|
|
|
|
y += FONT_USED.line_height;
|
2023-07-11 11:23:27 +02:00
|
|
|
i += n; /* We drew everything to i+n */
|
|
|
|
l++; /* We drew one more line. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(l>=max_lines_amount-1){
|
|
|
|
/* We drew one entire screen, reset everything to draw the next one.
|
|
|
|
*/
|
|
|
|
/* Make a little animation :). */
|
|
|
|
dupdate();
|
|
|
|
while(game->frame_duration < 20) sleep();
|
|
|
|
game->frame_duration = 0;
|
|
|
|
/* Ask the user to press EXE to continue. */
|
2023-07-11 13:29:48 +02:00
|
|
|
dtext(BOX_HEIGHT, y, C_BLACK, "[EXE] to continue ...");
|
2023-07-11 11:23:27 +02:00
|
|
|
/* Clear the screen. */
|
2023-07-11 13:29:48 +02:00
|
|
|
drect(0, 0, DWIDTH, BOX_HEIGHT*PXSIZE, C_WHITE);
|
2023-07-11 11:23:27 +02:00
|
|
|
}
|
|
|
|
/* Make a little animation :). */
|
|
|
|
dupdate();
|
|
|
|
if(l>=max_lines_amount-1){
|
|
|
|
while(getkey().key != KEY_EXE) sleep();
|
2023-07-11 13:29:48 +02:00
|
|
|
/* Reset y and l. */
|
|
|
|
y = 1;
|
|
|
|
l = 0;
|
2023-07-11 11:23:27 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
while(game->frame_duration < 20) sleep();
|
|
|
|
}
|
|
|
|
game->frame_duration = 0;
|
|
|
|
}
|
|
|
|
if(l<max_lines_amount-1){
|
|
|
|
/* If we have not filled everthing with text at the end. */
|
|
|
|
/* Make a little animation :). */
|
|
|
|
dupdate();
|
|
|
|
while(game->frame_duration < 20) sleep();
|
|
|
|
game->frame_duration = 0;
|
|
|
|
/* Ask the user to press EXE to continue. */
|
|
|
|
dtext(1, y, C_BLACK, "[EXE] To continue ...");
|
|
|
|
while(getkey().key != KEY_EXE) sleep();
|
2023-07-09 22:02:59 +02:00
|
|
|
}
|
2023-07-11 11:23:27 +02:00
|
|
|
/* Run another little fancy animation. */
|
2023-07-09 22:02:59 +02:00
|
|
|
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();
|
|
|
|
while(game->frame_duration < 20) sleep();
|
|
|
|
game->frame_duration = 0;
|
|
|
|
}
|
|
|
|
}
|