// input: flags => flags => formatting specificatons (PF_...) // nchoices => number of choices popup has // text_1 => text for first button // ... => // text_n => text for last button // msg text => text msg for popup (can be of form "%s",pl->text) // // exit: choice selected (0..nchoices-1) // will return -1 if there was an error or popup was aborted // // typical usage: // // rval = popup(0, 2, POPUP_OK, POPUP_CANCEL, "Sorry %s, try again", pl->callsign); int popup(int flags, int nchoices, ... ) { int i, choice; char *format, *s; va_list args; if ( Popup_is_active ) { Int3(); // should never happen return -1; } Popup_flags = flags; Assert( nchoices > 0 && nchoices <= POPUP_MAX_CHOICES ); Popup_info.nchoices = nchoices; va_start(args, nchoices ); // get button text for (i=0; i<nchoices; i++ ) { s = va_arg( args, char * ); Popup_info.button_text[i] = NULL; popup_maybe_assign_keypress(&Popup_info, i, s); } // get msg text format = va_arg( args, char * ); vsnprintf(Popup_info.raw_text, sizeof(Popup_info.raw_text)-1, format, args); va_end(args); Popup_info.raw_text[sizeof(Popup_info.raw_text)-1] = '\0'; gamesnd_play_iface(SND_POPUP_APPEAR); // play sound when popup appears io::mouse::CursorManager::get()->pushStatus(); io::mouse::CursorManager::get()->showCursor(true); Popup_is_active = 1; choice = popup_do( &Popup_info, flags ); io::mouse::CursorManager::get()->popStatus(); switch(choice) { case POPUP_ABORT: return -1; default: return choice; } // end switch }
// input: flags => flags => formatting specificatons (PF_...) // nchoices => number of choices popup has // text_1 => text for first button // ... => // text_n => text for last button // msg text => text msg for popup (can be of form "%s",pl->text) // // exit: choice selected (0..nchoices-1) // will return -1 if there was an error or popup was aborted // // typical usage: // // rval = popup(0, 2, POPUP_OK, POPUP_CANCEL, "Sorry %s, try again", pl->callsign); int popup(int flags, int nchoices, ... ) { int i, choice; char *format, *s; va_list args; if ( Popup_is_active ) { Int3(); // should never happen return -1; } Popup_flags = flags; Assert( nchoices > 0 && nchoices <= POPUP_MAX_CHOICES ); Popup_info.nchoices = nchoices; va_start(args, nchoices ); // get button text for (i=0; i<nchoices; i++ ) { s = va_arg( args, char * ); Popup_info.button_text[i] = NULL; popup_maybe_assign_keypress(&Popup_info, i, s); } // get msg text format = va_arg( args, char * ); Popup_info.raw_text[0] = 0; vsprintf(Popup_info.raw_text, format, args); va_end(args); Assert(strlen(Popup_info.raw_text) < POPUP_MAX_CHARS ); gamesnd_play_iface(SND_POPUP_APPEAR); // play sound when popup appears Mouse_hidden = 0; Popup_is_active = 1; choice = popup_do( &Popup_info, flags ); switch(choice) { case POPUP_ABORT: return -1; default: return choice; } // end switch }
// popup to return the value from an input box char *popup_input(int flags, const char *caption, int max_output_len) { if ( Popup_is_active ) { Int3(); // should never happen return NULL; } // make it an inputbox type popup Popup_flags = flags; Popup_flags |= PF_INPUT; // add a cancel button Popup_info.nchoices = 0; // popup_maybe_assign_keypress(&Popup_info, 0, "&Cancel"); // get msg text Assert(caption != NULL); strcpy_s(Popup_info.raw_text, caption); Assert(strlen(Popup_info.raw_text) < POPUP_MAX_CHARS ); // set input text length if((max_output_len > POPUP_INPUT_MAX_CHARS) || (max_output_len == -1)){ Popup_info.max_input_text_len = POPUP_INPUT_MAX_CHARS - 1; } else { Popup_info.max_input_text_len = max_output_len; } // zero the popup input text memset(Popup_info.input_text, 0, POPUP_INPUT_MAX_CHARS); gamesnd_play_iface(SND_POPUP_APPEAR); // play sound when popup appears Mouse_hidden = 0; Popup_is_active = 1; // if the user cancelled if(popup_do(&Popup_info, Popup_flags) == POPUP_ABORT){ return NULL; } // otherwise return the return Popup_info.input_text; }