Skip to content

Commit

Permalink
Revert highlighting of matched text.
Browse files Browse the repository at this point in the history
Not removing the underlying infrastrucutre, since I want to bring it back
on the description menu (soon).
  • Loading branch information
wheals committed Jan 14, 2016
1 parent 45e9a13 commit 9a212da
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 85 deletions.
6 changes: 1 addition & 5 deletions crawl-ref/docs/options_guide.txt
Expand Up @@ -61,7 +61,7 @@ The contents of this text are:
automagic_enable, automagic_slot, automagic_fight,
automagic_stop, fail_severity_to_confirm, easy_door,
warn_hatches, enable_recast_spell, confirm_action,
regex_search, search_highlight_colour
regex_search
3-h Message and Display Improvements.
hp_warning, mp_warning, hp_colour, mp_colour, stat_colour,
status_caption_colour, enemy_hp_colour, clear_messages,
Expand Down Expand Up @@ -1306,10 +1306,6 @@ regex_search = false
expression search and queries prefixed with = will be performed as a
substring search.

search_highlight_colour = lightcyan
The colour to use to highlight the matched portion of the item name
with when searching with ^F.

3-h Messages and Display Enhancements.
------------------------------------------

Expand Down
2 changes: 0 additions & 2 deletions crawl-ref/source/initfile.cc
Expand Up @@ -928,7 +928,6 @@ void game_options::reset_options()
pizzas.clear();

regex_search = false;
search_highlight_colour = LIGHTCYAN;

#ifdef WIZARD
fsim_rounds = 4000L;
Expand Down Expand Up @@ -2869,7 +2868,6 @@ void game_options::read_option_line(const string &str, bool runscript)
[](string p) { return !trimmed_string(p).empty(); });
}
else BOOL_OPTION(regex_search);
else COLOUR_OPTION(search_highlight_colour);
#if !defined(DGAMELAUNCH) || defined(DGL_REMEMBER_NAME)
else BOOL_OPTION(remember_name);
#endif
Expand Down
5 changes: 1 addition & 4 deletions crawl-ref/source/options.h
Expand Up @@ -414,10 +414,7 @@ struct game_options
int rest_wait_percent; // Stop resting after restoring this
// fraction of HP or MP

bool regex_search; // whether to default to regex search
// for ^F
int search_highlight_colour; // colour to use when highlighting
// search results
bool regex_search; // whether to default to regex search for ^F

lang_t language; // Translation to use.
const char* lang_name; // Database name of the language.
Expand Down
5 changes: 0 additions & 5 deletions crawl-ref/source/pattern.h
Expand Up @@ -26,11 +26,6 @@ class pattern_match
return text;
}

void nohl()
{
start = end = (matched ? 0 : -1);
}

private:

