mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-01 00:00:14 +00:00
gui2/unit_create: Allow searching by race name as well
(cherry-picked from commit b7c7fca8b10003d7d6445710a51ed0f740e9425c)
This commit is contained in:
parent
7fe7047ba9
commit
dce867921c
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user