| 838 | } |
| 839 | |
| 840 | char NetHackQtBind::qt_yn_function(const char *question_, |
| 841 | const char *choices, char def) |
| 842 | { |
| 843 | QString question(QString::fromLatin1(question_)); |
| 844 | QString message; |
| 845 | char yn_esc_map='\033'; |
| 846 | int result = -1; |
| 847 | |
| 848 | if (choices) { |
| 849 | QString choicebuf; |
| 850 | for (const char *p = choices; *p; ++p) { |
| 851 | if (*p == '\033') // <esc> and anything beyond is hidden |
| 852 | break; |
| 853 | choicebuf += visctrl(*p); |
| 854 | } |
| 855 | choicebuf.truncate(QBUFSZ - 1); // no effect if already shorter |
| 856 | message = QString("%1 [%2] ").arg(question, choicebuf); |
| 857 | if (def) |
| 858 | message += QString("(%1) ").arg(QChar(def)); |
| 859 | // escape maps to 'q' or 'n' or default, in that order |
| 860 | yn_esc_map = strchr(choices, 'q') ? 'q' |
| 861 | : strchr(choices, 'n') ? 'n' |
| 862 | : def; |
| 863 | } else { |
| 864 | message = question; |
| 865 | } |
| 866 | |
| 867 | if ( |
| 868 | /* |
| 869 | * The 'Settings' dialog doesn't present prompting-in-message-window |
| 870 | * as a candidate for customization but core supports 'popup_dialog' |
| 871 | * option so let player use that instead. |
| 872 | */ |
| 873 | #if 0 |
| 874 | qt_settings->ynInMessages() |
| 875 | #else |
| 876 | !::iflags.wc_popup_dialog |
| 877 | #endif |
| 878 | && WIN_MESSAGE != WIN_ERR) { |
| 879 | // Similar to X11 windowport `slow' feature. |
| 880 | |
| 881 | char cbuf[20]; |
| 882 | cbuf[0] = '\0'; |
| 883 | |
| 884 | // add the prompt to the message window |
| 885 | NetHackQtBind::qt_putstr(WIN_MESSAGE, ATR_BOLD, message); |
| 886 | |
| 887 | while (result < 0) { |
| 888 | cbuf[0] = '\0'; |
| 889 | char ch=NetHackQtBind::qt_nhgetch(); |
| 890 | if (ch=='\033') { |
| 891 | result=yn_esc_map; |
| 892 | Strcpy(cbuf, "ESC"); |
| 893 | } else if (choices && !strchr(choices,ch)) { |
| 894 | if (def && (ch==' ' || ch=='\r' || ch=='\n')) { |
| 895 | result=def; |
| 896 | Strcpy(cbuf, visctrl(def)); |
| 897 | } else { |
nothing calls this directly
no test coverage detected