MCPcopy Create free account
hub / github.com/NetHack/NetHack / qt_yn_function

Method qt_yn_function

outdated/win/Qt3/qt3_win.cpp:4958–5031  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4956}
4957
4958char NetHackQtBind::qt_yn_function(const char *question, const char *choices, CHAR_P def)
4959{
4960 if (qt_settings->ynInMessages() && WIN_MESSAGE!=WIN_ERR) {
4961 // Similar to X11 windowport `slow' feature.
4962
4963 char message[BUFSZ];
4964 char yn_esc_map='\033';
4965
4966 if (choices) {
4967 char *cb, choicebuf[QBUFSZ];
4968 Strcpy(choicebuf, choices);
4969 if ((cb = strchr(choicebuf, '\033')) != 0) {
4970 // anything beyond <esc> is hidden
4971 *cb = '\0';
4972 }
4973 (void)strncpy(message, question, QBUFSZ-1);
4974 message[QBUFSZ-1] = '\0';
4975 Sprintf(eos(message), " [%s]", choicebuf);
4976 if (def) Sprintf(eos(message), " (%c)", def);
4977 Strcat(message, " ");
4978 // escape maps to 'q' or 'n' or default, in that order
4979 yn_esc_map = (strchr(choices, 'q') ? 'q' :
4980 (strchr(choices, 'n') ? 'n' : def));
4981 } else {
4982 Strcpy(message, question);
4983 }
4984
4985#ifdef USE_POPUPS
4986 // Improve some special-cases (DIRKS 08/02/23)
4987 if (strcmp (choices,"ynq") == 0) {
4988 switch (QMessageBox::information (qApp->mainWidget(),"NetHack",question,"&Yes","&No","&Quit",0,2))
4989 {
4990 case 0: return 'y';
4991 case 1: return 'n';
4992 case 2: return 'q';
4993 }
4994 }
4995
4996 if (strcmp (choices,"yn") == 0) {
4997 switch (QMessageBox::information(qApp->mainWidget(),"NetHack",question,"&Yes", "&No",0,1))
4998 {
4999 case 0: return 'y';
5000 case 1: return 'n';
5001 }
5002 }
5003#endif
5004
5005 NetHackQtBind::qt_putstr(WIN_MESSAGE, ATR_BOLD, message);
5006
5007 int result=-1;
5008 while (result<0) {
5009 char ch=NetHackQtBind::qt_nhgetch();
5010 if (ch=='\033') {
5011 result=yn_esc_map;
5012 } else if (choices && !strchr(choices,ch)) {
5013 if (def && (ch==' ' || ch=='\r' || ch=='\n')) {
5014 result=def;
5015 } else {

Callers

nothing calls this directly

Calls 4

eosFunction · 0.85
mainWidgetMethod · 0.80
ynInMessagesMethod · 0.45
ExecMethod · 0.45

Tested by

no test coverage detected