mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-17 22:03:24 +00:00
Added progressive search functionality...
...(for label text and unit names). Algorithm performance proportional to map hexes.
This commit is contained in:
parent
b27bbbb6fc
commit
634d28c1f0
@ -2057,48 +2057,67 @@ void turn_info::show_statistics()
|
|||||||
|
|
||||||
void turn_info::search()
|
void turn_info::search()
|
||||||
{
|
{
|
||||||
create_textbox(floating_textbox::TEXTBOX_SEARCH,string_table["search_prompt"] + ":");
|
std::stringstream msg;
|
||||||
|
msg << string_table["search_prompt"];
|
||||||
|
if(last_search_hit_.valid()) {
|
||||||
|
msg << " [" << last_search_ << "]";
|
||||||
|
}
|
||||||
|
msg << ':';
|
||||||
|
create_textbox(floating_textbox::TEXTBOX_SEARCH,msg.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void turn_info::do_search(const std::string& new_search)
|
void turn_info::do_search(const std::string& new_search)
|
||||||
{
|
{
|
||||||
if(new_search == "") {
|
if(new_search.empty() == false && new_search != last_search_)
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(new_search.empty() == false)
|
|
||||||
last_search_ = new_search;
|
last_search_ = new_search;
|
||||||
|
|
||||||
if(last_search_.empty() == false) {
|
if(last_search_.empty() == false) {
|
||||||
//Search labels
|
//Scan the game map
|
||||||
const map_labels::label_map& labels = gui_.labels().labels();
|
gamemap::location loc = last_search_hit_;
|
||||||
for(map_labels::label_map::const_iterator i = labels.begin(); i != labels.end(); ++i) {
|
if(loc.valid() == false)
|
||||||
if(gui_.fogged(i->first.x,i->first.y)) continue;
|
loc = gamemap::location(map_.x()-1,map_.y()-1);
|
||||||
std::string label = gui_.labels().get_label(i->second);
|
gamemap::location start = loc;
|
||||||
if(std::search(label.begin(), label.end(),
|
bool found = false;
|
||||||
last_search_.begin(), last_search_.end(),
|
do {
|
||||||
chars_equal_insensitive) != label.end()) {
|
//Move to the next location
|
||||||
gui_.scroll_to_tile(i->first.x,i->first.y,display::WARP);
|
loc.x = (loc.x + 1) % map_.x();
|
||||||
gui_.highlight_hex(i->first);
|
if(loc.x == 0)
|
||||||
return;
|
loc.y = (loc.y + 1) % map_.y();
|
||||||
|
|
||||||
|
//Search label
|
||||||
|
const std::string label = gui_.labels().get_label(loc);
|
||||||
|
if(label.empty() == false) {
|
||||||
|
if(std::search(label.begin(), label.end(),
|
||||||
|
last_search_.begin(), last_search_.end(),
|
||||||
|
chars_equal_insensitive) != label.end()) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
//Search unit name
|
||||||
//Search unit names
|
unit_map::const_iterator ui = units_.find(loc);
|
||||||
for(unit_map::const_iterator u = units_.begin(); u != units_.end(); ++u) {
|
if(ui != units_.end()) {
|
||||||
if(gui_.fogged(u->first.x,u->first.y)) continue;
|
const std::string name = ui->second.description();
|
||||||
std::string name = u->second.description();
|
if(std::search(name.begin(), name.end(),
|
||||||
if(std::search(name.begin(), name.end(),
|
last_search_.begin(), last_search_.end(),
|
||||||
last_search_.begin(), last_search_.end(),
|
chars_equal_insensitive) != name.end()) {
|
||||||
chars_equal_insensitive) != name.end()) {
|
found = true;
|
||||||
gui_.scroll_to_tile(u->first.x,u->first.y,display::WARP);
|
}
|
||||||
gui_.highlight_hex(u->first);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} while (loc != start && !found);
|
||||||
|
|
||||||
|
if(found) {
|
||||||
|
last_search_hit_ = loc;
|
||||||
|
gui_.scroll_to_tile(loc.x,loc.y,display::WARP);
|
||||||
|
gui_.highlight_hex(loc);
|
||||||
|
} else {
|
||||||
|
last_search_hit_ = gamemap::location();
|
||||||
|
//Not found, inform the player
|
||||||
|
string_map symbols;
|
||||||
|
symbols["search"] = last_search_;
|
||||||
|
const std::string msg = config::interpolate_variables_into_string(
|
||||||
|
string_table["search_string_not_found"],&symbols);
|
||||||
|
gui::show_dialog(gui_,NULL,"",msg);
|
||||||
}
|
}
|
||||||
//Not found, inform the player
|
|
||||||
string_map symbols;
|
|
||||||
symbols["search"] = last_search_;
|
|
||||||
const std::string msg = config::interpolate_variables_into_string(string_table["search_string_not_found"],&symbols);
|
|
||||||
gui::show_dialog(gui_,NULL,"",msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,9 @@ private:
|
|||||||
int start_ncmd_;
|
int start_ncmd_;
|
||||||
|
|
||||||
std::string last_recruit_;
|
std::string last_recruit_;
|
||||||
|
|
||||||
std::string last_search_;
|
std::string last_search_;
|
||||||
|
gamemap::location last_search_hit_;
|
||||||
|
|
||||||
floating_textbox& textbox_;
|
floating_textbox& textbox_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user