Made help accessible from the race/class choosing screens by '+'.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@755 c06c8d41-db1a-0410-9941-cceddc491573
LAMIVDKY7LO5ONX5Z273ZCCEA5UBENOJD5VWNE4AK2EXGFED6BFQC
S7LXN4ZS57KFPKGOQNDZ6NZ7LOSQZIUHKO5DDZ2VTLJQSH2HN6MQC
VNSBAPL2FZNOR2R2NIJQITPHLQCMUE53U54GAENUSIN4526NHCPAC
OPSLMMKQZ7QX5RDNQXK4Y7ERO5MSZUCBYS47AIZGMPQZWYWHWBHAC
3CTGIWAOXJG4JJNLTN5DMPQQPDRJB6E6YB2R25HK6QF3PMKGZWDQC
5UVDIVD4NSXA52U4QMQIVST3GSZJ2A2YZK3RUEXKPM43YVQ7LI5AC
OHGGKG5PLPCOEVLYJKBNR4CVQAH6SDC6BSZOK7VCFRNEQY7ASSBAC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC
5ASC3STDYCNLZFEBN6UTMUCGDETHBR2OCBZCF5VIAZ5RRWLOTDYQC
2GV6OW7P54FXZ5OD2NUMX7MLXH424LYAFMOAUQ2UGSOLKLYDBJGAC
43ZTEB57FU7KE5EVMYWZONNVJBZCGF3JEAJZIY25LC4LGE65PG5QC
RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC
JJH7VX2LLBZPDKG24SQREWQLX6I6RYNWFECHRZVK7PT5KPQ4MAMAC
PP2XR22D3WGBCV4WYKPML55FTXD6K3LMYVB2AJPTKTCGKS6WTPPAC
// 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 );
};
// 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;
}
}
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.]"));
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);
}
}
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();
}
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;