diff options
-rw-r--r-- | crawl-ref/source/menu.cc | 26 | ||||
-rw-r--r-- | crawl-ref/source/menu.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/newgame.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/spl-cast.cc | 154 |
4 files changed, 74 insertions, 110 deletions
diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index da948d09cc..d1b2d7ad6c 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -660,9 +660,9 @@ bool slider_menu::process_key(int key) return (false); } - if (selected == 0 && - (key == CK_UP || key == CK_PGUP || key == '<' || key == ';') && - Menu::is_set(MF_EASY_EXIT)) + if (Menu::is_set(MF_NOWRAP) && + selected == 0 && + (key == CK_UP || key == CK_PGUP || key == '<' || key == ';')) { oldselect = selected; selected = -1; @@ -862,9 +862,23 @@ bool slider_menu::fix_entry(int recurse_depth) void slider_menu::new_selection(int nsel) { if (nsel < 0) - nsel = 0; - if (nsel >= (int) items.size()) - nsel = items.size() - 1; + { + if ( !is_set(MF_NOWRAP) ) + do { + nsel += items.size(); + } while ( nsel < 0 ); + else + nsel = 0; + } + if (nsel >= static_cast<int>(items.size())) + { + if ( !is_set(MF_NOWRAP) ) + do { + nsel -= items.size(); + } while ( nsel >= static_cast<int>(items.size()) ); + else + nsel = items.size() - 1; + } const int old = selected; selected = nsel; diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index 04b1cfa7da..ceaf517fe4 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -257,7 +257,7 @@ class slider_menu : public Menu { public: // Multiselect would be awkward to implement. - slider_menu(int flags = MF_SINGLESELECT); + slider_menu(int flags = MF_SINGLESELECT | MF_NOWRAP); void display(); std::vector<MenuEntry *> show(); diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index 223c0d7938..4d5f9b1a99 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -2185,7 +2185,7 @@ static void enter_player_name(bool blankOK) me->data = &existing_chars[i]; char_menu.add_entry(me); } - char_menu.set_flags(MF_EASY_EXIT | MF_SINGLESELECT); + char_menu.set_flags(MF_NOWRAP | MF_SINGLESELECT); } do diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index c92df53d2e..b468cce37c 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -15,10 +15,8 @@ #include "AppHdr.h" -#include <ctype.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include <sstream> +#include <iomanip> #include "spl-cast.h" @@ -128,119 +126,71 @@ static void surge_power(spell_type spell) } } // end surge_power() -char list_spells(void) +static std::string spell_full_description(spell_type spell) { - int j; - int lines = 0; - unsigned int anything = 0; - unsigned int i; - int ki; - bool already = false; + std::ostringstream desc; - const int num_lines = get_number_of_lines(); - cursor_control coff(false); - - clrscr(); + desc << std::left; - cprintf( " Your Spells Type Power Success Level" ); - lines++; + // spell name + desc << std::setw(30) << spell_title(spell); - for (j = 0; j < 52; j++) + // spell schools + bool already = false; + for ( int i = 0; i <= SPTYP_LAST_EXPONENT; ++i) { - if (lines > num_lines - 2) + if (spell_typematch(spell, (1<<i))) { - gotoxy(1, num_lines); - cprintf("-more-"); - - ki = getch(); - - if (ki == ESCAPE) - { - return (ESCAPE); - } - - if (isalpha( ki )) - { - return (ki); - } + if (already) + desc << '/'; + desc << spelltype_short_name(1 << i); + already = true; + } + } + + const int so_far = desc.str().length(); + if ( so_far < 46 ) + desc << std::string(46 - so_far, ' '); - if (ki == 0) - ki = getch(); + // spell power, fail rate, level + desc << std::setw(14) << spell_power_string(spell) + << std::setw(12) << failure_rate_to_string(spell_fail(spell)) + << spell_difficulty(spell); - lines = 0; - clrscr(); - gotoxy(1, 1); - anything = 0; - } + return desc.str(); +} - const char letter = index_to_letter(j); - const spell_type spell = get_spell_by_letter(letter); +char list_spells() +{ + slider_menu spell_menu(MF_SINGLESELECT | MF_ANYPRINTABLE); + spell_menu.set_title(new MenuEntry(" Your Spells Type Power Success Level", MEL_TITLE)); + spell_menu.set_highlighter(NULL); + for ( int i = 0; i < 52; ++i ) + { + const char letter = index_to_letter(i); + const spell_type spell = get_spell_by_letter(letter); if (spell != SPELL_NO_SPELL) { - anything++; - - if (lines > 0) - cprintf(EOL); - - lines++; - - cprintf( " %c - %s", letter, spell_title( spell ) ); - gotoxy(35, wherey()); - - already = false; - - for (i = 0; i <= SPTYP_LAST_EXPONENT; i++) - { - if (spell_typematch( spell, (1 << i) )) - { - if (already) - cprintf( "/" ); - - cprintf( "%s", spelltype_short_name( 1 << i ) ); - already = true; - } - } - - char sval[16]; - - // 35--48 is the spell schools - - gotoxy(51, wherey()); - cprintf("%s", spell_power_string(spell)); - - //gotoxy(58, wherey()); - gotoxy(65, wherey()); - - cprintf( "%s", failure_rate_to_string(spell_fail(spell))); - - gotoxy(77, wherey()); - - itoa( spell_difficulty( spell ), sval, 10 ); - cprintf(sval); + MenuEntry* me = new MenuEntry(spell_full_description(spell), + MEL_ITEM, 0, letter); + spell_menu.add_entry(me); } - } // end of j loop - - if (anything > 0) + } + + std::vector<MenuEntry*> sel = spell_menu.show(); + redraw_screen(); + if ( sel.empty() ) { - ki = getch(); - - if (ki >= 'A' && ki <= 'z') - { - return (ki); - } - - if (ki == 0) - ki = getch(); - - return (anything); + return 0; } - - // was 35 - ki = getch(); - - return (ki); -} // end list_spells() + else + { + ASSERT(sel.size() == 1); + ASSERT(sel[0]->hotkeys.size() == 1); + return sel[0]->hotkeys[0]; + } +} static int apply_vehumet_wizardry_boost(spell_type spell, int chance) { |