From aa300c86ccbb1cffa03ee8f6e0dca0e6ef48cef6 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sat, 26 Jan 2008 07:31:00 +0000 Subject: Added help for stash-search (dpeg). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3338 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/cio.cc | 4 ++ crawl-ref/source/cio.h | 5 +- crawl-ref/source/command.cc | 72 ++++++-------------------- crawl-ref/source/command.h | 1 + crawl-ref/source/dat/help.txt | 117 ++++++++++++++++++++++++++++++++++++++++++ crawl-ref/source/database.cc | 57 +++++++++++--------- crawl-ref/source/database.h | 2 + crawl-ref/source/files.cc | 2 +- crawl-ref/source/ouch.cc | 2 +- crawl-ref/source/stash.cc | 53 ++++++++++++++++--- 10 files changed, 225 insertions(+), 90 deletions(-) create mode 100644 crawl-ref/source/dat/help.txt (limited to 'crawl-ref') diff --git a/crawl-ref/source/cio.cc b/crawl-ref/source/cio.cc index f51b3a49bd..526c4d07b2 100644 --- a/crawl-ref/source/cio.cc +++ b/crawl-ref/source/cio.cc @@ -302,6 +302,10 @@ line_reader::line_reader(char *buf, size_t sz, int wrap) { } +line_reader::~line_reader() +{ +} + std::string line_reader::get_text() const { return (buffer); diff --git a/crawl-ref/source/cio.h b/crawl-ref/source/cio.h index 75e9ca048d..f0a0c2afa3 100644 --- a/crawl-ref/source/cio.h +++ b/crawl-ref/source/cio.h @@ -219,6 +219,7 @@ class line_reader public: line_reader(char *buffer, size_t bufsz, int wrap_col = get_number_of_cols()); + virtual ~line_reader(); typedef int (*keyproc)(int &key); @@ -231,14 +232,14 @@ public: protected: void cursorto(int newcpos); - int process_key(int ch); + virtual int process_key(int ch); void backspace(); void killword(); void kill_to_begin(); bool is_wordchar(int c); -private: +protected: char *buffer; size_t bufsz; input_history *history; diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc index 426e5c7d5d..cb9ec35c6f 100644 --- a/crawl-ref/source/command.cc +++ b/crawl-ref/source/command.cc @@ -557,30 +557,6 @@ static bool cmdhelp_textfilter(const std::string &tag) return (false); } -static const char *level_map_help = - "Level Map ('X' in main screen):\n" - "Esc : leave level map (also Space)\n" - "Dir.: move cursor\n" - "/ Dir., Shift-Dir.: move cursor far\n" - "-/+ : scroll level map up/down\n" - ". : travel (also Enter and , and ;)\n" - " (moves cursor to last travel\n" - " destination if still on @)\n" - "<</> : cycle through up/down stairs\n" - "^ : cycle through traps\n" - "Tab : cycle through shops and portals\n" - "X : cycle through travel eXclusions\n" - "x : change the radius of a travel exclusion\n" - "W : cycle through waypoints\n" - "* : cycle forward through stashes\n" - "/ : cycle backward through stashes\n" - "_ : cycle through altars\n" - "Ctrl-X : set travel eXclusion\n" - "Ctrl-E : Erase all travel exclusions\n" - "Ctrl-W : set Waypoint\n" - "Ctrl-C : Clear level and main maps\n" - "Ctrl-F : Forget level map\n"; - static const char *targeting_help_1 = "Examine surroundings ('x' in main):\n" "Esc : cancel (also Space)\n" @@ -620,32 +596,6 @@ static const char *targeting_help_2 = "Ctrl-N : cycle to next missile.\n"; -static const char *interlevel_travel_branch_help = - "Interlevel Travel (choose a branch):\n" - " Use the shortcut letter for a branch to select the branch for travel.\n" - "\n" - " Once you select a branch, you will be prompted for a depth in that\n" - " branch (more help is available there).\n" - "\n" - " Enter : Repeat last interlevel travel.\n" - " . : Travel to a level in the current branch.\n" - " << : Go up the nearest stairs.\n" - " > : Go down the nearest stairs.\n" - " Ctrl-P : Travel to a level in the branch above this one.\n" - " * : Show available waypoints (if any are set).\n" - " 0-9 : Go to the numbered waypoint.\n"; - -static const char *interlevel_travel_depth_help = - "Interlevel Travel (go to a specific level in the selected branch)\n" - " Type in the level number you want to go to and hit Enter, or use:\n" - " Enter : Go to the default level.\n" - " << : Change the default to one level above the current.\n" - " > : Change default to one level below the current.\n" - " -/p : Change default to the branch above this one.\n" - " $ : Change default to deepest visited level in this branch.\n" - " ^ : Change default to the entrance to the current level.\n" - "\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. @@ -1469,7 +1419,7 @@ static void show_keyhelp_menu(const std::vector &lines, cmd_help.show(); } -void show_specific_help( const char* help ) +void show_specific_help( const std::string &help ) { std::vector lines = split_string("\n", help, false, true); std::vector formatted_lines; @@ -1482,7 +1432,7 @@ void show_specific_help( const char* help ) void show_levelmap_help() { - show_specific_help( level_map_help ); + show_specific_help( getHelpString("level-map") ); } void show_targeting_help() @@ -1498,12 +1448,17 @@ void show_targeting_help() void show_interlevel_travel_branch_help() { - show_specific_help( interlevel_travel_branch_help ); + show_specific_help( getHelpString("interlevel-travel.branch.prompt") ); } void show_interlevel_travel_depth_help() { - show_specific_help( interlevel_travel_depth_help ); + show_specific_help( getHelpString("interlevel-travel.depth.prompt") ); +} + +void show_stash_search_help() +{ + show_specific_help( getHelpString("stash-search.prompt") ); } void list_commands(bool wizard, int hotkey, bool do_redraw_screen) @@ -1532,8 +1487,8 @@ void list_commands(bool wizard, int hotkey, bool do_redraw_screen) "or vi keys:\n" " 1 2 3 y k u\n" " \\|/ \\|/\n" - " 4-5-6" - " h-.-l\n" + " 4-5-6" + " h-.-l\n" " /|\\ /|\\\n" " 7 8 9 b j n\n", true, true, cmdhelp_textfilter); @@ -1619,7 +1574,10 @@ void list_commands(bool wizard, int hotkey, bool do_redraw_screen) "\n" "Searching in stashes allows regular\n" "expressions, and terms like 'altar'\n" - "or 'artefact' or 'long blades'.\n", + "or 'artefact' or 'long blades'.\n" + "\n" + "For more help on searching, you can\n" + "hit ? at the search prompt.\n", true, true, cmdhelp_textfilter); cols.add_formatted( diff --git a/crawl-ref/source/command.h b/crawl-ref/source/command.h index b64e4059d0..1ed6709f6e 100644 --- a/crawl-ref/source/command.h +++ b/crawl-ref/source/command.h @@ -62,6 +62,7 @@ void show_levelmap_help(); void show_targeting_help(); void show_interlevel_travel_branch_help(); void show_interlevel_travel_depth_help(); +void show_stash_search_help(); void list_commands(bool wizard, int hotkey = 0, bool do_redraw_screen = false); void list_tutorial_help(void); diff --git a/crawl-ref/source/dat/help.txt b/crawl-ref/source/dat/help.txt new file mode 100644 index 0000000000..22b849aba5 --- /dev/null +++ b/crawl-ref/source/dat/help.txt @@ -0,0 +1,117 @@ +%%%% +stash-search.prompt + +Searching the stash-tracker + +You can search for items and dungeon features by name (or a substring of the +name). In the list of search results, you can select a search result by its +hotkey to travel to its location. + +You can also examine shops and items in the search results by pressing ? +and then hitting the hotkey for the search result. This will show you a +description of the item or the contents of the shop. + +Some examples of search strings: +cure mutation find all potions of cure mutation, including potions + in shops. +cloak find all cloaks in the dungeon. +Lair:2 find everything known to be on Lair:2. +Lair:[2-4] finds everything on Lair:2-4. Regexes are allowed! Note + that Lair:[3-10] will not work as intended, since [x-y] is + a regex character range. +. is a shortcut to find everything on your current level. +Lair.*axe +or +axe && Lair both show all axes in the Lair. + + +Searching by item properties: + +You can search for spell names (such as Ignite Poison) to find spellbooks +or rods that contain the spell. + +You can search for artefact item properties (such as prevents.*teleport) +to find artefacts that have the property. + +If you're using stash.lua, you can also search by some additional item +properties: +artefact will find identified artefacts. +Skill names (such as Polearms or Long Blades) will find all +weapons that train that skill. + +If you're using stash.lua and have set annotate_item_class = true in your +init.txt, you can also search by item types such as book or +jewellery. + + +Finding Dungeon Features: + +You can search for dungeon features by name: all shops will be found by a search +for shop (including shops that do not have "shop" in their name); other +dungeon features can also be found by name: fountain, axe trap, +altar, etc. You can also search for altars by deity name: Zin. + + +The stash search string is case-insensitive. + + +Non-regex operators: + +You can use !! to negate a search string, && for a boolean AND, || for +boolean OR, and <<<< >> for grouping. + +For instance, to find rings (jewellery) but not ring mail you could use: +ring && !!mail +%%%% +level-map + +Level Map ('X' in main screen): +Esc : leave level map (also Space) +Dir.: move cursor +/ Dir., Shift-Dir.: move cursor far +-/+ : scroll level map up/down +. : travel (also Enter and , and ;) + (moves cursor to last travel + destination if still on @) +<</> : cycle through up/down stairs +^ : cycle through traps +Tab : cycle through shops and portals +X : cycle through travel eXclusions +x : change the radius of a travel exclusion +W : cycle through waypoints +* : cycle forward through stashes +/ : cycle backward through stashes +_ : cycle through altars +Ctrl-X : set travel eXclusion +Ctrl-E : Erase all travel exclusions +Ctrl-W : set Waypoint +Ctrl-C : Clear level and main maps +Ctrl-F : Forget level map +%%%% +interlevel-travel.branch.prompt + +Interlevel Travel (choose a branch): + Use the shortcut letter for a branch to select the branch for travel. + + Once you select a branch, you will be prompted for a depth in that + branch (more help is available there). + + Enter : Repeat last interlevel travel. + . : Travel to a level in the current branch. + << : Go up the nearest stairs. + > : Go down the nearest stairs. + Ctrl-P : Travel to a level in the branch above this one. + * : Show available waypoints (if any are set). + 0-9 : Go to the numbered waypoint. +%%%% +interlevel-travel.depth.prompt + +Interlevel Travel (go to a specific level in the selected branch) + Type in the level number you want to go to and hit Enter, or use: + Enter : Go to the default level. + << : Change the default to one level above the current. + > : Change default to one level below the current. + -/p : Change default to the branch above this one. + $ : Change default to deepest visited level in this branch. + ^ : Change default to the entrance to the current level. +%%%% diff --git a/crawl-ref/source/database.cc b/crawl-ref/source/database.cc index ff1b59bf2c..04accbd4f3 100644 --- a/crawl-ref/source/database.cc +++ b/crawl-ref/source/database.cc @@ -35,6 +35,7 @@ enum db_id { DB_SHOUT, DB_SPEAK, + DB_HELP, MAX_DBID }; @@ -50,7 +51,8 @@ struct SingleFileDB SingleFileDB singleFileDBs[MAX_DBID] = { SingleFileDB("shout"), - SingleFileDB("speak") + SingleFileDB("speak"), + SingleFileDB("help") }; #define DESC_BASE_NAME "descript" @@ -233,10 +235,8 @@ static void execute_embedded_lua(std::string &str) if (clua.execstring(lua.c_str(), "db_embedded_lua", 1)) { - std::string err = "{{" + clua.error; - err += "}}"; + std::string err = "{{" + clua.error + "}}"; str.replace(pos, lua_full.length(), err); - return; } @@ -249,11 +249,6 @@ static void execute_embedded_lua(std::string &str) } // while (pos != std::string::npos) } -static void trim_right(std::string &s) -{ - s.erase(s.find_last_not_of(" \r\t\n") + 1); -} - static void trim_leading_newlines(std::string &s) { s.erase(0, s.find_first_not_of("\n")); @@ -310,7 +305,7 @@ static void parse_text_db(std::ifstream &inf, DBM *db) else { std::string line = buf; - trim_right(line); + trim_string_right(line); value += line + "\n"; } } @@ -478,6 +473,27 @@ static std::string getRandomizedStr(DBM *database, const std::string &key, return str; } +static std::string query_database(DBM *db, std::string key, + bool canonicalise_key, bool run_lua) +{ + if (canonicalise_key) + { + // We have to canonicalize the key (in case the user typed it + // in and got the case wrong.) + lowercase(key); + } + + // Query the DB. + datum result = database_fetch(db, key); + + std::string str((const char *)result.dptr, result.dsize); + + if (run_lua) + execute_embedded_lua(str); + + return (str); +} + ///////////////////////////////////////////////////////////////////////////// // Description DB specific functions. @@ -486,19 +502,7 @@ std::string getLongDescription(const std::string &key) if (!descriptionDB) return (""); - // We have to canonicalize the key (in case the user typed it - // in and got the case wrong.) - std::string canonical_key = key; - lowercase(canonical_key); - - // Query the DB. - datum result = database_fetch(descriptionDB, canonical_key); - - // Cons up a (C++) string to return. The caller must release it. - std::string str((const char *)result.dptr, result.dsize); - - execute_embedded_lua(str); - return (str); + return query_database(descriptionDB, key, true, true); } std::vector getLongDescKeysByRegex(const std::string ®ex, @@ -598,3 +602,10 @@ std::string getSpeakString(const std::string &monst) return getRandomizedStr(get_dbm(DB_SPEAK), monst, "", num_replacements); } +///////////////////////////////////////////////////////////////////////////// +// Help DB specific functions. + +std::string getHelpString(const std::string &topic) +{ + return query_database(get_dbm(DB_HELP), topic, false, true); +} diff --git a/crawl-ref/source/database.h b/crawl-ref/source/database.h index 09b90364ea..a23773c6ce 100644 --- a/crawl-ref/source/database.h +++ b/crawl-ref/source/database.h @@ -60,4 +60,6 @@ std::vector getLongDescBodiesByRegex(const std::string ®ex, std::string getShoutString(const std::string &monst, const std::string &suffix = ""); std::string getSpeakString(const std::string &monst); +std::string getHelpString(const std::string &topic); + #endif diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index eed436232c..c656e2f596 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -356,7 +356,7 @@ static bool create_dirs(const std::string &dir) if (!dir_exists(path) && create_directory(path.c_str())) return (false); - path += FILE_SEPARATOR; + path += FILE_SEPARATOR; } return (true); } diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc index e57f43ccc0..2d7d5b5348 100644 --- a/crawl-ref/source/ouch.cc +++ b/crawl-ref/source/ouch.cc @@ -859,7 +859,7 @@ void ouch( int dam, int death_source, kill_method_type death_type, // prevent bogus notes activate_notes(false); - // CONSTRUCT SCOREFILE ENTRY + // construct scorefile entry. scorefile_entry se(dam, death_source, death_type, aux); #ifdef SCORE_WIZARD_CHARACTERS diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index 815146bb95..6e002ca209 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -11,6 +11,7 @@ #include "chardump.h" #include "cio.h" #include "clua.h" +#include "command.h" #include "describe.h" #include "direct.h" #include "food.h" @@ -1360,8 +1361,7 @@ void StashTracker::show_stash_search_prompt() if (level_type_is_stash_trackable(you.level_type) && lastsearch != ".") { - opts.push_back( - make_stringf("press . for all items on level")); + opts.push_back("? for help"); } std::string prompt_qual = @@ -1373,13 +1373,54 @@ void StashTracker::show_stash_search_prompt() mprf(MSGCH_PROMPT, "Search for what%s?\n", prompt_qual.c_str()); } +class stash_search_reader : public line_reader +{ +public: + stash_search_reader(char *buf, size_t sz, + int wcol = get_number_of_cols()) + : line_reader(buf, sz, wcol) + { + } +protected: + int process_key(int ch) + { + if (ch == '?' && !pos) + { + *buffer = 0; + return (ch); + } + return line_reader::process_key(ch); + } +}; + void StashTracker::search_stashes() { - show_stash_search_prompt(); - char buf[400]; - bool validline = - !cancelable_get_line(buf, sizeof buf, 80, &search_history); + + stash_search_reader reader(buf, sizeof buf); + + bool validline = false; + while (true) + { + show_stash_search_prompt(); + + int ret = reader.read_line(); + if (!ret) + { + validline = true; + break; + } + else if (ret == '?') + { + show_stash_search_help(); + redraw_screen(); + } + else + { + break; + } + } + mesclr(); if (!validline || (!*buf && !lastsearch.length())) return; -- cgit v1.2.3-54-g00ecf