Everything is working now.

This commit is contained in:
mibi88 2023-07-19 20:06:28 +02:00
parent aafa52f4ae
commit 65ed14fc37
5 changed files with 24 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 956 B

After

Width:  |  Height:  |  Size: 875 B

View file

@ -8,7 +8,7 @@
#include "config.h" #include "config.h"
#define BOX_HEIGHT (F_HEIGHT/PXSIZE+8) #define BOX_HEIGHT (F_HEIGHT/PXSIZE+9)
extern font_t fontRPG; extern font_t fontRPG;
#define FONT_USED fontRPG #define FONT_USED fontRPG
@ -39,32 +39,37 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
bool start_anim, bool start_anim,
bool end_anim, bool end_anim,
void for_each_screen(Game *game, unsigned int i), void for_each_screen(Game *game, unsigned int i),
int line_duration, bool line_anim, unsigned int start_i) { int line_duration, bool line_anim, unsigned int start_i,
bool wait_continue) {
dfont(&FONT_USED); dfont(&FONT_USED);
unsigned int i, n, y = PXSIZE, l = 0; unsigned int i, n, y = PXSIZE, l = 0;
int line_max_chars, return_int = 0; int line_max_chars, return_int = 0;
unsigned int max_lines_amount = (BOX_HEIGHT-2)*PXSIZE/ unsigned int max_lines_amount = (BOX_HEIGHT-2)*PXSIZE/
(FONT_USED.line_height+PXSIZE); (FONT_USED.line_height+PXSIZE);
const char *c; const char *c;
draw(game);
if(start_anim){ if(start_anim){
/* Run a little fancy animation. */ /* Run a little fancy animation. */
for(i=0;i<BOX_HEIGHT;i++){ for(i=0;i<BOX_HEIGHT;i++){
draw(game);
drect(0, 0, DWIDTH, i*PXSIZE, C_WHITE); drect(0, 0, DWIDTH, i*PXSIZE, C_WHITE);
drect(0, i*PXSIZE, DWIDTH, (i+1)*PXSIZE, C_BLACK); drect(0, i*PXSIZE, DWIDTH, (i+1)*PXSIZE, C_BLACK);
dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, (i-8)*PXSIZE, dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, (i-8)*PXSIZE,
DIMAGE_NONE); DIMAGE_NONE);
dupdate();
while(game->frame_duration < 20) sleep(); while(game->frame_duration < 20) sleep();
game->frame_duration = 0; game->frame_duration = 0;
} }
}else{ }else{
draw(game);
drect(0, 0, DWIDTH, (BOX_HEIGHT-1)*PXSIZE, C_WHITE); drect(0, 0, DWIDTH, (BOX_HEIGHT-1)*PXSIZE, C_WHITE);
drect(0, (BOX_HEIGHT-1)*PXSIZE, DWIDTH, BOX_HEIGHT*PXSIZE, C_BLACK); drect(0, (BOX_HEIGHT-1)*PXSIZE, DWIDTH, BOX_HEIGHT*PXSIZE, C_BLACK);
dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH, dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH,
(BOX_HEIGHT-7)*PXSIZE, DIMAGE_NONE); (BOX_HEIGHT-7)*PXSIZE, DIMAGE_NONE);
if(line_anim) dupdate(); if(line_anim) blit();
while(game->frame_duration < 20) sleep(); while(game->frame_duration < 20) sleep();
game->frame_duration = 0; game->frame_duration = 0;
@ -72,15 +77,16 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
/* We should start to drawing the text on the x axis at BOX_HEIGHT to avoid /* We should start to drawing the text on the x axis at BOX_HEIGHT to avoid
* drawing on the face. */ * drawing on the face. */
for(i=start_i;i<strlen(text);i++){ for(i=start_i;i<strlen(text);i++){
if(!l) for_each_screen(game, i); if(!l && for_each_screen) for_each_screen(game, i);
/* Get how many chars we can draw on screen with a padding on the left /* Get how many chars we can draw on screen with a padding on the left
* of BOX_HEIGHT px and on the right of 1 px. */ * of BOX_HEIGHT px and on the right of 1 px. */
c = drsize(text+i, &FONT_USED, DWIDTH-(BOX_HEIGHT*PXSIZE+PXSIZE), NULL); 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: */ /* c is a pointer to the last char that can be drawn. So: */
line_max_chars = c-(text+i); line_max_chars = c-(text+i);
/* TODO: Handle lines that are longer than what I can draw. */ /* TODO: Handle lines that are longer than what I can draw and '\n'. */
/* Loop from the end to the start for word wrap. */ /* Loop from the end to the start for word wrap. */
if(*(c+1) != '\0'){ if(*c){
/* If we are not drawing the end of the text. */
for(n=line_max_chars; n>0; n--) { for(n=line_max_chars; n>0; n--) {
/* If we found a space, we can draw this line and do the same /* If we found a space, we can draw this line and do the same
* for the next line. */ * for the next line. */
@ -95,6 +101,7 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
} }
} }
}else{ }else{
/* If it is the last line of the text. */
dtext_opt(BOX_HEIGHT*PXSIZE, y, C_BLACK, C_NONE, DTEXT_LEFT, dtext_opt(BOX_HEIGHT*PXSIZE, y, C_BLACK, C_NONE, DTEXT_LEFT,
DTEXT_TOP, text+i, line_max_chars); DTEXT_TOP, text+i, line_max_chars);
y += FONT_USED.line_height+PXSIZE; y += FONT_USED.line_height+PXSIZE;
@ -114,9 +121,9 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
/* Make a little animation :). */ /* Make a little animation :). */
if(line_anim) blit(); if(line_anim) blit();
if(l>=max_lines_amount-1){ if(l>=max_lines_amount-1){
while(getkey().key != KEY_EXE) sleep(); if(wait_continue) while(getkey().key != KEY_EXE) sleep();
/* Clear the screen. */ /* Clear the text area. */
drect(BOX_HEIGHT*PXSIZE, 0, DWIDTH, (BOX_HEIGHT-1)*PXSIZE-1, drect(BOX_HEIGHT*PXSIZE, 0, DWIDTH, (BOX_HEIGHT-1)*PXSIZE-2,
C_WHITE); C_WHITE);
/* Reset y and l. */ /* Reset y and l. */
y = PXSIZE; y = PXSIZE;
@ -136,7 +143,7 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
/* Ask the user to press EXE to continue. */ /* Ask the user to press EXE to continue. */
dtext(BOX_HEIGHT*PXSIZE, y, C_BLACK, "[EXE] to continue ..."); dtext(BOX_HEIGHT*PXSIZE, y, C_BLACK, "[EXE] to continue ...");
if(line_anim) blit(); if(line_anim) blit();
while(getkey().key != KEY_EXE) sleep(); if(wait_continue) while(getkey().key != KEY_EXE) sleep();
} }
if(call_before_end) return_int = call_before_end(game, i); if(call_before_end) return_int = call_before_end(game, i);
if(end_anim){ if(end_anim){
@ -160,7 +167,7 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
void showtext_dialog(Game *game, bopti_image_t *face, char *text, void showtext_dialog(Game *game, bopti_image_t *face, char *text,
bool dialog_start, bool dialog_end) { bool dialog_start, bool dialog_end) {
showtext_opt(game, face, text, NULL, dialog_start, dialog_end, NULL, 100, showtext_opt(game, face, text, NULL, dialog_start, dialog_end, NULL, 100,
true, 0); true, 0, true);
} }
#define CHOICE_BOX_HEIGHT 10 #define CHOICE_BOX_HEIGHT 10
@ -229,7 +236,7 @@ int _choice_call_before_end(Game *game, unsigned int org_i) {
for(i=DWIDTH/8+1;i>0;i--){ for(i=DWIDTH/8+1;i>0;i--){
draw(game); draw(game);
showtext_opt(game, _face, _text, NULL, false, false, NULL, 0, false, showtext_opt(game, _face, _text, NULL, false, false, NULL, 0, false,
_i); _i, false);
drect(0, BOX_HEIGHT*PXSIZE, i*(DWIDTH/8), drect(0, BOX_HEIGHT*PXSIZE, i*(DWIDTH/8),
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE); (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE);
drect(i*(DWIDTH/8), BOX_HEIGHT*PXSIZE, i*(DWIDTH/8)+PXSIZE-1, drect(i*(DWIDTH/8), BOX_HEIGHT*PXSIZE, i*(DWIDTH/8)+PXSIZE-1,
@ -252,5 +259,5 @@ int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start,
_face = face; _face = face;
_text = text; _text = text;
return showtext_opt(game, face, text, _choice_call_before_end, start, end, return showtext_opt(game, face, text, _choice_call_before_end, start, end,
_choice_screen_call, 100, true, 0); _choice_screen_call, 100, true, 0, true);
} }

View file

@ -14,7 +14,8 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
bool start_anim, bool start_anim,
bool end_anim, bool end_anim,
void for_each_screen(Game *game, unsigned int i), void for_each_screen(Game *game, unsigned int i),
int line_duration, bool line_anim, unsigned int start_i); int line_duration, bool line_anim, unsigned int start_i,
bool wait_continue);
void showtext_dialog(Game *game, bopti_image_t *face, char *text, void showtext_dialog(Game *game, bopti_image_t *face, char *text,
bool dialog_start, bool dialog_end); bool dialog_start, bool dialog_end);

View file

@ -99,7 +99,7 @@ int main(void) {
dgray(DGRAY_ON); dgray(DGRAY_ON);
#endif #endif
showtext(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, true); showtext_dialog(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, true);
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); 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(&game, &player_face_img, "You choosed ipsum", false, true); if(in) showtext_dialog(&game, &player_face_img, "You choosed ipsum", false, true);
else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true); else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true);