// force the chatbox to go into big mode (if its in small mode) - will not work if in multi paused chatbox mode void chatbox_force_big() { int new_mode_flags; // don't do anything unless we're currently in "small" mode if(!(Chatbox_mode_flags & CHATBOX_FLAG_SMALL)){ return; } new_mode_flags = Chatbox_mode_flags; // switch to the appropriate mode new_mode_flags &= ~(CHATBOX_FLAG_SMALL | CHATBOX_FLAG_BIG); new_mode_flags |= CHATBOX_FLAG_BIG; Chatbox_bitmap = Chatbox_big_bitmap; // flip the up/down arrow Chatbox_buttons[gr_screen.res][CHATBOX_TOGGLE_SIZE].button.set_bmaps(Chatbox_buttons[gr_screen.res][CHATBOX_TOGGLE_SIZE+1].filename); // call this to set everything up correctly chatbox_set_mode(new_mode_flags); // change the location of the input box Chat_inputbox.update_dimensions(Chatbox_inputbox_x, Chatbox_textenter_y, Chatbox_inputbox_w,15); Chat_inputbox.set_focus(); // adjust what line we start displaying from based upon the new size of the window chatbox_toggle_size_adjust_lines(); }
// user has pressed the "up" key void chatbox_recall_up() { // if we've got no recall lines, do nothing if(Chatbox_recall_count <= 0){ return; } // if we can increment up if(Chatbox_recall_index < (Chatbox_recall_count - 1)){ // if this is the last line we recalled, pre-increment if(Chatbox_recall_last == Chatbox_recall_index){ Chat_inputbox.set_text(Chatbox_recall_lines[++Chatbox_recall_index]); Chatbox_recall_last = Chatbox_recall_index; } // otherwise, post increment else { Chat_inputbox.set_text(Chatbox_recall_lines[Chatbox_recall_index++]); Chatbox_recall_last = Chatbox_recall_index - 1; } } // if we can't increment up else { Chat_inputbox.set_text(Chatbox_recall_lines[Chatbox_recall_index]); Chatbox_recall_last = Chatbox_recall_index; } }
void pilot_manage_init(void) { UI_WINDOW *w = &Ui_window; // create interface Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0); Ui_window.set_mask_bmap(PilotManage_bitmap_mask_fname[gr_screen.res]); // load background bitmap Background_bitmap = bm_load(PilotManage_bitmap_fname[gr_screen.res]); if(Background_bitmap < 0){ // we failed to load the bitmap - this is very bad Int3(); } for (int i=0; i<PM_NUM_BUTTONS; i++) { // create the object Buttons[gr_screen.res][i].button.create(&Ui_window, "", Buttons[gr_screen.res][i].x, Buttons[gr_screen.res][i].y, 60, 30, Buttons[gr_screen.res][i].repeat, 1); // set the sound to play when highlighted Buttons[gr_screen.res][i].button.set_highlight_action(common_play_highlight_sound); // set the ani for the button Buttons[gr_screen.res][i].button.set_bmaps(Buttons[gr_screen.res][i].filename); // set the hotspot Buttons[gr_screen.res][i].button.link_hotspot(Buttons[gr_screen.res][i].hotspot); } // load in help overlay bitmap // needs to be fixed, taked out to get to compile // help_overlay_load(PILOT_MANAGE_OVERLAY); // help_overlay_set_state(PILOT_MANAGE_OVERLAY,0); // button for selecting pilot List_region.create(&Ui_window, "", Pilot_manage_list_coords[gr_screen.res][PM_X_COORD], Pilot_manage_list_coords[gr_screen.res][PM_Y_COORD], Pilot_manage_list_coords[gr_screen.res][PM_W_COORD], Pilot_manage_list_coords[gr_screen.res][PM_H_COORD], 0, 1); List_region.hide(); // create input box (for new pilot) Inputbox.create(&Ui_window, Pilot_manage_list_coords[gr_screen.res][PM_X_COORD], Pilot_manage_list_coords[gr_screen.res][PM_Y_COORD], Pilot_manage_list_coords[gr_screen.res][PM_W_COORD], CALLSIGN_LEN - 1, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_LETTER_FIRST); Inputbox.set_valid_chars(VALID_PILOT_CHARS); Inputbox.disable(); Inputbox.hide(); Rank_pips_bitmaps = bm_load_animation("IconRankMini.ani", &Rank_pips_count); pilot_manage_callsign_enter_mode = 0; List_scroll_offset = Pic_number = Pic_squad_number;// = Selected_line = 0; prev_single_player = -1; prev_multi_player = -1; pilot_manage_init_player_stuff(is_pilot_multi(Player)); // enable hotkeys from start pilot_manage_set_callsign_enter_mode(false); }
// user has pressed the "down" key void chatbox_recall_down() { // if we've got no recall lines, do nothing if(Chatbox_recall_count <= 0){ return; } // if we can decrement down if(Chatbox_recall_index > 0){ // if this is the last line we recalled, pre-decrement if(Chatbox_recall_last == Chatbox_recall_index){ Chat_inputbox.set_text(Chatbox_recall_lines[--Chatbox_recall_index]); Chatbox_recall_last = Chatbox_recall_index; } // otherwise post,decrement else { Chat_inputbox.set_text(Chatbox_recall_lines[Chatbox_recall_index--]); Chatbox_recall_last = Chatbox_recall_index + 1; } } // if we can't decrement down else { Chat_inputbox.set_text(""); Chatbox_recall_last = -1; } }
void pilot_manage_set_callsign_enter_mode(bool set_callsign_enter_mode) { // set global mode variable pilot_manage_callsign_enter_mode = set_callsign_enter_mode; // disable/enable all buttons for (int idx=0; idx<PM_NUM_BUTTONS; idx++) { Buttons[gr_screen.res][idx].button.enable(!set_callsign_enter_mode); } // enable/disable hotkeys pilot_manage_set_hotkeys(!set_callsign_enter_mode); // disable/enable inputbox Inputbox.enable(set_callsign_enter_mode); // hide/unhide inputbox Inputbox.hide(!set_callsign_enter_mode); }
// process this frame for the chatbox int chatbox_process(int key_in) { int key_out; key_out = key_in; // if the chatbox hasn't explicitly been created, we can't do any processing if(!Chatbox_created){ return key_out; } // process the incoming key appropriately if (key_in == -1) { key_out = Chat_window.process(); } else { key_out = Chat_window.process(key_in); } // look for special keypresses switch(key_out){ // line recall up one case KEY_UP: chatbox_recall_up(); key_out = 0; break; // line recall down one case KEY_DOWN: chatbox_recall_down(); key_out = 0; break; } // if we're supposed to be checking our own scroll buttons if((Chatbox_mode_flags & CHATBOX_FLAG_BUTTONS) && (Chatbox_mode_flags & CHATBOX_FLAG_DRAW_BOX)){ if ( Chatbox_buttons[gr_screen.res][CHATBOX_SCROLL_UP].button.pressed() ) { chatbox_scroll_up(); } if ( Chatbox_buttons[gr_screen.res][CHATBOX_SCROLL_DOWN].button.pressed() ) { chatbox_scroll_down(); } if ( Chatbox_buttons[gr_screen.res][CHATBOX_TOGGLE_SIZE].button.pressed() ){ chatbox_toggle_size(); } } // check to see if the enter text button has been pressed if ( Chat_enter_text.pressed() ) { Chat_inputbox.set_focus(); } // check to see if the current input text needs to be split up and sent automaticall chatbox_autosplit_line(); return key_out; }
// "lose" the focus on the chatbox inputbox void chatbox_lose_focus() { if(!Chatbox_created){ return; } // clear the focus on the inputbox Chat_inputbox.clear_focus(); }
// automatically split up any input text, send it, and leave the remainder void chatbox_autosplit_line() { char *remainder,msg[150]; int msg_pixel_width; // if the chat line is getting too long, fire off the message, putting the last // word on the next input line. memset(msg,0,150); Chat_inputbox.get_text(msg); remainder = ""; // determine if the width of the string in pixels is > than the inputbox width -- if so, // then send the message gr_get_string_size(&msg_pixel_width, NULL, msg); // if ( msg_pixel_width >= (Chatbox_inputbox_w - Player->short_callsign_width) ) { if ( msg_pixel_width >= (Chatbox_inputbox_w - 25)) { remainder = strrchr(msg, ' '); if ( remainder ) { *remainder = '\0'; remainder++; } else { remainder = ""; } // if I'm the server, then broadcast the packet chatbox_recall_add(msg); send_game_chat_packet(Net_player, msg, MULTI_MSG_ALL,NULL); chatbox_add_line(msg, MY_NET_PLAYER_NUM); // display any remainder of text on the next line Chat_inputbox.set_text(remainder); } else if((Chat_inputbox.pressed() && (strlen(msg) > 0)) || (strlen(msg) >= CHATBOX_MAX_LEN)) { // tack on the null terminator in the boundary case int x = strlen(msg); if(x >= CHATBOX_MAX_LEN){ msg[CHATBOX_MAX_LEN-1] = '\0'; } // if I'm the server, then broadcast the packet chatbox_recall_add(msg); send_game_chat_packet(Net_player, msg, MULTI_MSG_ALL,NULL); chatbox_add_line(msg, MY_NET_PLAYER_NUM); // display any remainder of text on the next line Chat_inputbox.set_text(remainder); } }
int player_select_create_new_pilot() { int idx; // make sure we haven't reached the max if (Player_select_num_pilots >= MAX_PILOTS) { gamesnd_play_iface(SND_GENERAL_FAIL); return 0; } int play_scroll_sound = 1; if ( play_scroll_sound ) { gamesnd_play_iface(SND_SCROLL); } idx = Player_select_num_pilots; // move all the pilots in the list up while (idx--) { strcpy(Pilots[idx + 1], Pilots[idx]); } // by default, set the default netgame protocol to be VMT Multi_options_g.protocol = NET_TCP; // select the beginning of the list Player_select_pilot = 0; Player_select_num_pilots++; Pilots[Player_select_pilot][0] = 0; Player_select_list_start= 0; // set us to be in input mode player_select_set_input_mode(1); // set the input box to have focus Player_select_input_box.set_focus(); Player_select_input_box.set_text(""); Player_select_input_box.update_dimensions(Choose_list_coords[gr_screen.res][0], Choose_list_coords[gr_screen.res][1], Choose_list_coords[gr_screen.res][2], gr_get_font_height()); return 1; }
void barracks_set_callsign_enter_mode(bool set_callsign_enter_mode) { // set global mode variable Barracks_callsign_enter_mode = set_callsign_enter_mode; // disable/enable all buttons for (int idx=0; idx<BARRACKS_NUM_BUTTONS; idx++) { // don't ever mess with the prev and next squad logo buttons if((idx != B_SQUAD_PREV_BUTTON) && (idx != B_SQUAD_NEXT_BUTTON)){ Buttons[gr_screen.res][idx].button.enable(!set_callsign_enter_mode); } } // enable/disable hotkeys barracks_set_hotkeys(!set_callsign_enter_mode); // disable/enable inputbox Inputbox.enable(set_callsign_enter_mode); // hide/unhide inputbox Inputbox.hide(!set_callsign_enter_mode); }
// creates a new pilot file void pilot_manage_create_new_pilot()//UI_INPUTBOX *Inputbox) { // check if too many pilots if (Num_pilots >= MAX_PILOTS) { gamesnd_play_iface(SND_GENERAL_FAIL); return; } // play sound for pilot creation gamesnd_play_iface(SND_SCROLL); // only write pilot file if there is an active pilot if (strlen(Player->callsign)) { write_pilot_file(); } // move other pilot names and ranks down to make room for the new one int idx = Num_pilots; Assert(Num_pilots >= 0); while (idx--) { strcpy(Pilots[idx + 1], Pilots[idx]); Pilot_ranks[idx + 1] = Pilot_ranks[idx]; } Selected_line = 0; Num_pilots++; Pilots[Selected_line][0] = 0; Pilot_ranks[Selected_line] = 0; List_scroll_offset = 0; // set mode to accept pilot name text pilot_manage_set_callsign_enter_mode(true); // set focus to input box Inputbox.set_focus(); // set initial pilot name to "" Inputbox.set_text(""); // reset size of input box to only 1 line Inputbox.update_dimensions(Pilot_manage_list_coords[gr_screen.res][PM_X_COORD], Pilot_manage_list_coords[gr_screen.res][PM_Y_COORD], Pilot_manage_list_coords[gr_screen.res][PM_W_COORD], gr_get_font_height()); }
void player_select_set_input_mode(int n) { int i; // set the input mode Player_select_input_mode = n; // enable all the player select buttons for (i=0; i<NUM_PLAYER_SELECT_BUTTONS; i++) { Player_select_buttons[gr_screen.res][i].button.enable(!n); } Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].button.set_hotkey(n ? -1 : KEY_ENTER); Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].button.set_hotkey(n ? -1 : KEY_C); // enable the player select input box if (Player_select_input_mode) { Player_select_input_box.enable(); Player_select_input_box.unhide(); } else { Player_select_input_box.hide(); Player_select_input_box.disable(); } }
// automatically split up any input text, send it, and leave the remainder void chatbox_autosplit_line() { char *remainder,msg[150]; char temp[150]; int msg_pixel_width; int target, target_length = -1; // if the chat line is getting too long, fire off the message, putting the last // word on the next input line. memset(msg,0,150); Chat_inputbox.get_text(msg); remainder = ""; // check if this message is supposed to have a recipient target = chatbox_get_msg_target_type(msg); target_length = chatbox_get_msg_target_length(msg); // determine if the width of the string in pixels is > than the inputbox width -- if so, // then send the message gr_get_string_size(&msg_pixel_width, NULL, msg); // if ( msg_pixel_width >= (Chatbox_inputbox_w - Player->short_callsign_width) ) { if ( msg_pixel_width >= (Chatbox_inputbox_w - 25)) { remainder = strrchr(msg, ' '); if ( remainder ) { *remainder = '\0'; remainder++; } else { remainder = ""; } // if I'm the server, then broadcast the packet chatbox_recall_add(msg); if (target != MULTI_MSG_EXPR) { send_game_chat_packet(Net_player, msg, target); } else { // copy the name of the player the message is being sent to strncpy(temp, msg+1, target_length-2); temp[target_length-2] = '\0'; send_game_chat_packet(Net_player, msg, target, NULL, temp); } chatbox_add_line(msg, MY_NET_PLAYER_NUM); if (target != MULTI_MSG_ALL) { // we need to add the target the message is going to before we add the rest of the string strncpy(temp, msg, target_length); temp[target_length] = ' '; temp[target_length+1] = '\0'; strcat_s(temp, remainder); Chat_inputbox.set_text(temp); } else { // display any remainder of text on the next line Chat_inputbox.set_text(remainder); } } else if((Chat_inputbox.pressed() && (msg[0] != '\0')) || (strlen(msg) >= CHATBOX_MAX_LEN)) { // tack on the null terminator in the boundary case int x = strlen(msg); if(x >= CHATBOX_MAX_LEN){ msg[CHATBOX_MAX_LEN-1] = '\0'; } // if I'm the server, then broadcast the packet chatbox_recall_add(msg); if (target != MULTI_MSG_EXPR) { send_game_chat_packet(Net_player, msg, target); } else { // copy the name of the player the message is being sent to strncpy(temp, msg+1, target_length-2); temp[target_length-2] = '\0'; send_game_chat_packet(Net_player, msg, target, NULL, temp); } chatbox_add_line(msg, MY_NET_PLAYER_NUM); // display any remainder of text on the next line Chat_inputbox.set_text(remainder); } }
void pilot_manage_do(void) { int k = Ui_window.process(); int i; if ( k > 0 ) { // put back in when overlay stuff is fixed // if ( help_overlay_active(PILOT_MANAGE_OVERLAY) ) { // help_overlay_set_state(PILOT_MANAGE_OVERLAY,0); // k = 0; // } } switch (k) { case KEY_ESC: // cancel only if not trying to enter a pilot name if (!pilot_manage_callsign_enter_mode) gameseq_post_event(GS_EVENT_BARRACKS_MENU);//GS_EVENT_PREVIOUS_STATE break; } // end switch int prospective_pilot = -1; // Entering pilot callsign if (pilot_manage_callsign_enter_mode) { // set focus to inputbox Inputbox.set_focus(); switch (k) { case KEY_ESC: // cancel create pilot Num_pilots--; for (i=0; i<Num_pilots; i++) { strcpy(Pilots[i], Pilots[i + 1]); Pilot_ranks[i] = Pilot_ranks[i + 1]; } pilot_manage_set_callsign_enter_mode(false); break; case KEY_ENTER: pilot_manage_accept_new_pilot_callsign(); break; } } // process buttons for (i=0; i<PM_NUM_BUTTONS; i++) { if (Buttons[gr_screen.res][i].button.pressed()) { pilot_manage_button_pressed(i); } } // pilot that mouse is over // if mouse is over a pilot, find index into Pilots array if (List_region.is_mouse_on()) { int y; List_region.get_mouse_pos(NULL, &y); int pilot_index = List_scroll_offset + (y / gr_get_font_height()); if ((pilot_index >= 0) && (pilot_index < Num_pilots)) { prospective_pilot = pilot_index; } } // if mouse clicked in list region, find index into Pilots array if (List_region.pressed()) { if (prospective_pilot != -1) { Selected_line = prospective_pilot; gamesnd_play_iface(SND_USER_SELECT); } } gr_reset_clip(); GR_MAYBE_CLEAR_RES(Background_bitmap); if (Background_bitmap >= 0) { gr_set_bitmap(Background_bitmap); gr_bitmap(0, 0); } Ui_window.draw(); //light up the correct mode button (single or multi) if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) { Buttons[gr_screen.res][PM_SINGLE_MODE_BUTTON].button.draw_forced(2); } else { Buttons[gr_screen.res][PM_MULTI_MODE_BUTTON].button.draw_forced(2); } pilot_manage_display_pilot_callsigns(prospective_pilot); pilot_manage_force_button_frame(); pilot_manage_maybe_show_button_text(); // needs to be fixed help_overlay_maybe_blit(PILOT_MANAGE_OVERLAY); gr_flip(); }
// return if the inputbox was pressed - "clicked on" int chatbox_pressed() { return Chat_inputbox.pressed(); }
// grab the focus for the chatbox inputbox void chatbox_set_focus() { Chat_inputbox.set_focus(); }
// return if the inputbox for the chatbox currently has focus int chatbox_has_focus() { return Chat_inputbox.has_focus(); }
// init the Popup window int popup_init(popup_info *pi, int flags) { int i; UI_BUTTON *b; popup_background *pbg; char *fname; if(pi->nchoices == 0){ pbg = &Popup_background[gr_screen.res][0]; } else { pbg = &Popup_background[gr_screen.res][pi->nchoices-1]; } // anytime in single player, and multiplayer, not in mission, go ahead and stop time if ( (Game_mode & GM_NORMAL) || ((Game_mode & GM_MULTIPLAYER) && !(Game_mode & GM_IN_MISSION)) ){ game_stop_time(); } // create base window Popup_window.create(pbg->coords[0], pbg->coords[1], Popup_text_coords[gr_screen.res][2]+100, Popup_text_coords[gr_screen.res][3]+50, 0); Popup_window.set_foreground_bmap(pbg->filename); // create buttons for (i=0; i<pi->nchoices; i++) { b = &Popup_buttons[i]; // accommodate single-choice positive icon being positioned differently if ( (pi->nchoices == 1) && (flags&PF_USE_AFFIRMATIVE_ICON) ) { b->create(&Popup_window, "", Button_coords[gr_screen.res][i+1][0], Button_coords[gr_screen.res][i+1][1], 30, 25, 0, 1); } else { b->create(&Popup_window, "", Button_coords[gr_screen.res][i][0], Button_coords[gr_screen.res][i][1], 30, 25, 0, 1); } fname = popup_get_button_filename(pi, i, flags); b->set_bmaps(fname, 3, 0); b->set_highlight_action(common_play_highlight_sound); if ( pi->keypress[i] >= 0 ) { b->set_hotkey(pi->keypress[i]); } // create invisible buttons to detect mouse presses... can't use mask since button region is dynamically sized int lx, w, h; gr_get_string_size(&w, &h, pi->button_text[i]); lx = Button_regions[gr_screen.res][i][0] - w; b = &Popup_button_regions[i]; // accommodate single-choice positive icon being positioned differently if ( (pi->nchoices == 1) && (flags&PF_USE_AFFIRMATIVE_ICON) ) { b->create(&Popup_window, "", lx, Button_regions[gr_screen.res][i+1][1], Button_regions[gr_screen.res][i+1][2]-lx, Button_regions[gr_screen.res][i+1][3]-Button_regions[gr_screen.res][i+1][1], 0, 1); } else { b->create(&Popup_window, "", lx, Button_regions[gr_screen.res][i][1], Button_regions[gr_screen.res][i][2]-lx, Button_regions[gr_screen.res][i][3]-Button_regions[gr_screen.res][i][1], 0, 1); } b->hide(); } // webcursor setup if (Web_cursor_bitmap >= 0) { if (flags & PF_WEB_CURSOR_1) { Popup_buttons[1].set_custom_cursor_bmap(Web_cursor_bitmap); } if (flags & PF_WEB_CURSOR_2) { Popup_buttons[2].set_custom_cursor_bmap(Web_cursor_bitmap); } } // if this is an input popup, create and center the popup if(flags & PF_INPUT){ Popup_input.create(&Popup_window, Popup_text_coords[gr_screen.res][0], pbg->coords[1] + Popup_input_y_offset[gr_screen.res], Popup_text_coords[gr_screen.res][2], pi->max_input_text_len, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_CLR | UI_INPUTBOX_FLAG_ESC_FOC | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_TEXT_CEN); Popup_input.set_focus(); } Popup_default_choice=0; Popup_should_die = 0; if (flags & PF_RUN_STATE) { Popup_running_state = 1; } else { Popup_running_state = 0; } popup_split_lines(pi, flags); // create the popup slider (which we may not need to use Popup_slider.create(&Popup_window, Popup_slider_coords[gr_screen.res][0], Popup_slider_coords[gr_screen.res][1], Popup_slider_coords[gr_screen.res][2], Popup_slider_coords[gr_screen.res][3], pi->nlines > Popup_max_display[gr_screen.res] ? pi->nlines - Popup_max_display[gr_screen.res] : 0, Popup_slider_name[gr_screen.res], popup_slider_bogus, popup_slider_bogus, NULL); return 0; }
// exit: -1 => error // 0..nchoices-1 => choice int popup_do(popup_info *pi, int flags) { int screen_id, choice = -1, done = 0; if ( popup_init(pi, flags) == -1 ){ return -1; } screen_id = gr_save_screen(); int old_max_w_unscaled = gr_screen.max_w_unscaled; int old_max_h_unscaled = gr_screen.max_h_unscaled; int old_max_w_unscaled_zoomed = gr_screen.max_w_unscaled_zoomed; int old_max_h_unscaled_zoomed = gr_screen.max_h_unscaled_zoomed; gr_reset_screen_scale(); while(!done) { int k; os_poll(); // if we were killed by a call to popup_kill_any_active(), kill the popup if(Popup_should_die){ choice = -1; break; } // if we're flagged as should be running the state underneath, then do so if(flags & PF_RUN_STATE){ game_do_state(gameseq_get_state()); } // otherwise just run the common functions (for networking,etc) else { game_set_frametime(-1); game_do_state_common(gameseq_get_state(),flags & PF_NO_NETWORKING); // do stuff common to all states } k = Popup_window.process(); // poll for input, handle mouse choice = popup_process_keys(pi, k, flags); if ( choice != POPUP_NOCHANGE ) { done=1; } if ( !done ) { choice = popup_check_buttons(pi); if ( choice != POPUP_NOCHANGE ) { done=1; } } // don't draw anything if(!(flags & PF_RUN_STATE)){ gr_restore_screen(screen_id); } // if this is an input popup, store the input text if(flags & PF_INPUT){ Popup_input.get_text(pi->input_text); } Popup_window.draw(); popup_force_draw_buttons(pi); popup_draw_msg_text(pi, flags); popup_draw_button_text(pi, flags); gr_flip(); } gr_set_screen_scale(old_max_w_unscaled, old_max_h_unscaled, old_max_w_unscaled_zoomed, old_max_h_unscaled_zoomed); popup_close(pi,screen_id); return choice; }
// ----------------------------------------------------------------------------- void barracks_do_frame(float frametime) { int k = Ui_window.process(); if ( k > 0 ) { if ( help_overlay_active(Barracks_overlay_id) ) { help_overlay_set_state(Barracks_overlay_id,gr_screen.res,0); k = 0; } } // pilot that mouse is over int prospective_pilot = -1; int i; // Entering pilot callsign if (Barracks_callsign_enter_mode) { // set focus to inputbox Inputbox.set_focus(); switch (k) { case KEY_ESC: // cancel create pilot Num_pilots--; for (i=0; i<Num_pilots; i++) { strcpy(Pilots[i], Pilots[i + 1]); Pilot_ranks[i] = Pilot_ranks[i + 1]; } barracks_set_callsign_enter_mode(false); break; case KEY_ENTER: barracks_accept_new_pilot_callsign(); break; } } else { // not entering pilot callsign switch (k) { case KEY_ENTER: if (barracks_new_pilot_selected()) { gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); } break; case KEY_ESC: // cancel if (!help_overlay_active(Barracks_overlay_id)) { if (Num_pilots && !barracks_pilot_accepted()) { gameseq_post_event(GS_EVENT_MAIN_MENU); } else { gamesnd_play_iface(SND_GENERAL_FAIL); } } else { // kill the overlay help_overlay_set_state(Barracks_overlay_id,gr_screen.res,0); } break; case KEY_TAB: // switch mode (simgle/multi) if ( Networking_disabled ) { game_feature_disabled_popup(); break; } if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) { Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI; Pilot.save_player(Cur_pilot); barracks_init_player_stuff(PLAYER_SELECT_MODE_MULTI); } else { // make sure we don't carry over the multi flag Cur_pilot->flags &= ~PLAYER_FLAGS_IS_MULTI; Pilot.save_player(Cur_pilot); barracks_init_player_stuff(PLAYER_SELECT_MODE_SINGLE); } gamesnd_play_iface(SND_USER_SELECT); break; case KEY_F1: // show help overlay gamesnd_play_iface(SND_HELP_PRESSED); break; case KEY_F2: // goto options screen gamesnd_play_iface(SND_SWITCH_SCREENS); gameseq_post_event(GS_EVENT_OPTIONS_MENU); break; } // end switch // process buttons for (i=0; i<BARRACKS_NUM_BUTTONS; i++) { if (Buttons[gr_screen.res][i].button.pressed()) { barracks_button_pressed(i); } } // if mouse is over a pilot, find index into Pilots array if (List_region.is_mouse_on()) { int y; List_region.get_mouse_pos(NULL, &y); int pilot_index = List_scroll_offset + (y / gr_get_font_height()); if ((pilot_index >= 0) && (pilot_index < Num_pilots)) { prospective_pilot = pilot_index; } } // if mouse clicked in list region, find index into Pilots array if (List_region.pressed()) { if (prospective_pilot != -1) { Selected_line = prospective_pilot; gamesnd_play_iface(SND_USER_SELECT); } } } // check mouse over help if (mouse_down(MOUSE_LEFT_BUTTON)) { help_overlay_set_state(Barracks_overlay_id, gr_screen.res, 0); } // do pilot pic stuff if ((Pic_number >= 0) && (Pic_number < Num_pilot_images)) { if (Pilot_images[Pic_number] == BARRACKS_IMAGE_NOT_LOADED) { // haven't tried loading it yet Pilot_images[Pic_number] = bm_load(Pilot_image_names[Pic_number]); if (Pilot_images[Pic_number] >= 0) { int w, h; bm_get_info(Pilot_images[Pic_number], &w, &h, NULL); // check for invalid pilot pic file if ((w != PLAYER_PILOT_PIC_W) || (h != PLAYER_PILOT_PIC_H)) { bm_release(Pilot_images[Pic_number]); Pilot_images[Pic_number] = -1; } } } } else { Pic_number = -1; } // do squad pic stuff if ((Pic_squad_number >= 0) && (Pic_squad_number < Num_pilot_squad_images)) { if (Pilot_squad_images[Pic_squad_number] == BARRACKS_IMAGE_NOT_LOADED) { // haven't tried loading it yet Pilot_squad_images[Pic_squad_number] = bm_load_duplicate(Pilot_squad_image_names[Pic_squad_number]); if (Pilot_squad_images[Pic_squad_number] >= 0) { int w, h; bm_get_info(Pilot_squad_images[Pic_squad_number], &w, &h, NULL); // check for invalid pilot pic file if ((w != PLAYER_SQUAD_PIC_W) || (h != PLAYER_SQUAD_PIC_H)) { bm_release(Pilot_squad_images[Pic_squad_number]); Pilot_squad_images[Pic_squad_number] = -1; } } } } else { Pic_squad_number = -1; } // draw the background, etc gr_reset_clip(); GR_MAYBE_CLEAR_RES(Background_bitmap); if (Background_bitmap >= 0) { gr_set_bitmap(Background_bitmap); gr_bitmap(0, 0, GR_RESIZE_MENU); } // draw pilot image and clean up afterwards barracks_draw_pilot_pic(); barracks_draw_squad_pic(); // draw the window Ui_window.draw(); // light up the correct mode button (single or multi) if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) { Buttons[gr_screen.res][B_PILOT_SINGLE_MODE_BUTTON].button.draw_forced(2); } else { Buttons[gr_screen.res][B_PILOT_MULTI_MODE_BUTTON].button.draw_forced(2); } // write out pilot call signs barracks_display_pilot_callsigns(prospective_pilot); // write out current pilot stats barracks_display_pilot_stats(); // blit help overlay if active help_overlay_maybe_blit(Barracks_overlay_id, gr_screen.res); // flip the page gr_flip(); }
// ----------------------------------------------------------------------------- void barracks_init() { //Set these to null, 'cause they aren't allocated yet. Stat_labels = NULL; Stats = NULL; UI_WINDOW *w = &Ui_window; // save current pilot file, so we don't possibly loose it. Pilot.save_player(); // create interface Ui_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0); Ui_window.set_mask_bmap(Barracks_bitmap_mask_fname[gr_screen.res]); // load background bitmap Background_bitmap = bm_load(Barracks_bitmap_fname[gr_screen.res]); if(Background_bitmap < 0){ // we failed to load the bitmap - this is very bad Int3(); } // create buttons int i; for (i=0; i<BARRACKS_NUM_BUTTONS; i++) { // create the object Buttons[gr_screen.res][i].button.create(&Ui_window, "", Buttons[gr_screen.res][i].x, Buttons[gr_screen.res][i].y, 60, 30, Buttons[gr_screen.res][i].repeat, 1); // set the sound to play when highlighted Buttons[gr_screen.res][i].button.set_highlight_action(common_play_highlight_sound); // set the ani for the button Buttons[gr_screen.res][i].button.set_bmaps(Buttons[gr_screen.res][i].filename); // set the hotspot Buttons[gr_screen.res][i].button.link_hotspot(Buttons[gr_screen.res][i].hotspot); } // add all strings w->add_XSTR("Create", 1034, Buttons[gr_screen.res][0].text_x, Buttons[gr_screen.res][0].text_y, &Buttons[gr_screen.res][0].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Accept", 1035, Buttons[gr_screen.res][5].text_x, Buttons[gr_screen.res][5].text_y, &Buttons[gr_screen.res][5].button, UI_XSTR_COLOR_PINK); w->add_XSTR("Help", 928, Buttons[gr_screen.res][6].text_x, Buttons[gr_screen.res][6].text_y, &Buttons[gr_screen.res][6].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Options",1036, Buttons[gr_screen.res][7].text_x, Buttons[gr_screen.res][7].text_y, &Buttons[gr_screen.res][7].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Medals", 1037, Buttons[gr_screen.res][8].text_x, Buttons[gr_screen.res][8].text_y, &Buttons[gr_screen.res][8].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Remove", 1038, Buttons[gr_screen.res][11].text_x, Buttons[gr_screen.res][11].text_y, &Buttons[gr_screen.res][11].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Select", 1552, Buttons[gr_screen.res][12].text_x, Buttons[gr_screen.res][12].text_y, &Buttons[gr_screen.res][12].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Clone", 1040, Buttons[gr_screen.res][13].text_x, Buttons[gr_screen.res][13].text_y, &Buttons[gr_screen.res][13].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Single", 1041, Buttons[gr_screen.res][14].text_x, Buttons[gr_screen.res][14].text_y, &Buttons[gr_screen.res][14].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Multi", 1042, Buttons[gr_screen.res][15].text_x, Buttons[gr_screen.res][15].text_y, &Buttons[gr_screen.res][15].button, UI_XSTR_COLOR_GREEN); // w->add_XSTR("Convert",1043, Buttons[gr_screen.res][16].text_x, Buttons[gr_screen.res][16].text_y, &Buttons[gr_screen.res][16].button, UI_XSTR_COLOR_GREEN); for(i=0; i<BARRACKS_NUM_TEXT; i++) { w->add_XSTR(&Barracks_text[gr_screen.res][i]); } // button for selecting pilot List_region.create(&Ui_window, "", Barracks_list_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_Y_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_W_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_H_COORD], 0, 1); List_region.hide(); // create input box (for new pilot) Inputbox.create(&Ui_window, Barracks_list_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_Y_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_W_COORD], CALLSIGN_LEN - 1, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_LETTER_FIRST); Inputbox.set_valid_chars(VALID_PILOT_CHARS); Inputbox.disable(); Inputbox.hide(); // load in help overlay bitmap Barracks_overlay_id = help_overlay_get_index(BARRACKS_OVERLAY); help_overlay_set_state(Barracks_overlay_id,gr_screen.res,0); // other init stuff Barracks_callsign_enter_mode = 0; List_scroll_offset = Stats_scroll_offset = Pic_number = Pic_squad_number = Selected_line = 0; Cur_pilot = &Players[Player_num]; // disable squad logo selection buttons in single player if(!(Cur_pilot->flags & PLAYER_FLAGS_IS_MULTI)){ // squad logo picture buttons Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.hide(); Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.disable(); Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.hide(); Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.disable(); } else { // squad logo picture buttons Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.enable(); Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.unhide(); Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.enable(); Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.unhide(); } // set up hotkeys for buttons so we draw the correct animation frame when a key is pressed barracks_set_hotkeys(1); // load ramp pips Rank_pips_bitmaps = bm_load_animation("IconRankMini.ani", &Rank_pips_count); // load up the pilot pic list pilot_load_pic_list(); pilot_load_squad_pic_list(); // don't load pilot images yet for (i=0; i<MAX_PILOT_IMAGES; i++) { Pilot_images[i] = BARRACKS_IMAGE_NOT_LOADED; // while -1 is can't load Pilot_squad_images[i] = BARRACKS_IMAGE_NOT_LOADED; } // init stats barracks_init_stats(&Cur_pilot->stats); // base the mode we're in (single or multi) on the status of the currently selected pilot barracks_init_player_stuff((Game_mode & GM_MULTIPLAYER) == GM_MULTIPLAYER); }
void player_select_process_input(int k) { char buf[CALLSIGN_LEN + 1]; int idx,z; // if the player is in the process of typing in a new pilot name... switch (k) { // cancel create pilot case KEY_ESC: player_select_cancel_create(); break; // accept a new pilot name case KEY_ENTER: Player_select_input_box.get_text(buf); drop_white_space(buf); z = 0; if (!isalpha(*buf)) { z = 1; } else { for (idx=1; buf[idx]; idx++) { if (!isalpha(buf[idx]) && !isdigit(buf[idx]) && !strchr(VALID_PILOT_CHARS, buf[idx])) { z = 1; break; } } } for (idx=1; idx<Player_select_num_pilots; idx++) { if (!stricmp(buf, Pilots[idx])) { // verify if it is ok to overwrite the file if (pilot_verify_overwrite() == 1) { // delete the pilot and select the beginning of the list Player_select_pilot = idx; player_select_delete_pilot(); Player_select_pilot = 0; idx = Player_select_num_pilots; z = 0; } else z = 1; break; } } if (!*buf || (idx < Player_select_num_pilots)) { z = 1; } if (z) { gamesnd_play_iface(SND_GENERAL_FAIL); break; } // Create the new pilot, and write out his file strcpy(Pilots[0], buf); // if this is the first guy, we should set the Player struct if (Player == NULL) { Player = &Players[0]; Player->reset(); Player->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE; } strcpy_s(Player->callsign, buf); init_new_pilot(Player, !Player_select_clone_flag); // set him as being a multiplayer pilot if we're in the correct mode if (Player_select_mode == PLAYER_SELECT_MODE_MULTI) { Player->flags |= PLAYER_FLAGS_IS_MULTI; Player->stats.flags |= STATS_FLAG_MULTIPLAYER; } // create his pilot file Pilot.save_player(Player); // unset the player Player->reset(); Player = NULL; // make this guy the selected pilot and put him first on the list Player_select_pilot = 0; // unset the input mode player_select_set_input_mode(0); // clear any pending bottom text player_select_set_bottom_text(""); // clear any pending middle text player_select_set_middle_text(""); // ungray all the controls player_select_set_controls(0); // evaluate whether or not this is the very first pilot player_select_eval_very_first_pilot(); break; case 0: break; // always kill middle text when a char is pressed in input mode default: player_select_set_middle_text(""); break; } }
// initialize all chatbox details with the given mode flags int chatbox_create(int mode_flags) { int idx; // don't do anything if the chatbox is already initialized if (Chatbox_created){ return -1; } // probably shouldn't be using the chatbox in single player mode Assert(Game_mode & GM_MULTIPLAYER); // setup all data to correspond to our mode flags chatbox_set_mode(mode_flags); // initialize all low-level details related to chatting chatbox_chat_init(); // attempt to load in the chatbox background bitmap if(Chatbox_mode_flags & CHATBOX_FLAG_DRAW_BOX){ Chatbox_big_bitmap = bm_load(Chatbox_big_bitmap_fname[gr_screen.res]); Chatbox_small_bitmap = bm_load(Chatbox_small_bitmap_fname[gr_screen.res]); Chatbox_mp_bitmap = bm_load(Chatbox_p_bitmap_fname[gr_screen.res]); if(Chatbox_mode_flags & CHATBOX_FLAG_SMALL){ Chatbox_bitmap = Chatbox_small_bitmap; } else if(Chatbox_mode_flags & CHATBOX_FLAG_BIG){ Chatbox_bitmap = Chatbox_big_bitmap; } else { Chatbox_bitmap = Chatbox_mp_bitmap; } if((Chatbox_bitmap == -1) || (Chatbox_small_bitmap == -1) || (Chatbox_big_bitmap == -1) || (Chatbox_mp_bitmap == -1)){ return -1; } } // attempt to create the ui window for the chatbox and assign the mask Chat_window.create( 0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0 ); Chat_window.set_mask_bmap(Chatbox_mask); // create the chat text enter input area Chat_inputbox.create( &Chat_window, Chatbox_inputbox_x, Chatbox_textenter_y, Chatbox_inputbox_w, CHATBOX_MAX_LEN, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_CLR | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_EAT_USED, Chatbox_w, Color_netplayer[MY_NET_PLAYER_NUM]); Chat_inputbox.set_focus(); Chat_inputbox.set_invalid_chars(CHATBOX_INVALID_CHARS); // if we're supposed to supply and check for out own buttons if((Chatbox_mode_flags & CHATBOX_FLAG_BUTTONS) && (Chatbox_mode_flags & CHATBOX_FLAG_DRAW_BOX)){ for(idx=0; idx<CHATBOX_NUM_BUTTONS; idx++){ // create the button Chatbox_buttons[gr_screen.res][idx].button.create(&Chat_window, "", Chatbox_buttons[gr_screen.res][idx].x, Chatbox_buttons[gr_screen.res][idx].y, 60, 30, (idx == CHATBOX_TOGGLE_SIZE) ? 0 : 1); // set the highlight action Chatbox_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound); // set the bitmap Chatbox_buttons[gr_screen.res][idx].button.set_bmaps(Chatbox_buttons[gr_screen.res][idx].filename); // set the hotspot Chatbox_buttons[gr_screen.res][idx].button.link_hotspot(Chatbox_buttons[gr_screen.res][idx].hotspot); } // now create the toggle size button with the appropriate button if(Chatbox_mode_flags & CHATBOX_FLAG_SMALL){ Chatbox_buttons[gr_screen.res][CHATBOX_TOGGLE_SIZE].button.set_bmaps(Chatbox_buttons[gr_screen.res][CHATBOX_TOGGLE_SIZE].filename); } else { Chatbox_buttons[gr_screen.res][CHATBOX_TOGGLE_SIZE].button.set_bmaps(Chatbox_buttons[gr_screen.res][CHATBOX_TOGGLE_SIZE+1].filename); } } // an invisible button that will set focus to input box when clicked on Chat_enter_text.create( &Chat_window, "", 0, 0, 60, 30, 0); Chat_enter_text.hide(); // button doesn't show up Chat_enter_text.link_hotspot(50); Chatbox_created = 1; return 0; }
void player_select_do() { int k; // Goober5000 - display a popup warning about problems in the mod if ((Global_warning_count > 10 || Global_error_count > 0) && !Startup_warning_dialog_displayed) { char text[512]; sprintf(text, "Warning!\n\nThe currently active mod has generated %d warnings and/or errors during program startup. These could have been caused by anything from incorrectly formated table files to corrupt models. While FreeSpace Open will attempt to compensate for these issues, it cannot guarantee a trouble-free gameplay experience. Source Code Project staff cannot provide assistance or support for these problems, as they are caused by the mod's data files, not FreeSpace Open's source code.", Global_warning_count + Global_error_count); popup(PF_TITLE_BIG | PF_TITLE_RED | PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, text); Startup_warning_dialog_displayed = true; } // set the input box at the "virtual" line 0 to be active so the player can enter a callsign if (Player_select_input_mode) { Player_select_input_box.set_focus(); } // process any ui window stuff k = Player_select_window.process(); if (k) { extern void game_process_cheats(int k); game_process_cheats(k); } switch (k) { // switch between single and multiplayer modes case KEY_TAB: { if (Player_select_input_mode) { gamesnd_play_iface(SND_GENERAL_FAIL); break; } // play a little sound gamesnd_play_iface(SND_USER_SELECT); if (Player_select_mode == PLAYER_SELECT_MODE_MULTI) { player_select_set_bottom_text(XSTR( "Single-Player Mode", 376)); // reinitialize as single player mode player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE); } else if (Player_select_mode == PLAYER_SELECT_MODE_SINGLE) { player_select_set_bottom_text(XSTR( "Multiplayer Mode", 377)); // reinitialize as multiplayer mode player_select_init_player_stuff(PLAYER_SELECT_MODE_MULTI); } break; } case KEY_ESC: { // we can hit ESC to get out of text input mode, and we don't want // to set this var in that case since it will crash on a NULL Player // ptr when going to the mainhall if ( !Player_select_input_mode ) { Player_select_no_save_pilot = 1; } break; } } // draw the player select pseudo-dialog over it GR_MAYBE_CLEAR_RES(Player_select_background_bitmap); gr_set_bitmap(Player_select_background_bitmap); gr_bitmap(0,0,GR_RESIZE_MENU); // press the accept button if (Player_select_autoaccept) { Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].button.press_button(); } // draw any ui window stuf Player_select_window.draw(); // light up the correct mode button (single or multi) if (Player_select_mode == PLAYER_SELECT_MODE_SINGLE) { Player_select_buttons[gr_screen.res][SINGLE_BUTTON].button.draw_forced(2); } else { Player_select_buttons[gr_screen.res][MULTI_BUTTON].button.draw_forced(2); } // draw the pilot list text player_select_draw_list(); // draw copyright message on the bottom on the screen player_select_display_copyright(); if (!Player_select_input_mode) { player_select_process_noninput(k); } else { player_select_process_input(k); } // draw any pending messages on the bottom or middle of the screen player_select_display_all_text(); gr_flip(); }
// functions for selecting single/multiplayer pilots at the very beginning of FreeSpace void player_select_init() { int i; barracks_buttons *b; UI_WINDOW *w; // start a looping ambient sound main_hall_start_ambient(); Player_select_force_main_hall = ""; Player_select_screen_active = 1; // create the UI window Player_select_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0); Player_select_window.set_mask_bmap(Player_select_background_mask_bitmap[gr_screen.res]); // initialize the control buttons for (i=0; i<NUM_PLAYER_SELECT_BUTTONS; i++) { b = &Player_select_buttons[gr_screen.res][i]; // create the button b->button.create(&Player_select_window, NULL, b->x, b->y, 60, 30, 1, 1); // set its highlight action b->button.set_highlight_action(common_play_highlight_sound); // set its animation bitmaps b->button.set_bmaps(b->filename); // link the mask hotspot b->button.link_hotspot(b->hotspot); } // add some text w = &Player_select_window; w->add_XSTR("Create", 1034, Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].xt, Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].yt, &Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Clone", 1040, Player_select_buttons[gr_screen.res][CLONE_BUTTON].xt, Player_select_buttons[gr_screen.res][CLONE_BUTTON].yt, &Player_select_buttons[gr_screen.res][CLONE_BUTTON].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Remove", 1038, Player_select_buttons[gr_screen.res][DELETE_BUTTON].xt, Player_select_buttons[gr_screen.res][DELETE_BUTTON].yt, &Player_select_buttons[gr_screen.res][DELETE_BUTTON].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Select", 1039, Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].xt, Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].yt, &Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].button, UI_XSTR_COLOR_PINK); w->add_XSTR("Single", 1041, Player_select_buttons[gr_screen.res][SINGLE_BUTTON].xt, Player_select_buttons[gr_screen.res][SINGLE_BUTTON].yt, &Player_select_buttons[gr_screen.res][SINGLE_BUTTON].button, UI_XSTR_COLOR_GREEN); w->add_XSTR("Multi", 1042, Player_select_buttons[gr_screen.res][MULTI_BUTTON].xt, Player_select_buttons[gr_screen.res][MULTI_BUTTON].yt, &Player_select_buttons[gr_screen.res][MULTI_BUTTON].button, UI_XSTR_COLOR_GREEN); for(i=0; i<PLAYER_SELECT_NUM_TEXT; i++) { w->add_XSTR(&Player_select_text[gr_screen.res][i]); } // create the list button text select region Player_select_list_region.create(&Player_select_window, "", Choose_list_coords[gr_screen.res][0], Choose_list_coords[gr_screen.res][1], Choose_list_coords[gr_screen.res][2], Choose_list_coords[gr_screen.res][3], 0, 1); Player_select_list_region.hide(); // create the pilot callsign input box Player_select_input_box.create(&Player_select_window, Choose_list_coords[gr_screen.res][0], Choose_list_coords[gr_screen.res][1], Choose_list_coords[gr_screen.res][2] , CALLSIGN_LEN - 1, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_LETTER_FIRST); Player_select_input_box.set_valid_chars(VALID_PILOT_CHARS); Player_select_input_box.hide(); Player_select_input_box.disable(); // not currently entering any text Player_select_input_mode = 0; // set up hotkeys for buttons so we draw the correct animation frame when a key is pressed Player_select_buttons[gr_screen.res][SCROLL_LIST_UP_BUTTON].button.set_hotkey(KEY_UP); Player_select_buttons[gr_screen.res][SCROLL_LIST_DOWN_BUTTON].button.set_hotkey(KEY_DOWN); Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].button.set_hotkey(KEY_ENTER); Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].button.set_hotkey(KEY_C); // attempt to load in the background bitmap Player_select_background_bitmap = bm_load(Player_select_background_bitmap_name[gr_screen.res]); Assert(Player_select_background_bitmap >= 0); // load in the palette for the screen // Player_select_palette = bm_load(PLAYER_SELECT_PALETTE); // Player_select_palette_set = 0; // unset the very first pilot data Player_select_very_first_pilot = 0; Player_select_initial_count = -1; memset(Player_select_very_first_pilot_callsign, 0, CALLSIGN_LEN + 2); // if(Player_select_num_pilots == 0){ // Player_select_autoaccept = 1; // } // if we found a pilot if ( player_select_get_last_pilot_info() ) { if (Player_select_last_is_multi && !Networking_disabled) { player_select_init_player_stuff(PLAYER_SELECT_MODE_MULTI); } else { player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE); } } else { // otherwise go to the single player mode by default player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE); } if ( (Player_select_num_pilots == 1) && Player_select_input_mode ) { Player_select_autoaccept = 1; } }
// process pilot callsign void barracks_accept_new_pilot_callsign() { char buf[CALLSIGN_LEN + 1]; char name[MAX_FILENAME_LEN]; int i; int z = 0; Inputbox.get_text(buf); drop_white_space(buf); if (!isalpha(*buf)) { z = 1; } else { for (i=1; buf[i]; i++) { if (!isalpha(buf[i]) && !isdigit(buf[i]) && !strchr(VALID_PILOT_CHARS, buf[i])) { z = 1; return; } } } for (i=1; i<Num_pilots; i++) { if (!stricmp(buf, Pilots[i])) { z = 1; if (pilot_verify_overwrite() == 1) { strcpy_s(name, Pilots[Selected_line]); for (z=i; z<Num_pilots-1; z++) { strcpy(Pilots[z], Pilots[z + 1]); Pilot_ranks[z] = Pilot_ranks[z + 1]; } Num_pilots--; delete_pilot_file(name); z = 0; } return; } } if (!*buf || (i < Num_pilots)) { // duplicate name, alert user z = 1; } if (z) { gamesnd_play_iface(SND_GENERAL_FAIL); return; } strcpy(Pilots[0], buf); strcpy_s(Cur_pilot->callsign, buf); init_new_pilot(Cur_pilot, !Clone_flag); // again, make sure we set his flags correctly to ensure that he gets saved to the proper directory and gets // displayed correctly if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) { Cur_pilot->flags &= ~(PLAYER_FLAGS_IS_MULTI); } else { Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI; Cur_pilot->stats.flags |= STATS_FLAG_MULTIPLAYER; } if ( !(Game_mode & GM_STANDALONE_SERVER) ) { Pilot.save_player(Cur_pilot); } Selected_line = 0; barracks_new_pilot_selected(); barracks_set_callsign_enter_mode(false); }
// init the Popup window int popup_init(popup_info *pi, int flags) { int i; UI_BUTTON *b; popup_background *pbg; char *fname; int state, choice; // to have those cool holo projection popups we need to find what // state the game is then load the appropiate popup graphic for // display state = gameseq_get_state(); choice = pi->nchoices - 2; if (choice < 0) choice = 0; //pbg = &Popup_background[gr_screen.res][0][POPUP_DEFAULT]; switch (state) { case GS_STATE_INITIAL_PLAYER_SELECT: pbg = &Popup_background[gr_screen.res][choice][POPUP_REGDESK]; break; case GS_STATE_MAIN_MENU: pbg = &Popup_background[gr_screen.res][choice][POPUP_CONCOURSE]; break; case GS_STATE_SIMULATOR_ROOM: pbg = &Popup_background[gr_screen.res][choice][POPUP_LOADMISSION]; break; case GS_STATE_PILOT_MANAGE: pbg = &Popup_background[gr_screen.res][choice][POPUP_PILOTMANAGE]; break; case GS_STATE_VIEW_CUTSCENES: pbg = &Popup_background[gr_screen.res][choice][POPUP_FILMROOM]; break; case GS_STATE_GAME_PLAY: pbg = &Popup_background[gr_screen.res][choice][POPUP_FLY]; break; /*case GS_STATE_MULTI_DOGFIGHT_DEBRIEF: case GS_STATE_MULTI_JOIN_GAME: case GS_STATE_DEBRIEF: pbg = &Popup_background[gr_screen.res][choice][POPUP_DEFAULT]; break;*/ default: pbg = &Popup_background[gr_screen.res][choice][POPUP_DEFAULT]; } // anytime in single player, and multiplayer, not in mission, go ahead and stop time if ( (Game_mode & GM_NORMAL) || ((Game_mode && GM_MULTIPLAYER) && !(Game_mode & GM_IN_MISSION)) ){ game_stop_time(); } // create base window Popup_window.create(pbg->coords[0], pbg->coords[1], Popup_text_coords[gr_screen.res][2]+100, Popup_text_coords[gr_screen.res][3]+50, 0); Popup_window.set_foreground_bmap(pbg->filename); // create buttons for (i=0; i<pi->nchoices; i++) { b = &Popup_buttons[i]; // accommodate single-choice positive icon being positioned differently if ( (pi->nchoices == 1) && (flags&PF_USE_AFFIRMATIVE_ICON) ) { b->create(&Popup_window, "", Button_coords[gr_screen.res][i+1][0], Button_coords[gr_screen.res][i+1][1], 30, 25, 0, 1); } else { b->create(&Popup_window, "", Button_coords[gr_screen.res][i][0], Button_coords[gr_screen.res][i][1], 30, 25, 0, 1); } fname = popup_get_button_filename(pi, i, flags); b->set_bmaps(fname, 3, 0); b->set_highlight_action(common_play_highlight_sound); if ( pi->keypress[i] >= 0 ) { b->set_hotkey(pi->keypress[i]); } // create invisible buttons to detect mouse presses... can't use mask since button region is dynamically sized int lx, w, h; gr_get_string_size(&w, &h, pi->button_text[i]); lx = Button_regions[gr_screen.res][i][0] - w; b = &Popup_button_regions[i]; // accommodate single-choice positive icon being positioned differently if ( (pi->nchoices == 1) && (flags&PF_USE_AFFIRMATIVE_ICON) ) { b->create(&Popup_window, "", lx, Button_regions[gr_screen.res][i+1][1], Button_regions[gr_screen.res][i+1][2]-lx, Button_regions[gr_screen.res][i+1][3]-Button_regions[gr_screen.res][i+1][1], 0, 1); } else { b->create(&Popup_window, "", lx, Button_regions[gr_screen.res][i][1], Button_regions[gr_screen.res][i][2]-lx, Button_regions[gr_screen.res][i][3]-Button_regions[gr_screen.res][i][1], 0, 1); } b->hide(); } // webcursor setup if (Web_cursor_bitmap >= 0) { if (flags & PF_WEB_CURSOR_1) { Popup_buttons[1].set_custom_cursor_bmap(Web_cursor_bitmap); } if (flags & PF_WEB_CURSOR_2) { Popup_buttons[2].set_custom_cursor_bmap(Web_cursor_bitmap); } } // if this is an input popup, create and center the popup if(flags & PF_INPUT){ Popup_input.create(&Popup_window, Popup_text_coords[gr_screen.res][0], pbg->coords[1] + Popup_input_y_offset[gr_screen.res], Popup_text_coords[gr_screen.res][2], pi->max_input_text_len, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_CLR | UI_INPUTBOX_FLAG_ESC_FOC | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_TEXT_CEN); Popup_input.set_focus(); } Popup_default_choice=0; Popup_should_die = 0; if (flags & PF_RUN_STATE) { Popup_running_state = 1; } else { Popup_running_state = 0; } popup_split_lines(pi, flags); // create the popup slider (which we may not need to use Popup_slider.create(&Popup_window, Popup_slider_coords[gr_screen.res][0], Popup_slider_coords[gr_screen.res][1], Popup_slider_coords[gr_screen.res][2], Popup_slider_coords[gr_screen.res][3], pi->nlines > Popup_max_display[gr_screen.res] ? pi->nlines - Popup_max_display[gr_screen.res] : 0, Popup_slider_name[gr_screen.res], popup_slider_bogus, popup_slider_bogus, NULL); return 0; }