mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-28 04:23:42 +01:00
Changed showtext_opt to redraw the screen on the animation at the end of an interaction, like Lephé recommended it.
This commit is contained in:
parent
afc2623ad0
commit
aafa52f4ae
3 changed files with 46 additions and 83 deletions
107
src/dialogs.c
107
src/dialogs.c
|
@ -35,8 +35,11 @@ void blit()
|
|||
|
||||
|
||||
int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
||||
int call_before_end(Game *game), bool start_anim,
|
||||
bool end_anim) {
|
||||
int call_before_end(Game *game, unsigned int i),
|
||||
bool start_anim,
|
||||
bool end_anim,
|
||||
void for_each_screen(Game *game, unsigned int i),
|
||||
int line_duration, bool line_anim, unsigned int start_i) {
|
||||
dfont(&FONT_USED);
|
||||
unsigned int i, n, y = PXSIZE, l = 0;
|
||||
int line_max_chars, return_int = 0;
|
||||
|
@ -52,8 +55,6 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
|||
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;
|
||||
}
|
||||
|
@ -63,14 +64,15 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
|||
dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH,
|
||||
(BOX_HEIGHT-7)*PXSIZE, DIMAGE_NONE);
|
||||
|
||||
dupdate();
|
||||
if(line_anim) dupdate();
|
||||
|
||||
while(game->frame_duration < 20) sleep();
|
||||
game->frame_duration = 0;
|
||||
}
|
||||
/* We should start to drawing the text on the x axis at BOX_HEIGHT to avoid
|
||||
* drawing on the face. */
|
||||
for(i=0;i<strlen(text);i++){
|
||||
for(i=start_i;i<strlen(text);i++){
|
||||
if(!l) for_each_screen(game, i);
|
||||
/* 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. */
|
||||
c = drsize(text+i, &FONT_USED, DWIDTH-(BOX_HEIGHT*PXSIZE+PXSIZE), NULL);
|
||||
|
@ -80,8 +82,8 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
|||
/* Loop from the end to the start for word wrap. */
|
||||
if(*(c+1) != '\0'){
|
||||
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 we found a space, we can draw this line and do the same
|
||||
* for the next line. */
|
||||
if(text[i+n] == ' '){
|
||||
dtext_opt(BOX_HEIGHT*PXSIZE, y, C_BLACK, C_NONE, DTEXT_LEFT,
|
||||
DTEXT_TOP, text+i, n); /* Draw everything. */
|
||||
|
@ -103,14 +105,14 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
|||
/* We drew one entire screen, reset everything to draw the next one.
|
||||
*/
|
||||
/* Make a little animation :). */
|
||||
blit();
|
||||
while(game->frame_duration < 100) sleep();
|
||||
if(line_anim) blit();
|
||||
while(game->frame_duration < line_duration) sleep();
|
||||
game->frame_duration = 0;
|
||||
/* Ask the user to press EXE to continue. */
|
||||
dtext(BOX_HEIGHT*PXSIZE, y, C_BLACK, "[EXE] to continue ...");
|
||||
}
|
||||
/* Make a little animation :). */
|
||||
blit();
|
||||
if(line_anim) blit();
|
||||
if(l>=max_lines_amount-1){
|
||||
while(getkey().key != KEY_EXE) sleep();
|
||||
/* Clear the screen. */
|
||||
|
@ -121,22 +123,22 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
|||
l = 0;
|
||||
}
|
||||
else{
|
||||
while(game->frame_duration < 100) sleep();
|
||||
while(game->frame_duration < line_duration) 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 :). */
|
||||
blit();
|
||||
while(game->frame_duration < 100) sleep();
|
||||
if(line_anim) blit();
|
||||
while(game->frame_duration < line_duration) sleep();
|
||||
game->frame_duration = 0;
|
||||
/* Ask the user to press EXE to continue. */
|
||||
dtext(BOX_HEIGHT*PXSIZE, y, C_BLACK, "[EXE] to continue ...");
|
||||
blit();
|
||||
if(line_anim) blit();
|
||||
while(getkey().key != KEY_EXE) sleep();
|
||||
}
|
||||
if(call_before_end) return_int = call_before_end(game);
|
||||
if(call_before_end) return_int = call_before_end(game, i);
|
||||
if(end_anim){
|
||||
/* Run another little fancy animation. */
|
||||
for(i=40;i>0;i--){
|
||||
|
@ -155,64 +157,27 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
|||
return return_int;
|
||||
}
|
||||
|
||||
void showtext(Game *game, bopti_image_t *face, char *text) {
|
||||
showtext_opt(game, face, text, NULL, true, true);
|
||||
}
|
||||
|
||||
void showtext_dialog_start(Game *game, bopti_image_t *face, char *text) {
|
||||
showtext_opt(game, face, text, NULL, true, false);
|
||||
}
|
||||
|
||||
void showtext_dialog_mid(Game *game, bopti_image_t *face, char *text) {
|
||||
showtext_opt(game, face, text, NULL, false, false);
|
||||
}
|
||||
|
||||
void showtext_dialog_end(Game *game, bopti_image_t *face, char *text) {
|
||||
showtext_opt(game, face, text, NULL, false, true);
|
||||
void showtext_dialog(Game *game, bopti_image_t *face, char *text,
|
||||
bool dialog_start, bool dialog_end) {
|
||||
showtext_opt(game, face, text, NULL, dialog_start, dialog_end, NULL, 100,
|
||||
true, 0);
|
||||
}
|
||||
|
||||
#define CHOICE_BOX_HEIGHT 10
|
||||
#define CHOICE_BOX_PADDING_TOP 3
|
||||
|
||||
char *_choices;
|
||||
char *_choices, *_text;
|
||||
int _choices_amount, _default_choice;
|
||||
bopti_image_t *_face;
|
||||
unsigned int _i;
|
||||
|
||||
/* store_vram_part(int x1, int y1, int x2, int y2) and restore_vram_part(int x,
|
||||
* int y) are needed in the animations of the interaction dialog. */
|
||||
|
||||
#ifdef FXCG50
|
||||
#include <gint/image.h>
|
||||
image_t vram_part_reference;
|
||||
image_t *vram_part = NULL;
|
||||
#else
|
||||
// Really need to code this!
|
||||
#endif
|
||||
|
||||
void store_vram_part(int x, int y, int w, int h) {
|
||||
#ifdef FXCG50
|
||||
if(image_valid(vram_part)) image_free(vram_part);
|
||||
image_sub(image_create_vram(), x, y, w, h, &vram_part_reference);
|
||||
vram_part = image_alloc(w, h, IMAGE_RGB565);
|
||||
if(vram_part){
|
||||
image_copy(&vram_part_reference, vram_part, true);
|
||||
}
|
||||
#else
|
||||
// Really need to code this!
|
||||
#endif
|
||||
}
|
||||
void restore_vram_part(int x, int y) {
|
||||
#ifdef FXCG50
|
||||
dimage(x, y, vram_part);
|
||||
#else
|
||||
// Really need to code this!
|
||||
#endif
|
||||
void _choice_screen_call(Game *game, unsigned int i) {
|
||||
_i = i;
|
||||
}
|
||||
|
||||
int _choice_call_before_end(Game *game) {
|
||||
int _choice_call_before_end(Game *game, unsigned int org_i) {
|
||||
int i, key;
|
||||
/* Make a little animation because we looove little animations ;) */
|
||||
store_vram_part(0, BOX_HEIGHT*PXSIZE,
|
||||
DWIDTH, (CHOICE_BOX_HEIGHT+2)*PXSIZE);
|
||||
for(i=0;i<DWIDTH/8+1;i++){
|
||||
drect(0, BOX_HEIGHT*PXSIZE, i*(DWIDTH/8),
|
||||
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE);
|
||||
|
@ -262,22 +227,19 @@ int _choice_call_before_end(Game *game) {
|
|||
}while(key != KEY_EXE);
|
||||
/* Make a little animation because we looove little animations ;) */
|
||||
for(i=DWIDTH/8+1;i>0;i--){
|
||||
restore_vram_part(0, BOX_HEIGHT*PXSIZE);
|
||||
draw(game);
|
||||
showtext_opt(game, _face, _text, NULL, false, false, NULL, 0, false,
|
||||
_i);
|
||||
drect(0, BOX_HEIGHT*PXSIZE, i*(DWIDTH/8),
|
||||
(BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE, C_WHITE);
|
||||
drect(i*(DWIDTH/8), BOX_HEIGHT*PXSIZE, i*(DWIDTH/8)+PXSIZE-1,
|
||||
(BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE, C_BLACK);
|
||||
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE+1, i*(DWIDTH/8),
|
||||
(BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE, C_BLACK);
|
||||
blit();
|
||||
dupdate();
|
||||
while(game->frame_duration < 20) sleep();
|
||||
game->frame_duration = 0;
|
||||
}
|
||||
#ifdef FXCG50
|
||||
if(vram_part) image_free(vram_part);
|
||||
#else
|
||||
// Really need to code this!
|
||||
#endif
|
||||
return selected;
|
||||
}
|
||||
|
||||
|
@ -287,5 +249,8 @@ int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start,
|
|||
_choices = choices;
|
||||
_choices_amount = choices_amount;
|
||||
_default_choice = default_choice;
|
||||
return showtext_opt(game, face, text, _choice_call_before_end, start, end);
|
||||
_face = face;
|
||||
_text = text;
|
||||
return showtext_opt(game, face, text, _choice_call_before_end, start, end,
|
||||
_choice_screen_call, 100, true, 0);
|
||||
}
|
||||
|
|
|
@ -10,16 +10,14 @@
|
|||
#define F_HEIGHT (32*PXSIZE)
|
||||
|
||||
int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
||||
int call_before_end(Game *game), bool start_anim,
|
||||
bool end_anim);
|
||||
int call_before_end(Game *game, unsigned int i),
|
||||
bool start_anim,
|
||||
bool end_anim,
|
||||
void for_each_screen(Game *game, unsigned int i),
|
||||
int line_duration, bool line_anim, unsigned int start_i);
|
||||
|
||||
void showtext(Game *game, bopti_image_t *face, char *text);
|
||||
|
||||
void showtext_dialog_start(Game *game, bopti_image_t *face, char *text);
|
||||
|
||||
void showtext_dialog_mid(Game *game, bopti_image_t *face, char *text);
|
||||
|
||||
void showtext_dialog_end(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);
|
||||
|
||||
int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start,
|
||||
bool end, char *choices, int choices_amount,
|
||||
|
|
|
@ -99,10 +99,10 @@ int main(void) {
|
|||
dgray(DGRAY_ON);
|
||||
#endif
|
||||
|
||||
showtext(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.");
|
||||
showtext(&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);
|
||||
if(in) showtext_dialog_end(&game, &player_face_img, "You choosed ipsum");
|
||||
else showtext_dialog_end(&game, &player_face_img, "You choosed Lorem");
|
||||
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);
|
||||
do{
|
||||
/* clear screen */
|
||||
dclear(C_WHITE);
|
||||
|
|
Loading…
Reference in a new issue