diff options
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/acr.cc | 24 | ||||
-rw-r--r-- | crawl-ref/source/chardump.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/command.cc | 136 | ||||
-rw-r--r-- | crawl-ref/source/command.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/enum.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/menu.cc | 13 | ||||
-rw-r--r-- | crawl-ref/source/menu.h | 17 | ||||
-rw-r--r-- | crawl-ref/source/newgame.cc | 35 |
8 files changed, 128 insertions, 102 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 3b729ec44f..faa0737241 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -1054,29 +1054,6 @@ void process_command( command_type cmd ) { case CMD_DISPLAY_NOTES: display_notes(); break; - - case CMD_BROWSE_MANUAL: - { - FILE* fp; -#ifdef DATA_DIR_PATH - fp = fopen(DATA_DIR_PATH "/crawl_manual.txt", "r"); -#else - fp = fopen("../docs/crawl_manual.txt", "r"); - if ( !fp ) - fp = fopen("./docs/crawl_manual.txt", "r"); -#endif - if ( fp ) - { - browse_file(fp); - fclose(fp); - redraw_screen(); - } - else - { - mpr("Crawl manual (crawl_manual.txt) not found."); - } - } - break; case CMD_CLEAR_MAP: if (you.level_type != LEVEL_LABYRINTH && @@ -2387,7 +2364,6 @@ command_type keycode_to_command( keycode_type key ) { case ',': return CMD_PICKUP; case ':': return CMD_MAKE_NOTE; case '_': return CMD_DISPLAY_NOTES; - case '+': return CMD_BROWSE_MANUAL; case ';': return CMD_INSPECT_FLOOR; case '!': return CMD_SHOUT; case '^': return CMD_DISPLAY_RELIGION; diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc index d4d08a3f32..74a0799193 100644 --- a/crawl-ref/source/chardump.cc +++ b/crawl-ref/source/chardump.cc @@ -1055,9 +1055,8 @@ void resists_screen() formatted_scroller scr; for ( unsigned i = 0; i < vfs.size(); ++i ) - { scr.add_item_formatted_string(vfs[i]); - } + scr.show(); #ifdef DOS_TERM puttext(1, 1, 80, 25, dosbuffer); diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc index 1d1a07e6a7..555f0ec203 100644 --- a/crawl-ref/source/command.cc +++ b/crawl-ref/source/command.cc @@ -563,25 +563,6 @@ void list_weapons(void) mpr( info, MSGCH_EQUIPMENT, menu_colour(info) ); } // end list_weapons() -static int cmdhelp_keyfilter(int keyin) -{ - switch (keyin) - { - case CK_DOWN: - case '+': - case '=': - return ('>'); - case CK_UP: - case '-': - case '_': - return ('<'); - case 'x': - return (CK_ESCAPE); - default: - return (keyin); - } -} - static bool cmdhelp_textfilter(const std::string &tag) { #ifdef WIZARD @@ -626,8 +607,39 @@ static const char *targeting_help = "<w>*</w> : enter manual targeting (where <w>Dir.</w>\n" " moves the cursor and <w>.</w> etc. fire)\n" "<w>?</w> : describes monster under cursor\n"; + +// Add the contents of the file fp to the scroller menu m. +// If first_hotkey is nonzero, that will be the hotkey for the +// start of the contents of the file. +// If auto_hotkeys is true, the function will try to identify +// sections and add appropriate hotkeys. +static void add_file_to_scroller(FILE* fp, formatted_scroller& m, + int first_hotkey, bool auto_hotkeys ) +{ + bool next_is_hotkey = false; + bool is_first = true; + char buf[200]; + while (fgets(buf, sizeof buf, fp)) + { + MenuEntry* me = new MenuEntry(buf); + if ((next_is_hotkey && isupper(buf[0])) || (is_first && first_hotkey)) + { + me->add_hotkey(is_first ? first_hotkey : tolower(buf[0])); + me->level = MEL_TITLE; + me->colour = WHITE; + } + m.add_entry(me); + // XXX FIXME: there must be a better way to identify sections + next_is_hotkey = auto_hotkeys && + (strstr(buf, "------------------------------------------" + "------------------------------") == buf); + is_first = false; + } +} + -static void show_keyhelp_menu(const std::vector<formatted_string> &lines) +static void show_keyhelp_menu(const std::vector<formatted_string> &lines, + bool with_manual) { formatted_scroller cmd_help; @@ -636,14 +648,59 @@ static void show_keyhelp_menu(const std::vector<formatted_string> &lines) // FIXME: Allow for hiding Page down when at the end of the listing, ditto // for page up at start of listing. - cmd_help.set_more( - formatted_string::parse_string( - "<cyan>[ + : Page down. - : Page up." - " Esc/x exits.]")); - cmd_help.f_keyfilter = cmdhelp_keyfilter; + if ( with_manual ) + cmd_help.set_more( formatted_string::parse_string( + "<cyan>[ + : Page down. - : Page up." + " ? or letter for manual. Esc exits.]")); + else + cmd_help.set_more( formatted_string::parse_string( + "<cyan>[ + : Page down. - : Page up." + " Esc exits.]")); for (unsigned i = 0; i < lines.size(); ++i ) cmd_help.add_item_formatted_string(lines[i]); + + if ( with_manual ) + { + FILE* fp; +#ifdef DATA_DIR_PATH + fp = fopen(DATA_DIR_PATH "/crawl_manual.txt", "r"); +#else + fp = fopen("../docs/crawl_manual.txt", "r"); + if ( !fp ) + fp = fopen("./docs/crawl_manual.txt", "r"); +#endif + if ( fp ) + { + // put in a separator + cmd_help.add_item_string(""); + cmd_help.add_item_string(std::string(get_number_of_cols()-1,'-')); + add_file_to_scroller(fp, cmd_help, '?', true); + fclose(fp); + } + +#ifdef DATA_DIR_PATH + fp = fopen(DATA_DIR_PATH "/tables.txt", "r"); +#else + fp = fopen("../docs/tables.txt", "r"); + if ( !fp ) + fp = fopen("./docs/tables.txt", "r"); +#endif + if ( fp ) + { + // put in a separator + for ( int i = 0; i < get_number_of_lines() - 5; ++i ) + cmd_help.add_item_string(""); + MenuEntry* me = new MenuEntry("Tables"); + me->level = MEL_TITLE; + me->colour = WHITE; + me->add_hotkey('s'); + cmd_help.add_entry(me); + add_file_to_scroller(fp, cmd_help, 0, false); + fclose(fp); + } + + } cmd_help.show(); } @@ -656,7 +713,7 @@ void show_levelmap_help() formatted_lines.push_back( formatted_string::parse_string( lines[i], true, cmdhelp_textfilter)); - show_keyhelp_menu(formatted_lines); + show_keyhelp_menu(formatted_lines, false); } void list_commands(bool wizard) @@ -895,7 +952,7 @@ void list_commands(bool wizard) "stashes, and <w>Ctrl-E</w> to erase them.\n", true, true, cmdhelp_textfilter); - show_keyhelp_menu(cols.formatted_lines()); + show_keyhelp_menu(cols.formatted_lines(), true); } static void list_wizard_commands() @@ -993,28 +1050,3 @@ static const char *wizard_string( int i ) return (""); #endif } // end wizard_string() - -void browse_file( FILE* fp ) -{ - menu_browser m; - bool next_is_hotkey = false; - char buf[200]; - while (fgets(buf, sizeof buf, fp)) - { - MenuEntry* me = new MenuEntry(buf); - if ( next_is_hotkey && isupper(buf[0]) ) - { - me->add_hotkey(buf[0]); - me->add_hotkey(tolower(buf[0])); - me->level = MEL_TITLE; - me->colour = WHITE; - } - m.add_entry(me); - // XXX FIXME: there must be some better way to identify sections - next_is_hotkey = - (strstr(buf, - "--------------------------------------------------" - "----------------------") == buf); - } - m.show(); -} diff --git a/crawl-ref/source/command.h b/crawl-ref/source/command.h index f371cedc8c..0ae598360b 100644 --- a/crawl-ref/source/command.h +++ b/crawl-ref/source/command.h @@ -61,7 +61,6 @@ void swap_inv_slots(int slot1, int slot2, bool verbose); void show_levelmap_help(); void list_commands(bool wizard); -void browse_file(FILE* fp); // Actually defined in acr.cc; we may want to move this to command.cc void process_command(command_type cmd); diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index 79dfd9e4c3..39821d0625 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -633,7 +633,6 @@ enum command_type CMD_MAKE_NOTE, CMD_RESISTS_SCREEN, CMD_DISPLAY_NOTES, - CMD_BROWSE_MANUAL, /* overmap commands */ CMD_MAP_CLEAR_MAP, diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index f42d56725c..2f417f5179 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -1397,7 +1397,7 @@ int linebreak_string( std::string& s, int wrapcol, int maxcol ) return breakcount; } -bool menu_browser::jump_to( int i ) +bool formatted_scroller::jump_to( int i ) { if ( i == first_entry + 1 ) return false; @@ -1408,18 +1408,20 @@ bool menu_browser::jump_to( int i ) return true; } -bool menu_browser::process_key( int keyin ) +bool formatted_scroller::process_key( int keyin ) { + + if (f_keyfilter) + keyin = (*f_keyfilter)(keyin); + bool repaint = false; switch ( keyin ) { case 0: return true; - case CK_ENTER: case CK_ESCAPE: return false; - return false; - case ' ': case '+': case CK_PGDN: case '>': case '\'': + case ' ': case '+': case '=': case CK_PGDN: case '>': case '\'': repaint = page_down(); break; case '-': case CK_PGUP: case '<': case ';': @@ -1429,6 +1431,7 @@ bool menu_browser::process_key( int keyin ) repaint = line_up(); break; case CK_DOWN: + case CK_ENTER: repaint = line_down(); break; case CK_HOME: diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index b7194385f8..a67cca68e9 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -414,6 +414,10 @@ private: std::vector<formatted_string> flines; }; +// This class is for when (some of) your items are formatted, and +// selection is impossible...in other words, you just want a browser. +// Hotkeys can be set on menu items, in which case you can jump +// to them by pressing the appropriate key. class formatted_scroller : public Menu { public: @@ -425,20 +429,11 @@ public: virtual ~formatted_scroller(); protected: virtual void draw_index_item(int index, const MenuEntry* me) const; + virtual bool process_key( int keyin ); + bool jump_to( int linenum ); }; int menu_colour(const std::string &itemtext); int linebreak_string( std::string& s, int wrapcol, int maxcol ); -// Idea: Menu entries with the hotkey set will jump to that -// entry when the hotkey is pressed. -class menu_browser : public Menu -{ -public: - menu_browser() { flags &= (~MF_EASY_EXIT); } -protected: - virtual bool process_key( int keyin ); - bool jump_to( int linenum ); -}; - #endif diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index cf5e711264..3b50039221 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -71,6 +71,7 @@ #include "abl-show.h" #include "branch.h" +#include "command.h" #include "dungeon.h" #include "files.h" #include "fight.h" @@ -2950,11 +2951,16 @@ spec_query: textcolor( BROWN ); if (you.char_class == JOB_UNKNOWN) - cprintf(EOL "SPACE - Choose class first; " - "? - Random Species; * - Random Character; X - Quit" + cprintf(EOL + "SPACE - Choose class first; ? - Random Species; " + "* - Random Character" + EOL + "+ - Help; X - Quit" EOL); else - cprintf(EOL "? - Random; Bksp - Back to class selection; X - Quit" + cprintf(EOL + "+ - Help ? - Random; " + "Bksp - Back to class selection; X - Quit" EOL); if (Options.prev_race) @@ -2984,6 +2990,12 @@ spec_query: keyn = c_getch(); } + if ( keyn == '+' ) + { + list_commands(false); + return choose_race(); + } + if ((keyn == '\r' || keyn == '\n') && Options.prev_race && prevraceok) keyn = Options.prev_race; @@ -3144,11 +3156,16 @@ job_query: textcolor( BROWN ); if (!you.species) - cprintf(EOL "SPACE - Choose species first; " - "? - Random Class; * - Random Character; X - Quit" + cprintf(EOL + "SPACE - Choose species first; ? - Random Class; " + "* - Random Character" + EOL + "+ - Help; X - Quit" EOL); else - cprintf(EOL "? - Random; Bksp - Back to species selection; X - Quit" + cprintf(EOL + "+ - Help; ? - Random; " + "Bksp - Back to species selection; X - Quit" EOL); if (Options.prev_cls) @@ -3178,6 +3195,12 @@ job_query: keyn = c_getch(); } + if ( keyn == '+' ) + { + list_commands(false); + return choose_class(); + } + if ((keyn == '\r' || keyn == '\n') && Options.prev_cls && prevclassok) keyn = Options.prev_cls; |