// 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 }
// This function displays a popup message box and every frame it checks the condition() function // which is passed in as an argument. // If the condition() returns TRUE, the message box ends itself. This function returns whatever // the condition() did if the condition() occurred, and FALSE if the cancel button was pressed. int popup_till_condition(int (*condition)(), ...) { int choice; char *format, *s; va_list args; int flags = 0; if ( Popup_is_active ) { Int3(); // should never happen return -1; } //int nchoices = 1; Popup_info.nchoices = 1; Popup_flags = 0; va_start(args, condition ); // get button text s = va_arg( args, char * ); Popup_info.button_text[0] = NULL; popup_maybe_assign_keypress(&Popup_info, 0, 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_with_condition( &Popup_info, flags, condition ); io::mouse::CursorManager::get()->popStatus(); switch(choice) { case POPUP_ABORT: return 0; 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 }
// This function displays a popup message box and every frame it checks the condition() function // which is passed in as an argument. // If the condition() returns TRUE, the message box ends itself. This function returns whatever // the condition() did if the condition() occurred, and FALSE if the cancel button was pressed. int popup_till_condition(int (*condition)(), ...) { int choice; char *format, *s; va_list args; int flags = 0; if ( Popup_is_active ) { Int3(); // should never happen return -1; } //int nchoices = 1; Popup_info.nchoices = 1; Popup_flags = 0; va_start(args, condition ); // get button text s = va_arg( args, char * ); Popup_info.button_text[0] = NULL; popup_maybe_assign_keypress(&Popup_info, 0, 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); Popup_info.raw_text[POPUP_MAX_CHARS-1] = '\0'; gamesnd_play_iface(SND_POPUP_APPEAR); // play sound when popup appears Mouse_hidden = 0; Popup_is_active = 1; choice = popup_do_with_condition( &Popup_info, flags, condition ); switch(choice) { case POPUP_ABORT: return 0; default: return choice; } // end switch }