/* Create a new dialog, or reposition an existing one, in an appropriate position for showing prompts. Also draw a border around it. */ WINDOW * newdialog(int height, int width, int dismissable, WINDOW *win) { int starty, startx; if (height < 3) height = 3; if (height > LINES) height = LINES; if (width > COLS) width = COLS; if (game_is_running) { /* instead of covering up messages, draw the dialog as if it were a message */ fresh_message_line(TRUE); draw_msgwin(); if (getmaxx(msgwin) < getmaxx(stdscr)) width = getmaxx(msgwin) + (ui_flags.draw_outer_frame_lines ? 2 : 0); else width = getmaxx(stdscr); startx = 0; starty = getmaxy(msgwin) - (ui_flags.draw_outer_frame_lines ? 0 : 1); } else { /* out of game, keep dialogs centred */ starty = (LINES - height) / 2; startx = (COLS - width) / 2; } redraw_popup_windows(); if (!win) win = newwin_onscreen(height, width, starty, startx); else { mvwin(win, starty, startx); wresize(win, height, width); } werase(win); keypad(win, TRUE); meta(win, TRUE); nh_window_border(win, dismissable); return win; }
static void curses_print_message_core(int turn, const char *msg, nh_bool canblock) { int hsize, vsize, maxlen; nh_bool died; if (!msghistory) alloc_hist_array(); if (turn != prevturn) start_of_turn_curline = last_redraw_curline = curline; if (turn < prevturn) /* going back in time can happen during replay */ prune_messages(turn); if (!*msg) return; /* empty message. done. */ if (action > prevaction) { /* re-enable output if it was stopped and start a new line */ stopprint = FALSE; newline(); } prevturn = turn; prevaction = action; store_message(turn, msg); if (stopprint) return; /* * generally we want to put as many messages on one line as possible to * maximize space usage. A new line is begun after each player turn or if * more() is called via pause_messages(). "You die" also deserves its own line. * * If the message area is only one line high, space for "--More--" must be * reserved at the end of the line, otherwise --More-- is shown on a new line. */ getmaxyx(msgwin, vsize, hsize); maxlen = hsize; if (maxlen >= COLNO) maxlen = COLNO - 1; if (vsize == 1) maxlen -= 8; /* for "--More--" */ died = !strncmp(msg, "You die", 7); if (strlen(msglines[curline]) + strlen(msg) + 1 < maxlen && !died) { if (msglines[curline][0]) strcat(msglines[curline], " "); strcat(msglines[curline], msg); } else { int idx, output_count; char **output; wrap_text(maxlen, msg, &output_count, &output); for (idx = 0; idx < output_count; idx++) { if (strlen(msglines[curline]) > 0) fresh_message_line(canblock); if (stopprint) break; /* may get set in more() */ strcpy(msglines[curline], output[idx]); } free_wrap(output); } draw_msgwin(); }