summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-13 21:51:33 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-13 21:51:33 +0000
commit7f78db9414b3c2dd97da70ce74198f0360cdedc6 (patch)
treef39591afb980495e69fd438813e47f8273f47dd2 /crawl-ref
parentd34acfbefb3ac8ed2b22cc899976b7e9ba6a4593 (diff)
downloadcrawl-ref-7f78db9414b3c2dd97da70ce74198f0360cdedc6.tar.gz
crawl-ref-7f78db9414b3c2dd97da70ce74198f0360cdedc6.zip
Put in a very basic help browser on '+'. This is *not* a good key, I'm just
parking it here until more decisions on the browser come in. (It should probably be reachable by pressing '?' from the current '?' help screen.) It reads the manual from ../docs/crawl_manual.txt, so you'd better put it there! Yes, this is a hack and will have to be done better. You can press the letter of the section (e.g., 'j' or 'J') to jump to that section. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@627 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/acr.cc15
-rw-r--r--crawl-ref/source/command.cc22
-rw-r--r--crawl-ref/source/command.h3
-rw-r--r--crawl-ref/source/enum.h1
-rw-r--r--crawl-ref/source/invent.h6
-rw-r--r--crawl-ref/source/menu.cc53
-rw-r--r--crawl-ref/source/menu.h11
7 files changed, 103 insertions, 8 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 427218a601..3521e5dc55 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -1030,6 +1030,18 @@ void process_command( command_type cmd ) {
case CMD_DISPLAY_NOTES:
display_notes();
break;
+
+ case CMD_BROWSE_MANUAL:
+ {
+ FILE* fp = fopen("../docs/crawl_manual.txt", "r");
+ if ( fp )
+ {
+ browse_file(fp);
+ fclose(fp);
+ redraw_screen();
+ }
+ }
+ break;
case CMD_CLEAR_MAP:
if (you.level_type != LEVEL_LABYRINTH &&
@@ -1273,7 +1285,7 @@ void process_command( command_type cmd ) {
case CMD_SUSPEND_GAME:
// CTRL-Z suspend behaviour is implemented here,
// because we want to have CTRL-Y available...
- // and unfortuantely they tend to be stuck together.
+ // and unfortunately they tend to be stuck together.
clrscr();
unixcurses_shutdown();
kill(0, SIGTSTP);
@@ -2334,6 +2346,7 @@ 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/command.cc b/crawl-ref/source/command.cc
index 6e3d15756c..df35c8ea8f 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -1093,3 +1093,25 @@ static const char *command_string( int i )
: "");
} // end command_string()
#endif // OBSOLETE_COMMAND_HELP
+
+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 54424d4045..f371cedc8c 100644
--- a/crawl-ref/source/command.h
+++ b/crawl-ref/source/command.h
@@ -57,10 +57,11 @@ void list_armour(void);
* *********************************************************************** */
void list_jewellery(void);
-
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 38fd6b3846..9726ea4b0e 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -646,6 +646,7 @@ 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/invent.h b/crawl-ref/source/invent.h
index d99150b9dc..9ce3fbc5ac 100644
--- a/crawl-ref/source/invent.h
+++ b/crawl-ref/source/invent.h
@@ -182,12 +182,6 @@ unsigned char get_invent(int invent_type);
bool in_inventory(const item_def &i);
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: acr
- * *********************************************************************** */
-void list_commands(bool wizard);
-
std::string item_class_name(int type, bool terse = false);
bool check_warning_inscriptions(const item_def& item, operation_types oper);
diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc
index dba1d91b2a..ce1eac47b7 100644
--- a/crawl-ref/source/menu.cc
+++ b/crawl-ref/source/menu.cc
@@ -1375,3 +1375,56 @@ int linebreak_string( std::string& s, int wrapcol, int maxcol )
}
return breakcount;
}
+
+bool menu_browser::jump_to( int i )
+{
+ if ( i == first_entry + 1 )
+ return false;
+ if ( i == 0 )
+ first_entry = 0;
+ else
+ first_entry = i - 1;
+ return true;
+}
+
+bool menu_browser::process_key( int 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 '\'':
+ repaint = page_down();
+ break;
+ case '-': case CK_PGUP: case '<': case ';':
+ repaint = page_up();
+ break;
+ case CK_UP:
+ repaint = line_up();
+ break;
+ case CK_DOWN:
+ repaint = line_down();
+ break;
+ default:
+ // look for it as a hotkey
+ for ( unsigned int i = 0; i < items.size(); ++i )
+ {
+ // found it
+ if ( items[i]->is_hotkey(keyin) )
+ {
+ repaint = jump_to(i);
+ break;
+ }
+ }
+ break;
+ }
+
+ if (repaint)
+ draw_menu();
+ return true;
+}
diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h
index c920078b14..c2d9651734 100644
--- a/crawl-ref/source/menu.h
+++ b/crawl-ref/source/menu.h
@@ -430,4 +430,15 @@ protected:
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() {}
+protected:
+ virtual bool process_key( int keyin );
+ bool jump_to( int linenum );
+};
+
#endif