diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ad87c6b82..069186f28 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-Rebirth Changelog 20100317 -------- main/menu.c, main/menu.h: Add hide_menus and show_menus (for later use in the case of D1X) +main/titles.c: Make briefing into a window, allowing more flexibility with other windows and tidying code up 20100317 -------- diff --git a/main/titles.c b/main/titles.c index 71c0fe211..3b5aefb00 100644 --- a/main/titles.c +++ b/main/titles.c @@ -163,6 +163,20 @@ void show_titles(void) show_title_screen( (((SWIDTH>=640&&SHEIGHT>=480) && cfexist("descenth.pcx"))?"descenth.pcx":"descent.pcx"), 1, 1 ); } +void show_order_form() +{ + char exit_screen[16]; + + strcpy(exit_screen, "warning.pcx"); // D1 Registered + if (! cfexist(exit_screen)) + strcpy(exit_screen, "apple.pcx"); // D1 Mac OEM Demo + if (! cfexist(exit_screen)) + strcpy(exit_screen, "order01.pcx"); // D1 Demo + show_title_screen(exit_screen, 1, 1); +} + + +//----------------------------------------------------------------------------- typedef struct { char bs_name[14]; // filename, eg merc01. Assumes .lbm suffix. sbyte level_num; @@ -306,21 +320,8 @@ briefing_screen Briefing_screens_h[] = { // hires screens #define MAX_BRIEFING_SCREEN (sizeof(Briefing_screens) / sizeof(Briefing_screens[0])) -char * get_briefing_screen( int level_num ) +typedef struct msgstream { - int i, found_level=0, last_level=0; - for (i = 0; i < MAX_BRIEFING_SCREEN; i++) { - if ( found_level && Briefing_screens_LH[i].level_num != level_num ) - return Briefing_screens_LH[last_level].bs_name; - if (Briefing_screens[i].level_num == level_num ) { - found_level=1; - last_level = i; - } - } - return NULL; -} - -typedef struct msgstream { int x; int y; int color; @@ -342,7 +343,9 @@ typedef struct briefing short tab_stop; ubyte flashing_cursor; ubyte new_page; - int delay_count; + int new_screen; + fix start_time; + fix delay_count; int robot_num; grs_canvas *robot_canv; vms_angvec robot_angles; @@ -356,7 +359,12 @@ typedef struct briefing void briefing_init(briefing *br, short level_num) { br->level_num = level_num; + if (br->level_num == 1) + br->level_num = 0; // for start of game stuff + br->cur_screen = 0; + br->screen = NULL; + gr_init_bitmap_data (&br->background); strcpy(br->background_name, DEFAULT_BRIEFING_BKG); br->robot_canv = NULL; br->bitmap_name[0] = '\0'; @@ -365,12 +373,338 @@ void briefing_init(briefing *br, short level_num) br->animating_bitmap_type = 0; } +//----------------------------------------------------------------------------- +// Load Descent briefing text. +int load_screen_text(char *filename, char **buf) +{ + CFILE *tfile; + CFILE *ifile; + int len; + int have_binary = 0; + + if ((tfile = cfopen(filename,"rb")) == NULL) { + char nfilename[30], *ptr; + + strcpy(nfilename, filename); + if ((ptr = strrchr(nfilename, '.'))) + *ptr = '\0'; + strcat(nfilename, ".txb"); + if ((ifile = cfopen(nfilename, "rb")) == NULL) { + return (0); + //Error("Cannot open file %s or %s", filename, nfilename); + } + + have_binary = 1; + + len = cfilelength(ifile); + MALLOC(*buf, char, len+1); + cfread(*buf, 1, len, ifile); + cfclose(ifile); + } else { + len = cfilelength(tfile); + MALLOC(*buf, char, len+1); + cfread(*buf, 1, len, tfile); + cfclose(tfile); + } + + if (have_binary) + decode_text(*buf, len); + + *(*buf+len)='\0'; + + return (1); +} + +int get_message_num(char **message) +{ + int num=0; + + while (strlen(*message) > 0 && **message == ' ') + (*message)++; + + while (strlen(*message) > 0 && (**message >= '0') && (**message <= '9')) { + num = 10*num + **message-'0'; + (*message)++; + } + + while (strlen(*message) > 0 && *(*message)++ != 10) // Get and drop eoln + ; + + return num; +} + +void get_message_name(char **message, char *result) +{ + while (strlen(*message) > 0 && **message == ' ') + (*message)++; + + while (strlen(*message) > 0 && (**message != ' ') && (**message != 10)) { + if (**message != '\n') + *result++ = **message; + (*message)++; + } + + if (**message != 10) + while (strlen(*message) > 0 && *(*message)++ != 10) // Get and drop eoln + ; + + *result = 0; +} + +// Return a pointer to the start of text for screen #screen_num. +char * get_briefing_message(briefing *br, int screen_num) +{ + char *tptr = br->text; + int cur_screen=0; + int ch; + + Assert(screen_num >= 0); + + while ( (*tptr != 0 ) && (screen_num != cur_screen)) { + ch = *tptr++; + if (ch == '$') { + ch = *tptr++; + if (ch == 'S') + cur_screen = get_message_num(&tptr); + } + } + + if (screen_num!=cur_screen) + return (NULL); + + return tptr; +} + void init_char_pos(briefing *br, int x, int y) { br->text_x = x; br->text_y = y; } +// Make sure the text stays on the screen +// Return 1 if new page required +// 0 otherwise +int check_text_pos(briefing *br) +{ + if (br->text_x > br->screen->text_ulx + br->screen->text_width) + { + br->text_x = br->screen->text_ulx; + br->text_y += br->screen->text_uly; + } + + if (br->text_y > br->screen->text_uly + br->screen->text_height) + { + br->new_page = 1; + return 1; + } + + return 0; +} + +void put_char_delay(briefing *br, int ch) +{ + char str[] = { ch, '\0' }; + int w, h, aw; + + if (br->delay_count && (timer_get_fixed_seconds() < br->start_time + br->delay_count)) + { + br->message--; // Go back to same character + return; + } + + br->messagestream[br->streamcount].x = br->text_x; + br->messagestream[br->streamcount].y = br->text_y; + br->messagestream[br->streamcount].color = Briefing_text_colors[Current_color]; + br->messagestream[br->streamcount].ch = ch; + br->streamcount++; + + br->prev_ch = ch; + gr_get_string_size(str, &w, &h, &aw ); + br->text_x += w; + + br->start_time = timer_get_fixed_seconds(); +} + +void init_spinning_robot(briefing *br); +int load_briefing_screen(briefing *br, char *fname); + +// Process a character for the briefing, +// including special characters preceded by a '$'. +// Return 1 when page is finished, 0 otherwise +int briefing_process_char(briefing *br) +{ + int ch; + + ch = *br->message++; + if (ch == '$') { + ch = *br->message++; + if (ch == 'C') { + Current_color = get_message_num(&br->message)-1; + Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS)); + br->prev_ch = 10; + } else if (ch == 'F') { // toggle flashing cursor + br->flashing_cursor = !br->flashing_cursor; + br->prev_ch = 10; + while (*br->message++ != 10) + ; + } else if (ch == 'T') { + br->tab_stop = get_message_num(&br->message); + br->tab_stop*=(1+HIRESMODE); + br->prev_ch = 10; // read to eoln + } else if (ch == 'R') { + if (br->robot_canv != NULL) + { + d_free(br->robot_canv); + br->robot_canv=NULL; + } + + init_spinning_robot(br); + br->robot_num = get_message_num(&br->message); + while (*br->message++ != 10) + ; + br->prev_ch = 10; // read to eoln + } else if (ch == 'N') { + if (br->robot_canv != NULL) + { + d_free(br->robot_canv); + br->robot_canv=NULL; + } + + get_message_name(&br->message, br->bitmap_name); + strcat(br->bitmap_name, "#0"); + br->animating_bitmap_type = 0; + br->prev_ch = 10; + } else if (ch == 'O') { + if (br->robot_canv != NULL) + { + d_free(br->robot_canv); + br->robot_canv=NULL; + } + + get_message_name(&br->message, br->bitmap_name); + strcat(br->bitmap_name, "#0"); + br->animating_bitmap_type = 1; + br->prev_ch = 10; + } else if (ch == 'B') { + char bitmap_name[32]; + ubyte temp_palette[768]; + int iff_error; + + if (br->robot_canv != NULL) + { + d_free(br->robot_canv); + br->robot_canv=NULL; + } + + get_message_name(&br->message, bitmap_name); + strcat(bitmap_name, ".bbm"); + gr_init_bitmap_data (&br->guy_bitmap); + iff_error = iff_read_bitmap(bitmap_name, &br->guy_bitmap, BM_LINEAR, temp_palette); + Assert(iff_error == IFF_NO_ERROR); + gr_remap_bitmap_good( &br->guy_bitmap, temp_palette, -1, -1 ); + + br->guy_bitmap_show=1; + br->prev_ch = 10; + } else if (ch == 'S') { + br->new_screen = 1; + return 1; + } else if (ch == 'P') { // New page. + br->new_page = 1; + + while (*br->message != 10) { + br->message++; // drop carriage return after special escape sequence + } + br->message++; + br->prev_ch = 10; + + return 1; + } else if (ch == '$' || ch == ';') // Print a $/; + put_char_delay(br, ch); + } else if (ch == '\t') { // Tab + if (br->text_x - br->screen->text_ulx < br->tab_stop) + br->text_x = br->screen->text_ulx + br->tab_stop; + } else if ((ch == ';') && (br->prev_ch == 10)) { + while (*br->message++ != 10) + ; + br->prev_ch = 10; + } else if (ch == '\\') { + br->prev_ch = ch; + } else if (ch == 10) { + if (br->prev_ch != '\\') { + br->prev_ch = ch; + br->text_y += FSPACY(5)+FSPACY(5)*3/5; + br->text_x = br->screen->text_ulx; + if (br->text_y > br->screen->text_uly + br->screen->text_height) { + load_briefing_screen(br, Briefing_screens[br->cur_screen].bs_name); + br->text_x = br->screen->text_ulx; + br->text_y = br->screen->text_uly; + } + } else { + if (ch == 13) //Can this happen? Above says ch==10 + Int3(); + br->prev_ch = ch; + } + } else + put_char_delay(br, ch); + + return 0; +} + +void set_briefing_fontcolor () +{ + Briefing_text_colors[0] = gr_find_closest_color_current( 0, 40, 0); + Briefing_text_colors[1] = gr_find_closest_color_current( 40, 33, 35); + Briefing_text_colors[2] = gr_find_closest_color_current( 8, 31, 54); + + //green + Briefing_text_colors[0] = gr_find_closest_color_current( 0, 54, 0); + //white + Briefing_text_colors[1] = gr_find_closest_color_current( 42, 38, 32); + + //Begin D1X addition + //red + Briefing_text_colors[2] = gr_find_closest_color_current( 63, 0, 0); + + //blue + Briefing_text_colors[3] = gr_find_closest_color_current( 0, 0, 54); + //gray + Briefing_text_colors[4] = gr_find_closest_color_current( 14, 14, 14); + //yellow + Briefing_text_colors[5] = gr_find_closest_color_current( 54, 54, 0); + //purple + Briefing_text_colors[6] = gr_find_closest_color_current( 0, 54, 54); + //End D1X addition + + Erase_color = gr_find_closest_color_current(0, 0, 0); +} + +void redraw_messagestream(msgstream *stream, int count) +{ + char msgbuf[2]; + int i; + + for (i=0; i (F1_0/4)) + gr_set_fontcolor(Briefing_text_colors[Current_color], -1); + else + gr_set_fontcolor(Erase_color, -1); + + gr_printf(br->text_x, br->text_y, "_" ); +} + #define EXIT_DOOR_MAX 14 #define OTHER_THING_MAX 10 // Adam: This is the number of frames in your new animating thing. #define DOOR_DIV_INIT 6 @@ -499,6 +833,16 @@ void show_briefing_bitmap(grs_bitmap *bmp) } //----------------------------------------------------------------------------- +void init_spinning_robot(briefing *br) //(int x,int y,int w,int h) +{ + int x = rescale_x(138); + int y = rescale_y(55); + int w = rescale_x(166); + int h = rescale_y(138); + + br->robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h); +} + void show_spinning_robot_frame(briefing *br, int robot_num) { grs_canvas *curcanv_save; @@ -516,72 +860,28 @@ void show_spinning_robot_frame(briefing *br, int robot_num) } //----------------------------------------------------------------------------- -void init_spinning_robot(briefing *br) //(int x,int y,int w,int h) +#define KEY_DELAY_DEFAULT ((F1_0*20)/1000) + +void init_new_page(briefing *br) { - int x = rescale_x(138); - int y = rescale_y(55); - int w = rescale_x(166); - int h = rescale_y(138); - - br->robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h); -} - -//--------------------------------------------------------------------------- -// Returns char width. -// If show_robot_flag set, then show a frame of the spinning robot. -int show_char_delay(briefing *br, char the_char, int delay, int robot_num, int cursor_flag) -{ - int w, h, aw; - char message[2]; - static fix start_time = 0; - int i; - - message[0] = the_char; - message[1] = 0; - - if (start_time==0 && timer_get_fixed_seconds()<0) - start_time=timer_get_fixed_seconds(); - - gr_get_string_size(message, &w, &h, &aw ); - - Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS)); - - // Draw cursor if there is some delay and caller says to draw cursor - if (delay) - { - if (cursor_flag) - { - gr_set_fontcolor(Briefing_text_colors[Current_color], -1); - gr_printf(br->text_x, br->text_y, "_" ); - } - - for (i=0; i<2; i++) - { - if (br->bitmap_name[0] != 0) - show_animated_bitmap(br); - - while (timer_get_fixed_seconds() < start_time + delay/2); - if (robot_num != -1) - show_spinning_robot_frame(br, robot_num); - - start_time = timer_get_fixed_seconds(); - } - - // Erase cursor - if (cursor_flag) - { - gr_set_fontcolor(Erase_color, -1); - gr_printf(br->text_x, br->text_y, "_" ); - } + br->new_page = 0; + br->robot_num = -1; + + load_briefing_screen(br, br->background_name); + br->text_x = br->screen->text_ulx; + br->text_y = br->screen->text_uly; + + br->streamcount=0; + if (br->guy_bitmap_show) { + gr_free_bitmap_data (&br->guy_bitmap); + br->guy_bitmap_show=0; } - - // Draw the character - gr_set_fontcolor(Briefing_text_colors[Current_color], -1); - gr_printf(br->text_x+1, br->text_y, message ); - - return w; + + br->start_time = 0; + br->delay_count = KEY_DELAY_DEFAULT; } +// ----------------------------------------------------------------------------- ubyte baldguy_cheat = 0; static ubyte bald_guy_cheat_index = 0; char new_baldguy_pcx[] = "btexture.xxx"; @@ -610,14 +910,14 @@ void bald_guy_cheat(int key) bald_guy_cheat_index = 0; } -// ----------------------------------------------------------------------------- +void free_briefing_screen(briefing *br); + // loads a briefing screen int load_briefing_screen(briefing *br, char *fname) { int pcx_error; - if (br->background.bm_data != NULL) - gr_free_bitmap_data(&br->background); + free_briefing_screen(br); gr_init_bitmap_data(&br->background); @@ -636,44 +936,92 @@ int load_briefing_screen(briefing *br, char *fname) set_briefing_fontcolor(); + MALLOC(br->screen, briefing_screen, 1); + if (!br->screen) + return 0; + + memcpy(br->screen, &Briefing_screens[br->cur_screen], sizeof(briefing_screen)); + br->screen->text_ulx = rescale_x(br->screen->text_ulx); + br->screen->text_uly = rescale_y(br->screen->text_uly); + br->screen->text_width = rescale_x(br->screen->text_width); + br->screen->text_height = rescale_y(br->screen->text_height); + init_char_pos(br, br->screen->text_ulx, br->screen->text_uly); + + return 1; +} + +void free_briefing_screen(briefing *br) +{ + if (br->robot_canv != NULL) + d_free(br->robot_canv); + + if (br->screen != NULL) + d_free(br->screen); + + if (br->background.bm_data != NULL) + gr_free_bitmap_data (&br->background); +} + + + +int new_briefing_screen(briefing *br, int first) +{ + br->new_screen = 0; + + if (!first) + br->cur_screen++; + + while ((br->cur_screen < MAX_BRIEFING_SCREEN) && (Briefing_screens[br->cur_screen].level_num != br->level_num)) + { + br->cur_screen++; + if ((br->cur_screen == MAX_BRIEFING_SCREEN) && (br->level_num == 0)) + { + // Showed the pre-game briefing, now show level 1 briefing + br->level_num++; + br->cur_screen = 0; + } + } + + if (br->cur_screen == MAX_BRIEFING_SCREEN) + return 0; // finished + + if (!load_briefing_screen(br, Briefing_screens_LH[br->cur_screen].bs_name)) + return 0; + + br->message = get_briefing_message(br, Briefing_screens[br->cur_screen].message_num); + + if (br->message==NULL) + return 0; + + Current_color = 0; + br->streamcount = 0; + br->tab_stop = 0; + br->flashing_cursor = 0; + br->new_page = 0; + br->start_time = 0; + br->delay_count = KEY_DELAY_DEFAULT; + br->robot_num = -1; + br->bitmap_name[0] = 0; + br->guy_bitmap_show = 0; + br->prev_ch = -1; + return 1; } - -#define KEY_DELAY_DEFAULT ((F1_0*20)/1000) - //----------------------------------------------------------------------------- -int get_message_num(char **message) -{ - int num=0; - - while (strlen(*message) > 0 && **message == ' ') - (*message)++; - - while (strlen(*message) > 0 && (**message >= '0') && (**message <= '9')) { - num = 10*num + **message-'0'; - (*message)++; - } - - while (strlen(*message) > 0 && *(*message)++ != 10) // Get and drop eoln - ; - - return num; -} - void title_save_game() { grs_canvas * save_canv; grs_canvas * save_canv_data; grs_font * save_font; ubyte palette[768]; - + if ( Next_level_num == 0 ) return; save_canv = grd_curcanv; save_font = grd_curcanv->cv_font; - + save_canv_data = gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h ); gr_set_current_canvas(save_canv_data); gr_ubitmap(0,0,&save_canv->cv_bitmap); @@ -691,458 +1039,129 @@ void title_save_game() gr_set_curfont(save_font); } - //----------------------------------------------------------------------------- -void get_message_name(char **message, char *result) +int briefing_handler(window *wind, d_event *event, briefing *br) { - while (strlen(*message) > 0 && **message == ' ') - (*message)++; - - while (strlen(*message) > 0 && (**message != ' ') && (**message != 10)) { - if (**message != '\n') - *result++ = **message; - (*message)++; - } - - if (**message != 10) - while (strlen(*message) > 0 && *(*message)++ != 10) // Get and drop eoln - ; - - *result = 0; -} - -//----------------------------------------------------------------------------- -void flash_cursor(briefing *br, int cursor_flag) -{ - if (cursor_flag == 0) - return; - - if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4)) - gr_set_fontcolor(Briefing_text_colors[Current_color], -1); - else - gr_set_fontcolor(Erase_color, -1); - - gr_printf(br->text_x, br->text_y, "_" ); -} - -void redraw_messagestream(msgstream *stream, int count) -{ - char msgbuf[2]; - int i; - - for (i=0; istreamcount = 0; - br->tab_stop = 0; - br->flashing_cursor = 0; - br->new_page = 0; - br->delay_count = KEY_DELAY_DEFAULT; - br->robot_num = -1; - br->bitmap_name[0] = 0; - br->guy_bitmap_show = 0; - br->prev_ch = -1; - - gr_set_curfont( GAME_FONT ); - - MALLOC(br->screen, briefing_screen, 1); - memcpy(br->screen, &Briefing_screens[br->cur_screen], sizeof(briefing_screen)); - br->screen->text_ulx = rescale_x(br->screen->text_ulx); - br->screen->text_uly = rescale_y(br->screen->text_uly); - br->screen->text_width = rescale_x(br->screen->text_width); - br->screen->text_height = rescale_y(br->screen->text_height); - init_char_pos(br, br->screen->text_ulx, br->screen->text_uly); - - while (!done) { - ch = *br->message++; - if (ch == '$') { - ch = *br->message++; - if (ch == 'C') { - Current_color = get_message_num(&br->message)-1; - Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS)); - br->prev_ch = 10; - } else if (ch == 'F') { // toggle flashing cursor - br->flashing_cursor = !br->flashing_cursor; - br->prev_ch = 10; - while (*br->message++ != 10) - ; - } else if (ch == 'T') { - br->tab_stop = get_message_num(&br->message); - br->tab_stop*=(1+HIRESMODE); - br->prev_ch = 10; // read to eoln - } else if (ch == 'R') { - if (br->robot_canv != NULL) - { - d_free(br->robot_canv); - br->robot_canv=NULL; - } - - init_spinning_robot(br); - br->robot_num = get_message_num(&br->message); - while (*br->message++ != 10) - ; - br->prev_ch = 10; // read to eoln - } else if (ch == 'N') { - if (br->robot_canv != NULL) - { - d_free(br->robot_canv); - br->robot_canv=NULL; - } - - get_message_name(&br->message, br->bitmap_name); - strcat(br->bitmap_name, "#0"); - br->animating_bitmap_type = 0; - br->prev_ch = 10; - } else if (ch == 'O') { - if (br->robot_canv != NULL) - { - d_free(br->robot_canv); - br->robot_canv=NULL; - } - - get_message_name(&br->message, br->bitmap_name); - strcat(br->bitmap_name, "#0"); - br->animating_bitmap_type = 1; - br->prev_ch = 10; - } else if (ch == 'B') { - char bitmap_name[32]; - ubyte temp_palette[768]; - int iff_error; - - if (br->robot_canv != NULL) - { - d_free(br->robot_canv); - br->robot_canv=NULL; - } - - get_message_name(&br->message, bitmap_name); - strcat(bitmap_name, ".bbm"); - gr_init_bitmap_data (&br->guy_bitmap); - iff_error = iff_read_bitmap(bitmap_name, &br->guy_bitmap, BM_LINEAR, temp_palette); - Assert(iff_error == IFF_NO_ERROR); - gr_remap_bitmap_good( &br->guy_bitmap, temp_palette, -1, -1 ); - - show_briefing_bitmap(&br->guy_bitmap); - br->guy_bitmap_show=1; - br->prev_ch = 10; - } else if (ch == 'S') { - int keypress; - fix start_time; - - start_time = timer_get_fixed_seconds(); - while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key - - while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2) - ; - timer_delay2(50); - gr_flip(); - show_fullscr(&br->background); - redraw_messagestream(br->messagestream, br->streamcount); - if (br->guy_bitmap_show) - show_briefing_bitmap(&br->guy_bitmap); - flash_cursor(br, br->flashing_cursor); - if (br->robot_num != -1) - show_spinning_robot_frame(br, br->robot_num); - - if (br->bitmap_name[0] != 0) - show_animated_bitmap(br); - start_time += KEY_DELAY_DEFAULT/2; - } - + switch (event->type) + { + case EVENT_WINDOW_ACTIVATED: + case EVENT_WINDOW_DEACTIVATED: + key_flush(); + break; + + case EVENT_KEY_COMMAND: + { + int key = ((d_event_keycommand *)event)->keycode; + + switch (key) + { + case KEY_ALTED+KEY_F2: + title_save_game(); + return 1; + + case KEY_PRINT_SCREEN: + save_screen_shot(0); + return 1; + #ifndef NDEBUG - if (keypress == KEY_BACKSP) + case KEY_BACKSP: Int3(); + return 1; #endif - if (keypress == KEY_ESC) - rval = 1; - br->flashing_cursor = 0; - done = 1; - } else if (ch == 'P') { // New page. + case KEY_ESC: + window_close(wind); + return 1; + + case KEY_SPACEBAR: + case KEY_ENTER: + br->delay_count = 0; + // fall through + + default: + if (br->new_screen) + { + if (!new_briefing_screen(br, 0)) + { + window_close(wind); + return 1; + } + } + else if (br->new_page) + init_new_page(br); + break; + } + break; + } - br->new_page = 1; - - while (*br->message != 10) { - br->message++; // drop carriage return after special escape sequence + case EVENT_IDLE: + timer_delay2(50); + + if (mouse_button_state(0)) + { + if (br->new_screen) + { + if (!new_briefing_screen(br, 0)) + { + window_close(wind); + return 1; + } } - br->message++; - br->prev_ch = 10; - } else if (ch == '$' || ch == ';') { // Print a $/; - br->prev_ch = ch; - br->text_x += show_char_delay(br, ch, br->delay_count, br->robot_num, br->flashing_cursor); + else if (br->new_page) + init_new_page(br); + + br->delay_count = 0; } - } else if (ch == '\t') { // Tab - if (br->text_x - br->screen->text_ulx < br->tab_stop) - br->text_x = br->screen->text_ulx + br->tab_stop; - } else if ((ch == ';') && (br->prev_ch == 10)) { - while (*br->message++ != 10) - ; - br->prev_ch = 10; - } else if (ch == '\\') { - br->prev_ch = ch; - } else if (ch == 10) { - if (br->prev_ch != '\\') { - br->prev_ch = ch; - br->text_y += FSPACY(5)+FSPACY(5)*3/5; - br->text_x = br->screen->text_ulx; - if (br->text_y > br->screen->text_uly + br->screen->text_height) { - load_briefing_screen(br, Briefing_screens[br->cur_screen].bs_name); - br->text_x = br->screen->text_ulx; - br->text_y = br->screen->text_uly; + + if (!(br->new_screen || br->new_page)) + while (!briefing_process_char(br) && !br->delay_count) + { + check_text_pos(br); + if (br->new_page) + break; } - } else { - if (ch == 13) //Can this happen? Above says ch==10 - Int3(); - br->prev_ch = ch; - } - } else { - br->messagestream[br->streamcount].x = br->text_x; - br->messagestream[br->streamcount].y = br->text_y; - br->messagestream[br->streamcount].color = Briefing_text_colors[Current_color]; - br->messagestream[br->streamcount].ch = ch; - if (br->delay_count) { - gr_flip(); - show_fullscr(&br->background); - redraw_messagestream(br->messagestream, br->streamcount); - if (br->flashing_cursor) - gr_printf(br->text_x + FSPACX(7),br->text_y,"_"); - } + check_text_pos(br); + break; + + case EVENT_WINDOW_DRAW: + show_fullscr(&br->background); + if (br->guy_bitmap_show) show_briefing_bitmap(&br->guy_bitmap); - br->streamcount++; + if (br->bitmap_name[0] != 0) + show_animated_bitmap(br); + if (br->robot_num != -1) + show_spinning_robot_frame(br, br->robot_num); - br->prev_ch = ch; - br->text_x += show_char_delay(br, ch, br->delay_count, br->robot_num, br->flashing_cursor); - - } - - // Check for Esc -> abort. - if(br->delay_count) - key_check=local_key_inkey(); - else - key_check=0; - - if ( key_check == KEY_ESC ) { - rval = 1; - done = 1; - } - - if ( key_check == KEY_ALTED+KEY_F2 ) - title_save_game(); - - if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER)) - br->delay_count = 0; - - if (br->text_x > br->screen->text_ulx + br->screen->text_width) { - br->text_x = br->screen->text_ulx; - br->text_y += br->screen->text_uly; - } - - if ((br->new_page) || (br->text_y > br->screen->text_uly + br->screen->text_height)) { - fix start_time = 0; - int keypress; - - br->new_page = 0; - start_time = timer_get_fixed_seconds(); - while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key - while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2) - ; - timer_delay2(50); - gr_flip(); - show_fullscr(&br->background); - redraw_messagestream(br->messagestream, br->streamcount); - if (br->guy_bitmap_show) - show_briefing_bitmap(&br->guy_bitmap); + gr_set_curfont( GAME_FONT ); + + Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS)); + gr_set_fontcolor(Briefing_text_colors[Current_color], -1); + redraw_messagestream(br->messagestream, br->streamcount); + + if (br->new_page || br->new_screen) flash_cursor(br, br->flashing_cursor); - if (br->robot_num != -1) - show_spinning_robot_frame(br, br->robot_num); - if (br->bitmap_name[0] != 0) - show_animated_bitmap(br); - start_time += KEY_DELAY_DEFAULT/2; - } + else if (br->flashing_cursor) + gr_printf(br->text_x, br->text_y, "_"); + break; - br->robot_num = -1; - -#ifndef NDEBUG - if (keypress == KEY_BACKSP) - Int3(); -#endif - if (keypress == KEY_ESC) { - rval = 1; - done = 1; - } - load_briefing_screen(br, br->background_name); - br->text_x = br->screen->text_ulx; - br->text_y = br->screen->text_uly; - - br->streamcount=0; - if (br->guy_bitmap_show) { - gr_free_bitmap_data (&br->guy_bitmap); - br->guy_bitmap_show=0; - } - - br->delay_count = KEY_DELAY_DEFAULT; - } + case EVENT_WINDOW_CLOSE: + free_briefing_screen(br); + d_free(br->text); + d_free(br); + break; + + default: + break; } - - if (br->robot_canv != NULL) - {d_free(br->robot_canv); br->robot_canv=NULL;} - - d_free(br->screen); - if (br->background.bm_data != NULL) - gr_free_bitmap_data (&br->background); - - return rval; + + return 0; } -//----------------------------------------------------------------------------- -// Return a pointer to the start of text for screen #screen_num. -char * get_briefing_message(briefing *br, int screen_num) -{ - char *tptr = br->text; - int cur_screen=0; - int ch; - - Assert(screen_num >= 0); - - while ( (*tptr != 0 ) && (screen_num != cur_screen)) { - ch = *tptr++; - if (ch == '$') { - ch = *tptr++; - if (ch == 'S') - cur_screen = get_message_num(&tptr); - } - } - - if (screen_num!=cur_screen) - return (NULL); - - return tptr; -} - -//----------------------------------------------------------------------------- -// Load Descent briefing text. -int load_screen_text(char *filename, char **buf) -{ - CFILE *tfile; - CFILE *ifile; - int len; - int have_binary = 0; - - if ((tfile = cfopen(filename,"rb")) == NULL) { - char nfilename[30], *ptr; - - strcpy(nfilename, filename); - if ((ptr = strrchr(nfilename, '.'))) - *ptr = '\0'; - strcat(nfilename, ".txb"); - if ((ifile = cfopen(nfilename, "rb")) == NULL) { - return (0); - //Error("Cannot open file %s or %s", filename, nfilename); - } - - have_binary = 1; - - len = cfilelength(ifile); - MALLOC(*buf, char, len+1); - cfread(*buf, 1, len, ifile); - cfclose(ifile); - } else { - len = cfilelength(tfile); - MALLOC(*buf, char, len+1); - cfread(*buf, 1, len, tfile); - cfclose(tfile); - } - - if (have_binary) - decode_text(*buf, len); - - *(*buf+len)='\0'; - - return (1); -} - -//----------------------------------------------------------------------------- -// Return true if message got aborted, else return false. -int show_briefing_text(briefing *br) -{ - br->message = get_briefing_message(br, Briefing_screens[br->cur_screen].message_num); - - if (br->message==NULL) - return (0); - - set_briefing_fontcolor(); - - return show_briefing(br); -} - -void set_briefing_fontcolor () -{ - Briefing_text_colors[0] = gr_find_closest_color_current( 0, 40, 0); - Briefing_text_colors[1] = gr_find_closest_color_current( 40, 33, 35); - Briefing_text_colors[2] = gr_find_closest_color_current( 8, 31, 54); - - //green - Briefing_text_colors[0] = gr_find_closest_color_current( 0, 54, 0); - //white - Briefing_text_colors[1] = gr_find_closest_color_current( 42, 38, 32); - - //Begin D1X addition - //red - Briefing_text_colors[2] = gr_find_closest_color_current( 63, 0, 0); - - //blue - Briefing_text_colors[3] = gr_find_closest_color_current( 0, 0, 54); - //gray - Briefing_text_colors[4] = gr_find_closest_color_current( 14, 14, 14); - //yellow - Briefing_text_colors[5] = gr_find_closest_color_current( 54, 54, 0); - //purple - Briefing_text_colors[6] = gr_find_closest_color_current( 0, 54, 54); - //End D1X addition - - Erase_color = gr_find_closest_color_current(0, 0, 0); -} - -//----------------------------------------------------------------------------- -// Return true if screen got aborted by user, else return false. -int show_briefing_screen(briefing *br) -{ - int rval=0; - - gr_init_bitmap_data (&br->background); - - load_briefing_screen(br, Briefing_screens_LH[br->cur_screen].bs_name); - show_fullscr(&br->background ); - gr_palette_load(gr_palette); - - rval = show_briefing_text(br); - - return rval; -} - - -//----------------------------------------------------------------------------- void do_briefing_screens(char *filename, int level_num) { briefing *br; - int abort_briefing_screens = 0; + window *wind; if (!filename || !*filename) return; @@ -1158,38 +1177,37 @@ void do_briefing_screens(char *filename, int level_num) d_free(br); return; } + + wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))briefing_handler, br); + if (!wind) + { + d_free(br->text); + d_free(br); + return; + } songs_play_song( SONG_BRIEFING, 1 ); set_screen_mode( SCREEN_MENU ); gr_set_current_canvas(NULL); - key_flush(); - - if (br->level_num == 1) { - while ((!abort_briefing_screens) && (Briefing_screens[br->cur_screen].level_num == 0)) { - abort_briefing_screens = show_briefing_screen(br); - br->cur_screen++; - } + if (!new_briefing_screen(br, 1)) + { + window_close(wind); + return; } - if (!abort_briefing_screens) { - for (br->cur_screen = 0; br->cur_screen < MAX_BRIEFING_SCREEN; br->cur_screen++) - if (Briefing_screens[br->cur_screen].level_num == br->level_num) - if (show_briefing_screen(br)) - break; - } - - d_free(br->text); - d_free(br); - - key_flush(); + // Stay where we are in the stack frame until briefing done + // Too complicated otherwise + while (window_exists(wind)) + event_process(); } #ifndef SHAREWARE void do_registered_end_game(void) { briefing *br; + window *wind; if (!Ending_text_filename[0]) //no filename? return; @@ -1208,22 +1226,38 @@ void do_registered_end_game(void) MALLOC(br->text, char, len); sprintf(br->text, "Test"); } - - load_screen_text(Ending_text_filename, &br->text); - for (br->cur_screen = 0; br->cur_screen < MAX_BRIEFING_SCREEN; br->cur_screen++) - if (Briefing_screens[br->cur_screen].level_num == br->level_num) - if (show_briefing_screen(br)) - break; - - d_free(br->text); - d_free(br); + if (!load_screen_text(Ending_text_filename, &br->text) && !((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))) + { + d_free(br); + return; + } + + wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))briefing_handler, br); + if (!wind) + { + d_free(br->text); + d_free(br); + return; + } + + if (!new_briefing_screen(br, 1)) + { + window_close(wind); + return; + } + + // Stay where we are in the stack frame until briefing done + // Too complicated otherwise + while (window_exists(wind)) + event_process(); } #endif void do_shareware_end_game(void) { briefing *br; + window *wind; #ifdef NETWORK if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP)) @@ -1231,29 +1265,38 @@ void do_shareware_end_game(void) kmatrix_view(1); return; } - else #endif - { - MALLOC(br, briefing, 1); - if (!br) - return; - - briefing_init(br, SHAREWARE_ENDING_LEVEL_NUM); - + + MALLOC(br, briefing, 1); + if (!br) + return; + + briefing_init(br, SHAREWARE_ENDING_LEVEL_NUM); + #ifdef DEST_SAT - load_screen_text(Ending_text_filename, &br->text); + load_screen_text(Ending_text_filename, &br->text); #else - load_screen_text(SHAREWARE_ENDING_FILENAME, &br->text); + load_screen_text(SHAREWARE_ENDING_FILENAME, &br->text); #endif + + wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))briefing_handler, br); + if (!wind) + { + d_free(br->text); + d_free(br); + return; } - - for (br->cur_screen = 0; br->cur_screen < MAX_BRIEFING_SCREEN; br->cur_screen++) - if (Briefing_screens[br->cur_screen].level_num == br->level_num) - if (show_briefing_screen(br)) - break; - - d_free(br->text); - d_free(br); + + if (!new_briefing_screen(br, 1)) + { + window_close(wind); + return; + } + + // Stay where we are in the stack frame until briefing done + // Too complicated otherwise + while (window_exists(wind)) + event_process(); } void do_end_game(void) @@ -1289,15 +1332,3 @@ void do_end_game(void) } -void show_order_form() -{ - char exit_screen[16]; - - strcpy(exit_screen, "warning.pcx"); // D1 Registered - if (! cfexist(exit_screen)) - strcpy(exit_screen, "apple.pcx"); // D1 Mac OEM Demo - if (! cfexist(exit_screen)) - strcpy(exit_screen, "order01.pcx"); // D1 Demo - show_title_screen(exit_screen, 1, 1); -} -