gui2/unit_create: Allow searching by race name as well

(cherry-picked from commit b7c7fca8b1)
This commit is contained in:
Iris Morelle 2018-09-01 18:47:50 -03:00
parent 7fe7047ba9
commit dce867921c
2 changed files with 17 additions and 6 deletions

View file

@ -65,6 +65,7 @@
* Fixed the debug mode Create Unit dialog crashing when changing the gender
of the previous selection after causing the list to come up empty using
the filter box.
* Allow searching by race with the Create Unit filter box as well.
## Version 1.14.4
### Security Fixes

View file

@ -205,6 +205,18 @@ void unit_create::list_item_clicked(window& window)
});
}
namespace
{
bool ci_search(const std::string& a, const std::string& b)
{
return std::search(a.begin(), a.end(),
b.begin(), b.end(),
chars_equal_insensitive) != a.end();
}
} // end unnamed namespace
void unit_create::filter_text_changed(text_box_base* textbox, const std::string& text)
{
window& window = *textbox->get_window();
@ -227,16 +239,14 @@ void unit_create::filter_text_changed(text_box_base* textbox, const std::string&
grid::iterator it = row->begin();
label& type_label
= find_widget<label>(*it, "unit_type", false);
label& race_label
= find_widget<label>(*it, "race", false);
bool found = false;
for(const auto & word : words)
{
found = std::search(type_label.get_label().str().begin(),
type_label.get_label().str().end(),
word.begin(),
word.end(),
chars_equal_insensitive)
!= type_label.get_label().str().end();
found = ci_search(type_label.get_label().str(), word) ||
ci_search(race_label.get_label().str(), word);
if(!found) {
// one word doesn't match, we don't reach words.end()