mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +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 showtext_opt(Game *game, bopti_image_t *face, char *text,
|
||||||
int call_before_end(Game *game), bool start_anim,
|
int call_before_end(Game *game, unsigned int i),
|
||||||
bool end_anim) {
|
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);
|
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;
|
||||||
|
@ -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,
|
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;
|
||||||
}
|
}
|
||||||
|
@ -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,
|
dsubimage(4*PXSIZE, 2*PXSIZE, face, 0, 0, F_WIDTH,
|
||||||
(BOX_HEIGHT-7)*PXSIZE, DIMAGE_NONE);
|
(BOX_HEIGHT-7)*PXSIZE, DIMAGE_NONE);
|
||||||
|
|
||||||
dupdate();
|
if(line_anim) dupdate();
|
||||||
|
|
||||||
while(game->frame_duration < 20) sleep();
|
while(game->frame_duration < 20) sleep();
|
||||||
game->frame_duration = 0;
|
game->frame_duration = 0;
|
||||||
}
|
}
|
||||||
/* 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=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
|
/* 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);
|
||||||
|
@ -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. */
|
/* Loop from the end to the start for word wrap. */
|
||||||
if(*(c+1) != '\0'){
|
if(*(c+1) != '\0'){
|
||||||
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 for
|
/* If we found a space, we can draw this line and do the same
|
||||||
* the next line. */
|
* for the next line. */
|
||||||
if(text[i+n] == ' '){
|
if(text[i+n] == ' '){
|
||||||
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, n); /* Draw everything. */
|
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.
|
/* We drew one entire screen, reset everything to draw the next one.
|
||||||
*/
|
*/
|
||||||
/* Make a little animation :). */
|
/* Make a little animation :). */
|
||||||
blit();
|
if(line_anim) blit();
|
||||||
while(game->frame_duration < 100) sleep();
|
while(game->frame_duration < line_duration) sleep();
|
||||||
game->frame_duration = 0;
|
game->frame_duration = 0;
|
||||||
/* 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 ...");
|
||||||
}
|
}
|
||||||
/* Make a little animation :). */
|
/* Make a little animation :). */
|
||||||
blit();
|
if(line_anim) blit();
|
||||||
if(l>=max_lines_amount-1){
|
if(l>=max_lines_amount-1){
|
||||||
while(getkey().key != KEY_EXE) sleep();
|
while(getkey().key != KEY_EXE) sleep();
|
||||||
/* Clear the screen. */
|
/* Clear the screen. */
|
||||||
|
@ -121,22 +123,22 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
||||||
l = 0;
|
l = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
while(game->frame_duration < 100) sleep();
|
while(game->frame_duration < line_duration) sleep();
|
||||||
game->frame_duration = 0;
|
game->frame_duration = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(l<max_lines_amount-1){
|
if(l<max_lines_amount-1){
|
||||||
/* If we have not filled everthing with text at the end. */
|
/* If we have not filled everthing with text at the end. */
|
||||||
/* Make a little animation :). */
|
/* Make a little animation :). */
|
||||||
blit();
|
if(line_anim) blit();
|
||||||
while(game->frame_duration < 100) sleep();
|
while(game->frame_duration < line_duration) sleep();
|
||||||
game->frame_duration = 0;
|
game->frame_duration = 0;
|
||||||
/* 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 ...");
|
||||||
blit();
|
if(line_anim) blit();
|
||||||
while(getkey().key != KEY_EXE) sleep();
|
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){
|
if(end_anim){
|
||||||
/* Run another little fancy animation. */
|
/* Run another little fancy animation. */
|
||||||
for(i=40;i>0;i--){
|
for(i=40;i>0;i--){
|
||||||
|
@ -155,64 +157,27 @@ int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
||||||
return return_int;
|
return return_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
void showtext(Game *game, bopti_image_t *face, char *text) {
|
void showtext_dialog(Game *game, bopti_image_t *face, char *text,
|
||||||
showtext_opt(game, face, text, NULL, true, true);
|
bool dialog_start, bool dialog_end) {
|
||||||
}
|
showtext_opt(game, face, text, NULL, dialog_start, dialog_end, NULL, 100,
|
||||||
|
true, 0);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHOICE_BOX_HEIGHT 10
|
#define CHOICE_BOX_HEIGHT 10
|
||||||
#define CHOICE_BOX_PADDING_TOP 3
|
#define CHOICE_BOX_PADDING_TOP 3
|
||||||
|
|
||||||
char *_choices;
|
char *_choices, *_text;
|
||||||
int _choices_amount, _default_choice;
|
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,
|
void _choice_screen_call(Game *game, unsigned int i) {
|
||||||
* int y) are needed in the animations of the interaction dialog. */
|
_i = i;
|
||||||
|
|
||||||
#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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _choice_call_before_end(Game *game) {
|
int _choice_call_before_end(Game *game, unsigned int org_i) {
|
||||||
int i, key;
|
int i, key;
|
||||||
/* Make a little animation because we looove little animations ;) */
|
/* 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++){
|
for(i=0;i<DWIDTH/8+1;i++){
|
||||||
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);
|
||||||
|
@ -262,22 +227,19 @@ int _choice_call_before_end(Game *game) {
|
||||||
}while(key != KEY_EXE);
|
}while(key != KEY_EXE);
|
||||||
/* Make a little animation because we looove little animations ;) */
|
/* 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--){
|
||||||
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),
|
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,
|
||||||
(BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE, C_BLACK);
|
(BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE, C_BLACK);
|
||||||
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE+1, i*(DWIDTH/8),
|
drect(0, (BOX_HEIGHT+CHOICE_BOX_HEIGHT)*PXSIZE+1, i*(DWIDTH/8),
|
||||||
(BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE, C_BLACK);
|
(BOX_HEIGHT+CHOICE_BOX_HEIGHT+1)*PXSIZE, C_BLACK);
|
||||||
blit();
|
dupdate();
|
||||||
while(game->frame_duration < 20) sleep();
|
while(game->frame_duration < 20) sleep();
|
||||||
game->frame_duration = 0;
|
game->frame_duration = 0;
|
||||||
}
|
}
|
||||||
#ifdef FXCG50
|
|
||||||
if(vram_part) image_free(vram_part);
|
|
||||||
#else
|
|
||||||
// Really need to code this!
|
|
||||||
#endif
|
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,5 +249,8 @@ int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start,
|
||||||
_choices = choices;
|
_choices = choices;
|
||||||
_choices_amount = choices_amount;
|
_choices_amount = choices_amount;
|
||||||
_default_choice = default_choice;
|
_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)
|
#define F_HEIGHT (32*PXSIZE)
|
||||||
|
|
||||||
int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
int showtext_opt(Game *game, bopti_image_t *face, char *text,
|
||||||
int call_before_end(Game *game), bool start_anim,
|
int call_before_end(Game *game, unsigned int i),
|
||||||
bool end_anim);
|
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(Game *game, bopti_image_t *face, char *text,
|
||||||
|
bool dialog_start, bool dialog_end);
|
||||||
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);
|
|
||||||
|
|
||||||
int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start,
|
int showtext_dialog_ask(Game *game, bopti_image_t *face, char *text, bool start,
|
||||||
bool end, char *choices, int choices_amount,
|
bool end, char *choices, int choices_amount,
|
||||||
|
|
|
@ -99,10 +99,10 @@ 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.");
|
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);
|
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");
|
if(in) showtext_dialog(&game, &player_face_img, "You choosed ipsum", false, true);
|
||||||
else showtext_dialog_end(&game, &player_face_img, "You choosed Lorem");
|
else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true);
|
||||||
do{
|
do{
|
||||||
/* clear screen */
|
/* clear screen */
|
||||||
dclear(C_WHITE);
|
dclear(C_WHITE);
|
||||||
|
|
Loading…
Reference in a new issue