/* ------------------------------------------------------------------------ * Quickstart? screen. * ------------------------------------------------------------------------ */ static enum birth_stage get_quickstart_command(void) { const char *prompt = "['Y' to use this character, 'N' to start afresh, 'C' to change name]"; enum birth_stage next = BIRTH_QUICKSTART; /* Prompt for it */ prt("New character based on previous one:", 0, 0); prt(prompt, Term->hgt - 1, Term->wid / 2 - strlen(prompt) / 2); /* Buttons */ button_kill_all(); button_add("[Y]", 'y'); button_add("[N]", 'n'); button_add("[C]", 'c'); redraw_stuff(p_ptr); do { /* Get a key */ struct keypress ke = inkey(); if (ke.code == 'N' || ke.code == 'n') { cmd_insert(CMD_BIRTH_RESET); next = BIRTH_SEX_CHOICE; } else if (ke.code == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } else if (ke.code == 'C' || ke.code == 'c') { next = BIRTH_NAME_CHOICE; } else if (ke.code == 'Y' || ke.code == 'y') { cmd_insert(CMD_ACCEPT_CHARACTER); next = BIRTH_COMPLETE; } } while (next == BIRTH_QUICKSTART); /* Buttons */ button_kill_all(); redraw_stuff(p_ptr); /* Clear prompt */ clear_from(23); return next; }
/* ------------------------------------------------------------------------ * Quickstart? screen. * ------------------------------------------------------------------------ */ static enum birth_stage get_quickstart_command(void) { const char *prompt = "['Y' to use this character, 'N' to start afresh, 'C' to change name]"; ui_event_data ke; enum birth_stage next = BIRTH_QUICKSTART; /* Prompt for it */ prt("New character based on previous one:", 0, 0); prt(prompt, Term->hgt - (mouse_buttons ? 2 : 1), Term->wid / 2 - strlen(prompt) / 2); /* Buttons */ button_kill_all(); button_add("[YES]", 'y'); button_add("[START_OVER]", 'n'); button_add("[CHANGE_NAME]", 'c'); redraw_stuff(); event_signal(EVENT_MOUSEBUTTONS); do { /* Get a key */ ke = inkey_ex(); if (ke.key == 'N' || ke.key == 'n') { cmd_insert(CMD_BIRTH_RESET, TRUE); next = BIRTH_SEX_CHOICE; } else if (ke.key == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } else if (ke.key == 'C' || ke.key == 'c') { next = BIRTH_NAME_CHOICE; } else if (ke.key == 'Y' || ke.key == 'y') { cmd_insert(CMD_ACCEPT_CHARACTER); next = BIRTH_COMPLETE; } } while (next == BIRTH_QUICKSTART); /* Buttons */ button_kill_all(); handle_stuff(); event_signal(EVENT_MOUSEBUTTONS); /* Clear prompt */ clear_from(23); return next; }
/* ------------------------------------------------------------------------ * Final confirmation of character. * ------------------------------------------------------------------------ */ static enum birth_stage get_confirm_command(void) { const char *prompt = "['ESC' to step back, 'S' to start over, or any other key to continue]"; ui_event_data ke; enum birth_stage next; /* Prompt for it */ prt(prompt, Term->hgt - (mouse_buttons ? 2 : 1), Term->wid / 2 - strlen(prompt) / 2); /* Buttons */ button_kill_all(); button_add("[CONTINUE]", 'q'); button_add("[BACK]", ESCAPE); button_add("[START OVER]", 'S'); handle_stuff(); event_signal(EVENT_MOUSEBUTTONS); /* Get a key */ ke = inkey_ex(); /* Start over */ if (ke.key == 'S' || ke.key == 's') { next = BIRTH_RESET; } else if (ke.key == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } else if (ke.key == ESCAPE) { next = BIRTH_BACK; } else { cmd_insert(CMD_ACCEPT_CHARACTER); next = BIRTH_COMPLETE; } /* Buttons */ button_kill_all(); handle_stuff(); event_signal(EVENT_MOUSEBUTTONS); /* Clear prompt */ clear_from(23); return next; }
/* ------------------------------------------------------------------------ * Final confirmation of character. * ------------------------------------------------------------------------ */ static enum birth_stage get_confirm_command(void) { const char *prompt = "['ESC' to step back, 'S' to start over, or any other key to continue]"; struct keypress ke; enum birth_stage next; /* Prompt for it */ prt(prompt, Term->hgt - 1, Term->wid / 2 - strlen(prompt) / 2); /* Buttons */ button_kill_all(); button_add("[Continue]", 'q'); button_add("[ESC]", ESCAPE); button_add("[S]", 'S'); redraw_stuff(p_ptr); /* Get a key */ ke = inkey(); /* Start over */ if (ke.code == 'S' || ke.code == 's') { next = BIRTH_RESET; } else if (ke.code == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } else if (ke.code == ESCAPE) { next = BIRTH_BACK; } else { cmd_insert(CMD_ACCEPT_CHARACTER); next = BIRTH_COMPLETE; } /* Buttons */ button_kill_all(); redraw_stuff(p_ptr); /* Clear prompt */ clear_from(23); return next; }
/* * Re-set and add the basic buttons * More are added in process_player depending on the * situation. */ void basic_buttons(void) { button_kill_all(); /* Make basic mouse buttons */ (void) button_add("[MENU]", KTRL('H')); (void) button_add("[HELP]", '?'); (void) button_add("[OPT]", '='); (void) button_add("[REPEAT]", KTRL('V')); if ((p_ptr->chp < p_ptr->mhp) || (p_ptr->csp < p_ptr->msp)) button_add("[REST]", 'R'); if ((cp_ptr->spell_book) && (p_ptr->csp)) button_add("[CAST]", 'm'); (void) button_add("[ITEM_MENU]", '|'); }
/* * Restore the buttons from backup */ void button_restore(void) { int i = 0; /* Remove the current lot */ button_kill_all(); /* Get all the previous buttons, copy them back */ while (button_backup[i].key) { /* Add them all back, forget the backups */ button_add(button_backup[i].label, button_backup[i].key); button_backup[i].key = '\0'; i++; } }
/* * Restore the buttons from backup */ void button_restore(void) { int i = 0; /* Remove the current lot */ button_kill_all(); if (button_backups) { button_backup *next; /* restore the 2d buttons */ button_stack = button_backups->buttons; button_num = button_backups->num; /* restore the 1d buttons */ if (button_backups->buttons_1d) { /* straight memory copy */ if (button_backups->num_1d > MAX_MOUSE_BUTTONS) { (void)C_COPY(button_1d_list, button_backups->buttons_1d, MAX_MOUSE_BUTTONS, button_mouse); button_1d_num = MAX_MOUSE_BUTTONS; button_1d_length = button_backups->length_1d; /* modify the length of the button row based on the buttons that were not copied */ for (i = MAX_MOUSE_BUTTONS; i < button_backups->num_1d; i++) { button_1d_length -= strlen(button_backups->buttons_1d[i].label); } } else { (void)C_COPY(button_1d_list, button_backups->buttons_1d, button_backups->num_1d, button_mouse_1d); button_1d_num = button_backups->num_1d; button_1d_length = button_backups->length_1d; } FREE(button_backups->buttons_1d); } /* remove the backup from the stack */ next = button_backups->next; if (button_backups->buttons_1d) { FREE(button_backups->buttons_1d); } FREE(button_backups); button_backups = next; } /* signal that the buttons need to be redrawn */ p_ptr->redraw |= (PR_BUTTONS); }
/* * Handle "target" and "look". * * Note that this code can be called from "get_aim_dir()". * * Currently, when "flag" is true, that is, when * "interesting" grids are being used, and a directional key is used, we * only scroll by a single panel, in the direction requested, and check * for any interesting grids on that panel. The "correct" solution would * actually involve scanning a larger set of grids, including ones in * panels which are adjacent to the one currently scanned, but this is * overkill for this function. XXX XXX * * Hack -- targetting/observing an "outer border grid" may induce * problems, so this is not currently allowed. * * The player can use the direction keys to move among "interesting" * grids in a heuristic manner, or the "space", "+", and "-" keys to * move through the "interesting" grids in a sequential manner, or * can enter "location" mode, and use the direction keys to move one * grid at a time in any direction. The "t" (set target) command will * only target a monster (as opposed to a location) if the monster is * target_able and the "interesting" mode is being used. * * The current grid is described using the "look" method above, and * a new command may be entered at any time, but note that if the * "TARGET_LOOK" bit flag is set (or if we are in "location" mode, * where "space" has no obvious meaning) then "space" will scan * through the description of the current grid until done, instead * of immediately jumping to the next "interesting" grid. This * allows the "target" command to retain its old semantics. * * The "*", "+", and "-" keys may always be used to jump immediately * to the next (or previous) interesting grid, in the proper mode. * * The "return" key may always be used to scan through a complete * grid description (forever). * * This command will cancel any old target, even if used from * inside the "look" command. * * 'mode' is one of TARGET_LOOK or TARGET_KILL. * 'x' and 'y' are the initial position of the target to be highlighted, * or -1 if no location is specified. * Returns TRUE if a target has been successfully set, FALSE otherwise. */ bool target_set_interactive(int mode, int x, int y) { int py = p_ptr->py; int px = p_ptr->px; int i, d, m, t, bd; int wid, hgt, help_prompt_loc; bool done = FALSE; bool flag = TRUE; bool help = FALSE; bool list_floor_objects = auto_display_lists; u16b path_n; u16b path_g[PATH_SIZE]; u16b path_gx[PATH_SIZE]; ui_event_data query; char info[80]; /* These are used for displaying the path to the target */ char path_char[MAX_RANGE]; byte path_attr[MAX_RANGE]; /* If we haven't been given an initial location, start on the player. */ if (x == -1 || y == -1) { x = p_ptr->px; y = p_ptr->py; } /* If we /have/ been given an initial location, make sure we honour it by going into "free targeting" mode. */ else { flag = FALSE; } /* Cancel target */ target_set_monster(0); /* make some buttons */ button_backup_all(); button_kill_all(); button_add("[ESCAPE]", ESCAPE); button_add("[NEXT]", '+'); button_add("[PREV]", '-'); button_add("[PLAYER]", 'p'); button_add("[PATHFIND]", 'g'); button_add("[TARGET]", 't'); /* health_track(0); */ /* All grids are selectable */ if (mode & (TARGET_GRID)) { /* Disable other modes */ mode &= ~(TARGET_LOOK | TARGET_KILL | TARGET_TRAP); /* Disable interesting grids */ flag = FALSE; } /* Calculate the window location for the help prompt */ Term_get_size(&wid, &hgt); help_prompt_loc = hgt - (mouse_buttons ? 2 : 1); /* Display the help prompt */ prt("'?' - help", help_prompt_loc, 0); /* Prepare the "temp" array */ target_set_interactive_prepare(mode); /* Start near the player */ m = 0; /* Interact */ while (!done) { button_kill('l'); button_kill('?'); if (list_floor_objects) { button_add("[HIDE_OBJLIST]", 'l'); } else button_add("[SHOW_OBJLIST]", 'l'); if (help) { button_add("[HIDE_HELP]", '?'); } else button_add("[SHOW_HELP]",'?'); /* Interesting grids */ if (flag && temp_n) { bool path_drawn = FALSE; int yy, xx; y = temp_y[m]; x = temp_x[m]; button_add("[SCAN]",'o'); /* Update help */ if (help) { bool good_target = ((cave_m_idx[y][x] > 0) && target_able(cave_m_idx[y][x])); target_display_help(good_target, !(flag && temp_n)); } /* Dummy pointers to send to project_path */ yy = y; xx = x; /* Allow targets for monsters....or traps, if applicable */ if (((cave_m_idx[y][x] > 0) && target_able(cave_m_idx[y][x])) || ((mode & (TARGET_TRAP)) && target_able_trap(y, x))) { strcpy(info, "q,t,r,l,p,o,+,-,<dir>"); } /* Dis-allow target */ else { strcpy(info, "q,p,l,o,+,-,<dir>"); } /* Adjust panel if needed */ if (adjust_panel(y, x)) { /* Handle stuff */ handle_stuff(); } /* Find the path. */ path_n = project_path(path_g, path_gx, MAX_RANGE, py, px, &yy, &xx, PROJECT_THRU); /* Draw the path in "target" mode. If there is one */ if ((mode & (TARGET_KILL)) && (cave_info[y][x] & (CAVE_FIRE))) { path_drawn = draw_path(path_n, path_g, path_char, path_attr, py, px, y, x); } event_signal(EVENT_MOUSEBUTTONS); /* Describe and Prompt */ query = target_set_interactive_aux(y, x, mode, info, list_floor_objects); /* Remove the path */ if (path_drawn) load_path(path_n, path_g, path_char, path_attr); /* Cancel tracking */ /* health_track(0); */ /* Assume no "direction" */ d = 0; /* Analyze */ switch (query.key) { case ESCAPE: case 'q': { done = TRUE; break; } case ' ': case '*': case '+': { if (++m == temp_n) m = 0; break; } case '-': { if (m-- == 0) m = temp_n - 1; break; } case 'p': { /* Recenter around player */ verify_panel(); /* Handle stuff */ handle_stuff(); y = py; x = px; } case 'o': { flag = FALSE; break; } case 'm': { break; } /* If we click, move the target location to the click and switch to "free targetting" mode by unsetting 'flag'. This means we get some info about wherever we've picked. */ case DEFINED_XFF: { x = KEY_GRID_X(query); y = KEY_GRID_Y(query); flag = FALSE; break; } case 't': case '5': case '0': case '.': { int m_idx = cave_m_idx[y][x]; if ((m_idx > 0) && target_able(m_idx)) { health_track(m_idx); target_set_monster(m_idx); done = TRUE; } else if ((mode & (TARGET_TRAP)) && target_able_trap(y, x)) { target_set_location(y, x); done = TRUE; } else if (mode & (TARGET_PROBE)) { target_set_location(y, x); done = TRUE; } else { bell("Illegal target!"); } break; } case 'g': { cmd_insert(CMD_PATHFIND, y, x); done = TRUE; break; } case 'l': { list_floor_objects = (!list_floor_objects); } case '?': { help = !help; /* Redraw main window */ p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP); Term_clear(); handle_stuff(); if (!help) prt("'?' - help", help_prompt_loc, 0); break; } default: { /* Extract direction */ d = target_dir(query.key); /* Oops */ if (!d) bell("Illegal command for target mode!"); break; } } /* Hack -- move around */ if (d) { int old_y = temp_y[m]; int old_x = temp_x[m]; /* Find a new monster */ i = target_pick(old_y, old_x, ddy[d], ddx[d]); /* Scroll to find interesting grid */ if (i < 0) { int old_wy = Term->offset_y; int old_wx = Term->offset_x; /* Change if legal */ if (change_panel(d)) { /* Recalculate interesting grids */ target_set_interactive_prepare(mode); /* Find a new monster */ i = target_pick(old_y, old_x, ddy[d], ddx[d]); /* Restore panel if needed */ if ((i < 0) && modify_panel(Term, old_wy, old_wx)) { /* Recalculate interesting grids */ target_set_interactive_prepare(mode); } /* Handle stuff */ handle_stuff(); } } /* Use interesting grid if found */ if (i >= 0) m = i; } } /* Arbitrary grids */ else { bool path_drawn = FALSE; /* Dummy pointers to send to project_path */ int yy = y; int xx = x; /* Don't need this button any more */ button_kill('o'); /* Update help */ if (help) { bool good_target = ((cave_m_idx[y][x] > 0) && target_able(cave_m_idx[y][x])); target_display_help(good_target, !(flag && temp_n)); } /* Default prompt */ if (!(mode & (TARGET_GRID))) { strcpy(info, "q,t,l,p,m,+,-,<dir>"); } /* Disable monster selection */ else { strcpy(info, "q,t,l.p,+,-,<dir>"); } /* Find the path. */ path_n = project_path(path_g, path_gx, MAX_RANGE, py, px, &yy, &xx, PROJECT_THRU); /* Draw the path in "target" mode. If there is one */ if ((mode & (TARGET_KILL)) && (cave_info[y][x] & (CAVE_FIRE))) { /* Save target info */ path_drawn = draw_path(path_n, path_g, path_char, path_attr, py, px, y, x); } event_signal(EVENT_MOUSEBUTTONS); /* Describe and Prompt (enable "TARGET_LOOK") */ query = target_set_interactive_aux(y, x, (mode | TARGET_LOOK), info, list_floor_objects); /* Remove the path */ if (path_drawn) load_path(path_n, path_g, path_char, path_attr); /* Cancel tracking */ /* health_track(0); */ /* Assume no direction */ d = 0; /* Analyze the keypress */ switch (query.key) { case ESCAPE: case 'q': { done = TRUE; break; } case ' ': case '*': case '+': case '-': { break; } case 'p': { /* Recenter around player */ verify_panel(); /* Handle stuff */ handle_stuff(); y = py; x = px; } case 'o': { break; } case 'm': { /* Monster selection is disabled */ if (mode & (TARGET_GRID)) break; flag = TRUE; m = 0; bd = 999; /* Pick a nearby monster */ for (i = 0; i < temp_n; i++) { t = distance(y, x, temp_y[i], temp_x[i]); /* Pick closest */ if (t < bd) { m = i; bd = t; } } /* Nothing interesting */ if (bd == 999) flag = FALSE; break; } case '\xff': { /* We only target if we click somewhere where the cursor is already (i.e. a double-click without a time limit) */ if (KEY_GRID_X(query) == x && KEY_GRID_Y(query) == y) { /* Make an attempt to target the monster on the given square rather than the square itself (it seems this is the more likely intention of clicking on a monster). */ int m_idx = cave_m_idx[y][x]; if ((m_idx > 0) && target_able(m_idx)) { health_track(m_idx); target_set_monster(m_idx); } else { /* There is no monster, or it isn't targettable, so target the location instead. */ target_set_location(y, x); } done = TRUE; } else { /* Just move the cursor for now - another click will target. */ x = KEY_GRID_X(query); y = KEY_GRID_Y(query); } break; } case 't': case '5': case '0': case '.': { target_set_location(y, x); done = TRUE; break; } case 'g': { cmd_insert(CMD_PATHFIND, y, x); done = TRUE; break; } case 'l': { list_floor_objects = (!list_floor_objects); } case '?': { help = !help; /* Redraw main window */ p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP); Term_clear(); handle_stuff(); if (!help) prt("'?' - help.", help_prompt_loc, 0); break; } default: { /* Extract a direction */ d = target_dir(query.key); /* Oops */ if (!d) bell("Illegal command for target mode!"); break; } } /* Handle "direction" */ if (d) { int dungeon_hgt = p_ptr->cur_map_hgt; int dungeon_wid = p_ptr->cur_map_wid; /* Move */ x += ddx[d]; y += ddy[d]; /* Slide into legality */ if (x >= dungeon_wid - 1) x--; else if (x <= 0) x++; /* Slide into legality */ if (y >= dungeon_hgt - 1) y--; else if (y <= 0) y++; /* Adjust panel if needed */ if (adjust_panel(y, x)) { /* Handle stuff */ handle_stuff(); /* Recalculate interesting grids */ target_set_interactive_prepare(mode); } } } } /* Forget */ temp_n = 0; /* Redraw as necessary */ if (help) { p_ptr->redraw |= (PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP); Term_clear(); } else { prt("", 0, 0); prt("", help_prompt_loc, 0); p_ptr->redraw |= (PR_DEPTH | PR_STATUS); } /* Recenter around player */ verify_panel(); /* Restore buttons */ button_restore(); /* Handle stuff */ handle_stuff(); /* Failure to set target */ if (!p_ptr->target_set) return (FALSE); /* Success */ return (TRUE); }
/* * Make a backup of the current buttons */ bool button_backup_all(bool kill_all) { button_backup *newbackup; newbackup = RNEW(button_backup); if(!newbackup) { return FALSE; } /* copy the 2d buttons */ if (kill_all) { newbackup->buttons = button_stack; newbackup->num = button_num; button_stack = NULL; button_num = 0; } else { /* copy the buttons to new memory */ button_mouse *dest, *src, *end; newbackup->buttons = NULL; newbackup->num = 0; end = NULL; src = button_stack; while (src) { dest = RNEW(button_mouse); if (!dest) { FREE(newbackup); return FALSE; } (void)C_COPY(dest, src, 1, button_mouse); if (src->label) { dest->label = (char*)string_make(src->label); } if (!(newbackup->buttons)) { newbackup->buttons = dest; } if (end) { end->next = dest; } end = dest; newbackup->num++; dest->next = NULL; src = src->next; } #if 0 int i; button_mouse *button; newbackup->buttons = C_RNEW(button_num, button_mouse); if (!(newbackup->buttons)) { FREE(newbackup); return FALSE; } button = button_stack; for (i=0; i<button_num; i++) { if (button) { /* Straight memory copy */ (void)C_COPY(&(newbackup->buttons[i]), button, 1, button_mouse); if (button->label) { newbackup->buttons[i].label = string_make(button->label); } button = button->next; } if (button) { newbackup->buttons[i].next = &(newbackup->buttons[i+1]); } } newbackup->num = button_num; #endif } /* copy the 1d buttons */ if (button_1d_num == 0) { newbackup->buttons_1d = NULL; newbackup->num_1d = 0; newbackup->length_1d = 0; } else { newbackup->buttons_1d = C_RNEW(button_1d_num, button_mouse_1d); if (!(newbackup->buttons_1d)) { /* free the 2d buttons TODO */ if (newbackup->buttons && !kill_all) { int i; for (i=0; i<newbackup->num; i++) { if (newbackup->buttons[i].label) { string_free(newbackup->buttons[i].label); } } FREE(newbackup->buttons); } FREE(newbackup); return FALSE; } /* Straight memory copy */ (void)C_COPY(newbackup->buttons_1d, button_1d_list, button_1d_num, button_mouse_1d); newbackup->num_1d = button_1d_num; newbackup->length_1d = button_1d_length; } /* push the backup onto the stack */ newbackup->next = button_backups; button_backups = newbackup; if (kill_all && (button_num || button_1d_num)) { button_kill_all(); } /* Redraw */ p_ptr->redraw |= (PR_BUTTONS); return TRUE; }
static enum birth_stage point_based_command(void) { static int stat = 0; char ch; enum birth_stage next = BIRTH_POINTBASED; ui_event_data ke; /* Add buttons */ button_kill_all(); button_add("[ESCAPE]", ESCAPE); button_add("[ACCEPT]", '\r'); button_add("[RESET STATS]", 'r'); button_add("[UP]", '8'); button_add("[DOWN]", '2'); button_add("[DEC_STAT]", '4'); button_add("[INC_STAT]", '6'); button_add("[QUIT]", '\x18'); /* CTRL-X */ clear_from(Term->hgt - 2); handle_stuff(); event_signal(EVENT_MOUSEBUTTONS); /* point_based_display();*/ /* Place cursor just after cost of current stat */ Term_gotoxy(COSTS_COL + 4, COSTS_ROW + stat); /* Get key */ /* Prompt and get a command */ ke = inkey_ex(); ch = ke.key; if (ch == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } /* Go back a step, or back to the start of this step */ else if (ch == ESCAPE) { next = BIRTH_BACK; } else if (ch == 'r' || ch == 'R') { cmd_insert(CMD_RESET_STATS, FALSE); } /* Done */ else if ((ch == '\r') || (ch == '\n')) { next = BIRTH_NAME_CHOICE; } else { ch = target_dir(ch); /* Prev stat, looping round to the bottom when going off the top */ if (ch == 8) stat = (stat + A_MAX - 1) % A_MAX; /* Next stat, looping round to the top when going off the bottom */ if (ch == 2) stat = (stat + 1) % A_MAX; /* Decrease stat (if possible) */ if (ch == 4) { cmd_insert(CMD_SELL_STAT, stat); } /* Increase stat (if possible) */ if (ch == 6) { cmd_insert(CMD_BUY_STAT, stat); } } button_kill_all(); event_signal(EVENT_MOUSEBUTTONS); return next; }
static enum birth_stage roller_command(bool first_call) { char prompt[80] = ""; size_t promptlen = 0; ui_event_data ke; char ch; enum birth_stage next = BIRTH_ROLLER; /* Used to keep track of whether we've rolled a character before or not. */ static bool prev_roll = FALSE; /* Display the player - a bit cheaty, but never mind. */ display_player(0, TRUE); if (first_call) prev_roll = FALSE; /* Add buttons */ button_kill_all(); button_add("[ESCAPE]", ESCAPE); button_add("[ACCEPT]", '\r'); button_add("[REROLL]", 'r'); if (prev_roll) button_add("[PREV]", 'p'); button_add("[HELP]", '?'); button_add("[QUIT]", '\x18'); /* CTRL-X */ clear_from(Term->hgt - 2); handle_stuff(); event_signal(EVENT_MOUSEBUTTONS); /* Prepare a prompt (must squeeze everything in) */ strnfcat(prompt, sizeof (prompt), &promptlen, "['r' to reroll"); if (prev_roll) strnfcat(prompt, sizeof(prompt), &promptlen, ", 'p' for prev"); strnfcat(prompt, sizeof (prompt), &promptlen, " or 'Enter' to accept]"); /* Prompt for it */ prt(prompt, Term->hgt - (mouse_buttons ? 2 : 1), Term->wid / 2 - promptlen / 2); /* Prompt and get a command */ ke = inkey_ex(); ch = ke.key; if (ch == ESCAPE) { button_kill('r'); button_kill('p'); next = BIRTH_BACK; } /* 'Enter' accepts the roll */ if ((ch == '\r') || (ch == '\n')) { next = BIRTH_NAME_CHOICE; } /* Reroll this character */ else if ((ch == ' ') || (ch == 'r')) { cmd_insert(CMD_ROLL_STATS); prev_roll = TRUE; } /* Previous character */ else if (prev_roll && (ch == 'p')) { cmd_insert(CMD_PREV_STATS); } /* Quit */ else if (ch == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } /* Help XXX */ else if (ch == '?') { do_cmd_help(); } /* Nothing handled directly here */ else { bell("Illegal roller command!"); } /* Kill buttons */ button_kill_all(); handle_stuff(); event_signal(EVENT_MOUSEBUTTONS); return next; }
/* Allow the user to select from the current menu, and return the corresponding command to the game. Some actions are handled entirely by the UI (displaying help text, for instance). */ static enum birth_stage menu_question(enum birth_stage current, menu_type *current_menu, cmd_code choice_command) { struct birthmenu_data *menu_data = current_menu->menu_data; int cursor = current_menu->cursor; ui_event_data cx; enum birth_stage next = BIRTH_RESET; /* Print the question currently being asked. */ clear_question(); Term_putstr(QUESTION_COL, QUESTION_ROW, -1, TERM_YELLOW, menu_data->hint); current_menu->cmd_keys = "?=*\r\n\x18"; /* ?, ,= *, \n, <ctl-X> */ while (next == BIRTH_RESET) { button_kill_all(); button_add("[ENTER]", '\r'); if (menu_data->allow_random) button_add("[RANDOM]", '*'); button_add("[ESCAPE]", ESCAPE); button_add("[OPTIONS]", '='); button_add("[HELP]", '?'); button_add("[QUIT]", '\x18'); /* CTRL-X */ event_signal(EVENT_MOUSEBUTTONS); /* Display the menu, wait for a selection of some sort to be made. */ cx = menu_select(current_menu, &cursor, EVT_CMD); /* As all the menus are displayed in "hierarchical" style, we allow use of "back" (left arrow key or equivalent) to step back in the proces as well as "escape". */ if (cx.type == EVT_BACK || cx.type == EVT_ESCAPE || cx.key == ESCAPE) { next = BIRTH_BACK; } /* '\xff' or DEFINED_XFF is a mouse selection, '\r' a keyboard one. */ else if (cx.key == DEFINED_XFF || cx.key == '\r') { if (current == BIRTH_ROLLER_CHOICE) { if (cursor) { /* Do a first roll of the stats */ cmd_insert(CMD_ROLL_STATS); next = current + 2; } else { /* * Make sure we've got a point-based char to play with. * We call point_based_start here to make sure we get * an update on the points totals before trying to * display the screen. The call to CMD_RESET_STATS * forces a rebuying of the stats to give us up-to-date * totals. This is, it should go without saying, a hack. */ point_based_start(); cmd_insert(CMD_RESET_STATS, TRUE); next = current + 1; } } else { cmd_insert(choice_command, cursor); next = current + 1; } } /* '*' chooses an option at random from those the game's provided. */ else if (cx.key == '*' && menu_data->allow_random) { current_menu->cursor = randint0(current_menu->count); cmd_insert(choice_command, current_menu->cursor); menu_refresh(current_menu); next = current + 1; } else if (cx.key == '=') { do_cmd_options(); next = current; } else if (cx.key == KTRL('X')) { cmd_insert(CMD_QUIT); next = BIRTH_COMPLETE; } else if (cx.key == '?') { do_cmd_help(); } } return next; }
/** * Display some character info */ static void death_info(const char *title, int row) { int i, j, k, which = 0; object_type *o_ptr; store_type *st_ptr; ui_event_data ke; bool done = FALSE; /* Get the store number of the home */ if (OPT(adult_dungeon)) which = NUM_TOWNS_SMALL * 4 + STORE_HOME; else { for (i = 0; i < NUM_TOWNS; i++) { /* Found the town */ if (p_ptr->home == towns[i]) { which += (i < NUM_TOWNS_SMALL ? 3 : STORE_HOME); break; } /* Next town */ else which += (i < NUM_TOWNS_SMALL ? MAX_STORES_SMALL : MAX_STORES_BIG); } } /* Activate the store */ st_ptr = &store[which]; screen_save(); /* Display player */ display_player(0); /* Prompt for inventory */ prt("Hit any key to see more information (ESC to abort): ", 0, 0); /* Buttons */ button_backup_all(); button_kill_all(); button_add("ESC", ESCAPE); button_add("Continue", 'q'); /* Allow abort at this point */ ke = inkey_ex(); if (ke.key == ESCAPE) done = TRUE; /* Show equipment and inventory */ /* Equipment -- if any */ if ((p_ptr->equip_cnt) && !done) { Term_clear(); item_tester_full = TRUE; show_equip(OLIST_WEIGHT); prt("You are using: -more-", 0, 0); ke = inkey_ex(); if (ke.key == ESCAPE) done = TRUE; } /* Inventory -- if any */ if ((p_ptr->inven_cnt) && !done) { Term_clear(); item_tester_full = TRUE; show_inven(OLIST_WEIGHT); prt("You are carrying: -more-", 0, 0); ke = inkey_ex(); if (ke.key == ESCAPE) done = TRUE; } /* Home -- if anything there */ if ((st_ptr->stock_num) && !done) { /* Display contents of the home */ for (k = 0, i = 0; i < st_ptr->stock_num; k++) { /* Clear screen */ Term_clear(); /* Show 12 items */ for (j = 0; (j < 12) && (i < st_ptr->stock_num); j++, i++) { byte attr; char o_name[80]; char tmp_val[80]; /* Get the object */ o_ptr = &st_ptr->stock[i]; /* Print header, clear line */ sprintf(tmp_val, "%c) ", I2A(j)); prt(tmp_val, j + 2, 4); /* Get the object description */ object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL); /* Get the inventory color */ attr = tval_to_attr[o_ptr->tval & 0x7F]; /* Display the object */ c_put_str(attr, o_name, j + 2, 7); } /* Caption */ prt(format("Your home contains (page %d): -more-", k + 1), 0, 0); /* Wait for it */ ke = inkey_ex(); if (ke.key == ESCAPE) done = TRUE; } } screen_load(); }
/** * Save a "bones" file for a dead character. Now activated and (slightly) * altered. Allows the inclusion of personalized strings. */ static void make_bones(void) { ang_file *fp; char str[1024]; ui_event_data answer; byte choice = 0; int i; /* Ignore wizards and borgs */ if (!(p_ptr->noscore & 0x00FF)) { /* Ignore people who die in town */ if (p_ptr->depth) { int level; char tmp[128]; /* Slightly more tenacious saving routine. */ for (i = 0; i < 5; i++) { /* Ghost hovers near level of death. */ if (i == 0) level = p_ptr->depth; else level = p_ptr->depth + 5 - damroll(2, 4); if (level < 1) level = randint1(4); /* XXX XXX XXX "Bones" name */ sprintf(tmp, "bone.%03d", level); /* Build the filename */ path_build(str, 1024, ANGBAND_DIR_BONE, tmp); /* Attempt to open the bones file */ fp = file_open(str, MODE_READ, FTYPE_TEXT); /* Close it right away */ if (fp) file_close(fp); /* Do not over-write a previous ghost */ if (fp) continue; /* If no file by that name exists, we can make a new one. */ if (!(fp)) break; } /* Failure */ if (fp) return; /* Try to write a new "Bones File" */ fp = file_open(str, MODE_WRITE, FTYPE_TEXT); /* Not allowed to write it? Weird. */ if (!fp) return; /* Save the info */ if (op_ptr->full_name[0] != '\0') file_putf(fp, "%s\n", op_ptr->full_name); else file_putf(fp, "Anonymous\n"); file_putf(fp, "%d\n", p_ptr->psex); file_putf(fp, "%d\n", p_ptr->prace); file_putf(fp, "%d\n", p_ptr->pclass); /* Clear screen */ Term_clear(); while (1) { /* Ask the player if he wants to add a personalized string. */ prt("Information about your character has been saved", 15, 0); prt("in a bones file. Would you like to give the", 16, 0); prt("ghost a special message or description? (yes/no)", 17, 0); button_add("Yes", 'y'); button_add("No", 'n'); answer = inkey_ex(); /* Clear last line */ clear_from(15); clear_from(16); /* Determine what the personalized string will be used for. */ if ((answer.key == 'Y') || (answer.key == 'y')) { prt("Will you add something for your ghost to say,", 15, 0); prt("or add to the monster description?", 16, 0); prt("((M)essage/(D)escription)", 17, 0); /* Buttons */ button_kill('y'); button_kill('n'); button_add("M", 'M'); button_add("D", 'D'); button_add("ESC", ESCAPE); while (1) { answer = inkey_ex(); clear_from(15); clear_from(16); if ((answer.key == 'M') || (answer.key == 'm')) { choice = 1; break; } else if ((answer.key == 'D') || (answer.key == 'd')) { choice = 2; break; } else { choice = 0; break; } } } else if ((answer.key == 'N') || (answer.key == 'n') || (answer.key == ESCAPE)) { choice = 0; break; } button_kill_all(); /* If requested, get the personalized string, and write it and * info on how it should be used in the bones file. Otherwise, * indicate the absence of such a string. */ if (choice) file_putf(fp, "%d:%s\n", choice, get_personalized_string(choice)); else file_putf(fp, "0: \n"); /* Close and save the Bones file */ file_close(fp); return; } } } }
/** * Show previous messages to the user * * The screen format uses line 0 and 23 for headers and prompts, * skips line 1 and 22, and uses line 2 thru 21 for old messages. * * This command shows you which commands you are viewing, and allows * you to "search" for strings in the recall. * * Note that messages may be longer than 80 characters, but they are * displayed using "infinite" length, with a special sub-command to * "slide" the virtual display to the left or right. * * Attempt to only hilight the matching portions of the string. */ void do_cmd_messages(void) { ui_event ke; int i, j, n, q; int wid, hgt; char shower[80]; char finder[80]; char p[80]; /* Wipe finder */ my_strcpy(finder, "", sizeof(shower)); /* Wipe shower */ my_strcpy(shower, "", sizeof(finder)); /* Total messages */ n = messages_num(); /* Start on first message */ i = 0; /* Start at leftmost edge */ q = 0; /* Get size */ Term_get_size(&wid, &hgt); /* Prompt */ strncpy(p, "[Press 'p' for older, 'n' for newer, ..., or ESCAPE]", 80); /* Save screen */ screen_save(); /* Adjust the buttons */ button_backup_all(); button_kill_all(); button_add("ESC", ESCAPE); button_add("-", '-'); button_add("=", '='); button_add("/", '/'); button_add("p", 'p'); button_add("n", 'n'); button_add("+", '+'); button_add("->", '6'); button_add("<-", '4'); p_ptr->redraw |= (PR_BUTTONS); /* Process requests until done */ while (1) { /* Clear screen */ Term_clear(); /* Dump messages */ for (j = 0; (j < hgt - 4) && (i + j < n); j++) { const char *msg = message_str((s16b)(i+j)); byte attr = message_color((s16b)(i+j)); /* Apply horizontal scroll */ msg = ((int)strlen(msg) >= q) ? (msg + q) : ""; /* Dump the messages, bottom to top */ Term_putstr(0, hgt - 3 - j, -1, attr, msg); /* Hilight "shower" */ if (shower[0]) { const char *str = msg; /* Display matches */ while ((str = strstr(str, shower)) != NULL) { int len = strlen(shower); /* Display the match */ Term_putstr(str-msg, hgt - 3 - j, len, TERM_YELLOW, shower); /* Advance */ str += len; } } } /* Display header XXX XXX XXX */ prt(format("Message Recall (%d-%d of %d), Offset %d", i, i + j - 1, n, q), 0, 0); /* Display prompt (not very informative) */ prt(p, hgt - 1, 0); redraw_stuff(p_ptr); /* Get a command */ ke = inkey_ex(); /* Exit on Escape */ if (ke.key.code == ESCAPE) break; /* Hack -- Save the old index */ j = i; /* Horizontal scroll */ if (ke.key.code == '4') { /* Scroll left */ q = (q >= wid / 2) ? (q - wid / 2) : 0; /* Success */ continue; } /* Horizontal scroll */ if (ke.key.code == '6') { /* Scroll right */ q = q + wid / 2; /* Success */ continue; } /* Hack -- handle show */ if (ke.key.code == '=') { /* Prompt */ prt("Show: ", hgt - 1, 0); /* Get a "shower" string, or continue */ if (!askfor_aux(shower, sizeof shower, NULL)) continue; /* Okay */ continue; } /* Hack -- handle find */ if (ke.key.code == '/') { s16b z; /* Prompt */ prt("Find: ", hgt - 1, 0); /* Get a "finder" string, or continue */ if (!askfor_aux(finder, sizeof finder, NULL)) continue; /* Show it */ my_strcpy(shower, finder, sizeof(shower)); /* Scan messages */ for (z = i + 1; z < n; z++) { const char *msg = message_str(z); /* Search for it */ if (strstr(msg, finder)) { /* New location */ i = z; /* Done */ break; } } } /* Recall 20 older messages */ if ((ke.key.code == 'p') || (ke.key.code == KTRL('P')) || (ke.key.code == ' ')) { /* Go older if legal */ if (i + 20 < n) i += 20; } /* Recall 10 older messages */ if (ke.key.code == '+') { /* Go older if legal */ if (i + 10 < n) i += 10; } /* Recall 1 older message */ if ((ke.key.code == '8') || (ke.key.code == '\n') || (ke.key.code == '\r')) { /* Go older if legal */ if (i + 1 < n) i += 1; } /* Recall 20 newer messages */ if ((ke.key.code == 'n') || (ke.key.code == KTRL('N'))) { /* Go newer (if able) */ i = (i >= 20) ? (i - 20) : 0; } /* Recall 10 newer messages */ if (ke.key.code == '-') { /* Go newer (if able) */ i = (i >= 10) ? (i - 10) : 0; } /* Recall 1 newer messages */ if (ke.key.code == '2') { /* Go newer (if able) */ i = (i >= 1) ? (i - 1) : 0; } /* Scroll forwards or backwards using mouse clicks */ if (ke.mouse.button) { if (ke.mouse.y <= hgt / 2) { /* Go older if legal */ if (i + 20 < n) i += 20; } else { /* Go newer (if able) */ i = (i >= 20) ? (i - 20) : 0; } } /* Hack -- Error of some kind */ if (i == j) bell(NULL); } /* Adjust the buttons */ button_restore(); /* Load screen */ screen_load(); }
/** * Hack -- change name */ void do_cmd_change_name(void) { ui_event ke; int col = 0; int last_line = 0; int top_line = 0; const char *p; /* Prompt */ p = "['c' change name, 'f' to file, scroll, or ESC]"; /* Save screen */ screen_save(); /* Adjust the buttons */ button_backup_all(); button_kill_all(); button_add("ESC", ESCAPE); button_add("Spc", ' '); button_add("-", '-'); button_add("c", 'c'); button_add("f", 'f'); button_add("->", ARROW_RIGHT); button_add("<-", ARROW_LEFT); p_ptr->redraw |= PR_BUTTONS; /* Make the array of lines */ C_WIPE(dumpline, DUMP_MAX_LINES, char_attr_line); last_line = make_dump(dumpline, 2); /* Forever */ while (1) { /* Display the player */ display_dump(dumpline, top_line, top_line + Term->hgt - 1, col); redraw_stuff(p_ptr); /* Clear the bottom line */ prt("", Term->hgt - 1, 0); /* Prompt */ Term_putstr(0, Term->hgt - 1, -1, TERM_WHITE, p); /* Query */ ke = inkey_ex(); /* Exit */ if (ke.key.code == ESCAPE) break; /* Change name */ if (ke.key.code == 'c') { char namebuf[32] = ""; if (get_name(namebuf, sizeof namebuf)) { /* Set player name */ my_strcpy(op_ptr->full_name, namebuf, sizeof(op_ptr->full_name)); /* Don't change savefile name. */ process_player_name(FALSE); } //(void) get_name(namebuf, sizeof namebuf); (void) make_dump(dumpline, 2); } /* File dump */ else if (ke.key.code == 'f') { char ftmp[80]; strnfmt(ftmp, sizeof ftmp, "%s.txt", op_ptr->base_name); if (get_string("File name: ", ftmp, 80)) { if (ftmp[0] && (ftmp[0] != ' ')) { if (file_character(ftmp, dumpline, last_line)) msg("Character dump failed!"); else msg("Character dump successful."); } } } /* Scroll down */ else if (ke.key.code == ARROW_DOWN) { if (top_line + Term->hgt - 2 < last_line) top_line++; } /* Page down */ else if (ke.key.code == ' ') { top_line = MIN(last_line - Term->hgt + 2, top_line + (Term->hgt - 2)); } /* Scroll up */ else if (ke.key.code == ARROW_UP) { if (top_line) top_line--; } /* Page up */ else if (ke.key.code == '-') { top_line -= (Term->hgt - 2) / 2; if (top_line < 0) top_line = 0; } /* Scroll left */ else if (ke.key.code == ARROW_LEFT) { if (col) col--; } /* Scroll right */ else if (ke.key.code == ARROW_RIGHT) { if (col < 32) col++; } /* Oops */ else { bell(NULL); } /* Flush messages */ message_flush(); } /* Adjust the buttons */ button_restore(); /* Load screen */ screen_load(); }