pattern_match(bool _matched, const string &_text, int _start, int _end)
Expand Down
88 changes: 24 additions & 64 deletions crawl-ref/source/stash.cc
Expand Up @@ -15,7 +15,6 @@
#include "chardump.h"
#include "clua.h"
#include "cluautil.h"
#include "colour.h"
#include "command.h"
#include "coordit.h"
#include "describe.h"
Expand Down Expand Up @@ -459,15 +458,11 @@ vector<stash_search_result> Stash::matches_search(
{
const string s = stash_item_name(item);
const string ann = stash_annotate_item(STASH_LUA_SEARCH_ANNOTATE, &item);
pattern_match match(search.match_location(s));
if (!match)
match = search.match_location(s + " " + prefix + " " + ann);
if (!match && is_dumpable_artefact(item))
match = search.match_location(s + " " + chardump_desc(item));
if (match)
if (search.matches(prefix + " " + ann + " " + s)
|| is_dumpable_artefact(item) && search.matches(chardump_desc(item)))
{
stash_search_result res;
res.match = match;
res.match = s;
res.item = item;
results.push_back(res);
}
Expand All @@ -476,15 +471,11 @@ vector<stash_search_result> Stash::matches_search(
if (results.empty() && feat != DNGN_FLOOR)
{
const string fdesc = feature_description();
if (!fdesc.empty())
if (!fdesc.empty() && search.matches(fdesc))
{
pattern_match feat_match(search.match_location(fdesc));
if (feat_match)
{
stash_search_result res;
res.match = feat_match;
results.push_back(res);
}
stash_search_result res;
res.match = fdesc;
results.push_back(res);
}
}

Expand Down Expand Up @@ -699,18 +690,11 @@ vector<stash_search_result> ShopInfo::matches_search(

no_notes nx;

string shoptitle = shop_name(shop);
if (shop.stock.empty())
shoptitle += "*";
shoptitle += " " + prefix + " {shop}";

pattern_match shoptitle_match(search.match_location(shop_name(shop)));
if (!shoptitle_match)
shoptitle_match = search.match_location(shoptitle);
if (shoptitle_match)
const string shoptitle = shop_name(shop) + (shop.stock.empty() ? "*" : "");
if (search.matches(shoptitle + " " + prefix + " {shop}"))
{
stash_search_result res;
res.match = shoptitle_match;
res.match = shoptitle;
res.shop = this;
res.pos.pos = shop.pos;
results.push_back(res);
Expand All @@ -724,18 +708,12 @@ vector<stash_search_result> ShopInfo::matches_search(
const string ann = stash_annotate_item(STASH_LUA_SEARCH_ANNOTATE,
&item, true);

pattern_match itemname_match(search.match_location(sname));
if (!itemname_match)
itemname_match = search.match_location(sname + " " + prefix + " " + ann);
if (!itemname_match)
itemname_match = search.match_location(sname + " " + shop_item_desc(item));
if (itemname_match)
if (search.matches(prefix + " " + ann + " " + sname)
|| search.matches(shop_item_desc(item)))
{
stash_search_result res;
res.match = itemname_match;
res.item = item;
res.shop = this;
res.pos.pos = shop.pos;
res.match = sname;
res.item = item.item;
results.push_back(res);
}
}
Expand Down Expand Up @@ -1264,10 +1242,10 @@ static bool _compare_by_distance(const stash_search_result& lhs,
return lhs_dist < rhs_dist;
}

if (lhs.match.matched_text() != rhs.match.matched_text())
if (lhs.match != rhs.match)
{
// Then by name.
return lhs.match.matched_text() < rhs.match.matched_text();
return lhs.match < rhs.match;
}
else
return false;
Expand All @@ -1277,10 +1255,10 @@ static bool _compare_by_distance(const stash_search_result& lhs,
static bool _compare_by_name(const stash_search_result& lhs,
const stash_search_result& rhs)
{
if (lhs.match.matched_text() != rhs.match.matched_text())
if (lhs.match != rhs.match)
{
// Sort by name
return lhs.match.matched_text() < rhs.match.matched_text();
return lhs.match < rhs.match;
}
else if (lhs.player_distance != rhs.player_distance)
{
Expand All @@ -1301,15 +1279,12 @@ static vector<stash_search_result> _inventory_search(const base_pattern &search)

const string s = Stash::stash_item_name(item);
const string ann = stash_annotate_item(STASH_LUA_SEARCH_ANNOTATE, &item);
pattern_match itemname_match(search.match_location(s));
if (!itemname_match)
itemname_match = search.match_location(s + " " + ann);
if (!itemname_match && is_dumpable_artefact(item))
itemname_match = search.match_location(s + " " + chardump_desc(item));
if (itemname_match)
if (search.matches(ann + " " + s)
|| is_dumpable_artefact(item)
&& search.matches(chardump_desc(item)))
{
stash_search_result res;
res.match = itemname_match;
res.match = s;
res.item = item;
// Needs to not be equal to ITEM_IN_INVENTORY so the describe
// menu doesn't think it can manipulate the item.
Expand Down Expand Up @@ -1363,7 +1338,6 @@ void StashTracker::search_stashes()
string csearch = csearch_literal;

bool curr_lev = (csearch[0] == '@' || csearch == ".");
bool nohl = false;
if (curr_lev)
{
csearch.erase(0, 1);
Expand All @@ -1385,8 +1359,6 @@ void StashTracker::search_stashes()
{
if (csearch[0] == '/')
csearch.erase(0, 1);
if (csearch == "." || csearch == "..")
nohl = true;
tpat = csearch;
search = &tpat;
}
Expand Down Expand Up @@ -1423,10 +1395,6 @@ void StashTracker::search_stashes()
return;
}

if (nohl)
for (auto &res : results)
res.match.nohl();

bool sort_by_dist = true;
bool filter_useless = false;
bool default_execute = true;
Expand Down Expand Up @@ -1603,17 +1571,9 @@ bool StashTracker::display_search_results(
}

if (!res.in_inventory)
matchtitle << "[" << res.pos.id.describe() << "] ";

string item_desc = res.match.annotate_string(colour_to_str(Options.search_highlight_colour));
item_desc = replace_all(item_desc, "\n", " ");
// not replace_all because that would collapse " " to " "
// rather than " "
size_t pos;
while ((pos = item_desc.find(" ")) != string::npos)
item_desc.erase(pos, 1);
matchtitle << "[" << res.pos.id.describe() << "]";

matchtitle << item_desc;
matchtitle << " " << res.match;

MenuEntry *me = new MenuEntry(matchtitle.str(), MEL_ITEM, 1, hotkey);
me->data = &res;
Expand Down
9 changes: 4 additions & 5 deletions crawl-ref/source/stash.h
Expand Up @@ -120,9 +120,9 @@ struct stash_search_result
// is on.
int player_distance;

// Match for this search result - usually the first matching item in the
// stash or the name of the shop.
pattern_match match;
// Text that describes this search result - usually the name of
// the first matching item in the stash or the name of the shop.
string match;

// Item that was matched.
item_def item;
Expand All @@ -133,8 +133,7 @@ struct stash_search_result
// Whether the found items are in the player's inventory.
bool in_inventory;

stash_search_result() : pos(), player_distance(0),
match(pattern_match::failed()), item(),
stash_search_result() : pos(), player_distance(0), match(), item(),
shop(nullptr), in_inventory(false)
{
}
Expand Down

0 comments on commit 9a212da

Please sign in to comment.