/** * Add a message to the queue to be sent later */ void message_training_queue(char *text, int timestamp, int length) { int m; char temp_buf[TRAINING_MESSAGE_LENGTH]; Assert(Training_message_queue_count < TRAINING_MESSAGE_QUEUE_MAX); if (Training_message_queue_count < TRAINING_MESSAGE_QUEUE_MAX) { if (!stricmp(text, NOX("none"))) { m = -1; } else { for (m=0; m<Num_messages; m++) if (!stricmp(text, Messages[m].name)) break; Assert(m < Num_messages); if (m >= Num_messages) return; } Training_message_queue[Training_message_queue_count].num = m; Training_message_queue[Training_message_queue_count].timestamp = timestamp; Training_message_queue[Training_message_queue_count].length = length; // Goober5000 - this shouldn't happen, but let's be safe if (Training_message_queue[Training_message_queue_count].special_message != NULL) { Int3(); vm_free(Training_message_queue[Training_message_queue_count].special_message); Training_message_queue[Training_message_queue_count].special_message = NULL; } // Goober5000 - replace variables if necessary strcpy_s(temp_buf, Messages[m].message); if (sexp_replace_variable_names_with_values(temp_buf, MESSAGE_LENGTH)) Training_message_queue[Training_message_queue_count].special_message = vm_strdup(temp_buf); Training_message_queue_count++; } }
subtitle::subtitle(int in_x_pos, int in_y_pos, const char* in_text, const char* in_imageanim, float in_display_time, float in_fade_time, const color *in_text_color, int in_text_fontnum, bool center_x, bool center_y, int in_width, int in_height, bool in_post_shaded) :display_time(-1.0f), fade_time(-1.0f), text_fontnum(-1), time_displayed(-1.0f), time_displayed_end(-1.0f), post_shaded(false) { // Initialize color gr_init_color(&text_color, 0, 0, 0); SCP_string text_buf; // basic init, this always has to be done memset( imageanim, 0, sizeof(imageanim) ); memset( &text_pos, 0, 2*sizeof(int) ); memset( &image_pos, 0, 4*sizeof(int) ); image_id = -1; if ( ((in_text != NULL) && (strlen(in_text) <= 0)) && ((in_imageanim != NULL) && (strlen(in_imageanim) <= 0)) ) return; if (in_text != NULL && in_text[0] != '\0') { text_buf = in_text; sexp_replace_variable_names_with_values(text_buf); in_text = text_buf.c_str(); } int num_text_lines = 0; const char *text_line_ptrs[MAX_SUBTITLE_LINES]; int text_line_lens[MAX_SUBTITLE_LINES]; //Setup text if ( (in_text != NULL) && (in_text[0] != '\0') ) { int split_width = (in_width > 0) ? in_width : 200; num_text_lines = split_str(in_text, split_width, text_line_lens, text_line_ptrs, MAX_SUBTITLE_LINES); for(int i = 0; i < num_text_lines; i++) { text_buf.assign(text_line_ptrs[i], text_line_lens[i]); text_lines.push_back(text_buf); } } //Setup text color if(in_text_color != NULL) text_color = *in_text_color; else gr_init_alphacolor(&text_color, 255, 255, 255, 255); text_fontnum = in_text_fontnum; //Setup display and fade time display_time = fl_abs(in_display_time); fade_time = fl_abs(in_fade_time); //Setup image if ( (in_imageanim != NULL) && (in_imageanim[0] != '\0') ) { image_id = bm_load(in_imageanim); if (image_id >= 0) strncpy(imageanim, in_imageanim, sizeof(imageanim) - 1); } //Setup pos int w=0, h=0, tw=0, th=0; if(center_x || center_y) { // switch font because we need to measure it int old_fontnum; if (text_fontnum >= 0) { old_fontnum = gr_get_current_fontnum(); gr_set_font(text_fontnum); } else { old_fontnum = -1; } //Get text size for(int i = 0; i < num_text_lines; i++) { gr_get_string_size(&w, &h, text_line_ptrs[i], text_line_lens[i]); if(w > tw) tw = w; th += h; } // restore old font if (old_fontnum >= 0) { gr_set_font(old_fontnum); } //Get image size if(image_id != -1) { bm_get_info(image_id, &w, &h); if (in_width > 0) w = in_width; if (in_height > 0) h = in_height; tw += w; if(h > th) th = h; } //Center it? if(center_x) image_pos.x = (gr_screen.max_w - tw)/2; if(center_y) image_pos.y = (gr_screen.max_h - th)/2; } if(in_x_pos < 0 && !center_x) image_pos.x += gr_screen.max_w + in_x_pos; else if(!center_x) image_pos.x += in_x_pos; if(in_y_pos < 0 && !center_y) image_pos.y += gr_screen.max_h + in_y_pos; else if(!center_y) image_pos.y += in_y_pos; image_pos.w = in_width; image_pos.h = in_height; if(image_id != -1) text_pos.x = image_pos.x + w; //Still set from bm_get_info call else text_pos.x = image_pos.x; text_pos.y = image_pos.y; time_displayed = 0.0f; time_displayed_end = 2.0f*fade_time + display_time; post_shaded = in_post_shaded; }
void cmd_brief_init(int team) { common_music_init(SCORE_BRIEFING); int i; ui_button_info *b; Cmd_brief_inited = 0; Cur_cmd_brief = &Cmd_briefs[team]; // Goober5000 - replace any variables (probably persistent variables) with their values for (i = 0; i < Cur_cmd_brief->num_stages; i++) sexp_replace_variable_names_with_values(Cur_cmd_brief->stage[i].text); if (Cur_cmd_brief->num_stages <= 0) return; gr_reset_clip(); gr_clear(); Mouse_hidden++; gr_flip(); Mouse_hidden--; // first determine which layout to use Uses_scroll_buttons = 1; // assume true Cmd_brief_background_bitmap = bm_load(Cmd_brief_fname[Uses_scroll_buttons][gr_screen.res]); // try to load extra one first if (Cmd_brief_background_bitmap < 0) // failed to load { Uses_scroll_buttons = 0; // nope, sorry Cmd_brief_background_bitmap = bm_load(Cmd_brief_fname[Uses_scroll_buttons][gr_screen.res]); } Ui_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0); Ui_window.set_mask_bmap(Cmd_brief_mask[Uses_scroll_buttons][gr_screen.res]); for (i=0; i<NUM_CMD_BRIEF_BUTTONS; i++) { b = &Cmd_brief_buttons[gr_screen.res][i]; b->button.create(&Ui_window, "", b->x, b->y, 60, 30, 0, 1); // set up callback for when a mouse first goes over a button b->button.set_highlight_action(common_play_highlight_sound); b->button.set_bmaps(b->filename); b->button.link_hotspot(b->hotspot); } // add text for(i=0; i<CMD_BRIEF_NUM_TEXT; i++){ Ui_window.add_XSTR(&Cmd_brief_text[gr_screen.res][i]); } // set up readyrooms for buttons so we draw the correct animation frame when a key is pressed Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_FIRST_STAGE].button.set_hotkey(KEY_SHIFTED | KEY_LEFT); Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_LAST_STAGE].button.set_hotkey(KEY_SHIFTED | KEY_RIGHT); Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_PREV_STAGE].button.set_hotkey(KEY_LEFT); Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_NEXT_STAGE].button.set_hotkey(KEY_RIGHT); Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_ACCEPT].button.set_hotkey(KEY_CTRLED | KEY_ENTER); Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_HELP].button.set_hotkey(KEY_F1); Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_OPTIONS].button.set_hotkey(KEY_F2); // extra - Goober5000 if (Uses_scroll_buttons) { Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_SCROLL_UP].button.set_hotkey(KEY_UP); Cmd_brief_buttons[gr_screen.res][CMD_BRIEF_BUTTON_SCROLL_DOWN].button.set_hotkey(KEY_DOWN); } // load in help overlay bitmap help_overlay_load(CMD_BRIEF_OVERLAY); help_overlay_set_state(CMD_BRIEF_OVERLAY,0); for (i=0; i<Cur_cmd_brief->num_stages; i++) cmd_brief_ani_wave_init(i); cmd_brief_init_voice(); cmd_brief_new_stage(0); Cmd_brief_paused = 0; Cmd_brief_inited = 1; }