Skip to content

Commit

Permalink
gui2/unit_create: Allow searching by race name as well
Browse files Browse the repository at this point in the history
(cherry-picked from commit b7c7fca)
  • Loading branch information
irydacea committed Oct 7, 2018
1 parent 7fe7047 commit dce8679
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions src/gui/dialogs/unit_create.cpp
Expand Up @@ -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();
Expand All @@ -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()
Expand Down

0 comments on commit dce8679

Please sign in to comment.