static int _choose_spell(spell_info* spells, int ct, cptr desc, int max_cost) { int choice = -1; char prompt1[140]; char prompt2[140]; variant name; bool describe = FALSE; var_init(&name); for (;;) { char ch = '\0'; strnfmt(prompt1, 78, "Use which %s? (Type '?' to Browse) ", desc); strnfmt(prompt2, 78, "Browse which %s? (Type '?' to Use)", desc); _list_spells(spells, ct, max_cost); /* Prompt User */ choice = -1; if (!get_com(describe ? prompt2 : prompt1, &ch, FALSE)) break; if (ch == '?') { describe = !describe; if (!get_com(describe ? prompt2 : prompt1, &ch, FALSE)) break; } if (isupper(ch)) choice = ch - 'A' + 26; else if (islower(ch)) choice = ch - 'a'; else if (ch >= '0' && ch <= '9') choice = ch - '0' + 52; /* Valid Choice? */ if (choice < 0 || choice >= ct) { bell(); continue; } if (describe) { _describe_spell(&spells[choice], _col_height(ct)); continue; } /* Good to go! */ break; } var_clear(&name); return choice; }
static int _choose_form_imp(int ct) { int choice = -1; char prompt1[140]; char prompt2[140]; bool describe = FALSE; strnfmt(prompt1, 78, "Mimic which %s? (Type '?' to Browse) ", "Race"); strnfmt(prompt2, 78, "Browse which %s? (Type '?' to Use)", "Race"); _list_forms(ct); for (;;) { char ch = '\0'; /* Prompt User */ choice = -1; if (!get_com(describe ? prompt2 : prompt1, &ch, FALSE)) break; if (ch == '?') { describe = !describe; if (!get_com(describe ? prompt2 : prompt1, &ch, FALSE)) break; } if (isupper(ch)) choice = ch - 'A' + 26; else if (islower(ch)) choice = ch - 'a'; else if (ch >= '0' && ch <= '9') choice = ch - '0' + 52; /* Valid Choice? */ if (choice < 0 || choice >= ct) { bell(); continue; } if (describe) { _describe_form(choice, _col_height(ct)); continue; } /* Good to go! */ break; } return choice; }
void browse_spells(spell_info* spells, int ct, cptr desc) { screen_save(); for(;;) { int choice = -1; choice = _choose_spell(spells, ct, desc, 10000); if (choice < 0 || choice >= ct) break; if (_describe_spell(&spells[choice], _col_height(ct))) break; } screen_load(); }
static void _list_forms(int ct) { char temp[140]; int i; int y = 1; int x = 10; int col_height = _col_height(ct); int col_width; Term_erase(x, y, 255); if (col_height == ct) { Term_erase(x, y, 255); put_str("Lv Cost Fail", y, x + 29); } else { col_width = 42; x = 1; Term_erase(x, y, 255); put_str("Lv Cost Fail", y, x + 29); put_str("Lv Cost Fail", y, x + col_width + 29); } for (i = 0; i < ct; i++) { char letter = '\0'; byte attr = TERM_WHITE; int level = _forms[i].level; int race_idx = _forms[i].race; race_t *race_ptr = get_race_t_aux(race_idx, 0); int cost = _form_cost(race_ptr->exp); int fail = calculate_fail_rate(level, _forms[i].fail, p_ptr->stat_ind[A_DEX]); if (i < 26) letter = I2A(i); else if (i < 52) letter = 'A' + i - 26; else letter = '0' + i - 52; sprintf(temp, " %c) ", letter); strcat(temp, format("%-23.23s %2d %4d %3d%%", race_ptr->name, level, cost, fail)); if (fail == 100) attr = TERM_L_DARK; if (i < col_height) { c_prt(attr, temp, y + i + 1, x); } else { c_prt(attr, temp, y + (i - col_height) + 1, (x + col_width)); } } }
static void _list_spells(spell_info* spells, int ct, int max_cost) { char temp[140]; int i; rect_t display = ui_menu_rect(); int col_height = _col_height(ct); int col_width; variant name, info, color; var_init(&name); var_init(&info); var_init(&color); Term_erase(display.x, display.y, display.cx); if (col_height == ct) { put_str("Lvl Cost Fail Desc", display.y, display.x + 29); } else { col_width = 42; put_str("Lvl Cost Fail", display.y, display.x + 29); put_str("Lvl Cost Fail", display.y, display.x + col_width + 29); } for (i = 0; i < ct; i++) { char letter = '\0'; byte attr = TERM_WHITE; spell_info* spell = &spells[i]; var_set_int(&color, TERM_WHITE); (spell->fn)(SPELL_NAME, &name); (spell->fn)(SPELL_INFO, &info); (spell->fn)(SPELL_COLOR, &color); attr = var_get_int(&color); if (i < 26) letter = I2A(i); else if (i < 52) letter = 'A' + i - 26; else letter = '0' + i - 52; sprintf(temp, " %c) ", letter); strcat(temp, format("%-23.23s %3d %4d %3d%%", var_get_string(&name), spell->level, spell->cost, spell->fail)); if (col_height == ct) strcat(temp, format(" %s", var_get_string(&info))); if (spell->fail == 100) attr = TERM_L_DARK; if (spell->cost > max_cost) attr = TERM_L_DARK; if (spell->level > p_ptr->lev) attr = TERM_L_DARK; if (i < col_height) { Term_erase(display.x, display.y + i + 1, display.cx); c_put_str(attr, temp, display.y + i + 1, display.x); } else { c_put_str(attr, temp, display.y + (i - col_height) + 1, display.x + col_width); } } Term_erase(display.x, display.y + col_height + 1, display.cx); var_clear(&name); var_clear(&info); var_clear(&color); }