gui/unit_recruit: Restructure filter criteria checks

This makes it easier to add any number of text criteria for filtering
without making the conditional increasingly unwieldy. Criteria that
shouldn't count because of conditions disabling them (such as the unit
type id only being considered when debug mode is eanbled) can just
become empty strings which will never match.
This commit is contained in:
Iris Morelle 2024-03-08 20:30:18 -03:00
parent 9f5e61b803
commit 3a8c234df7

View file

@ -79,13 +79,21 @@ void unit_recruit::filter_text_changed(const std::string& text)
const unit_type* type = recruit_list_[i];
if(!type) continue;
// List of possible match criteria for this unit type. Empty values will
// never match.
auto criteria = std::make_tuple(
(game_config::debug ? type->id() : ""),
type->type_name()
);
bool found = false;
for(const auto & word : words)
{
// Search for the name in the local language.
// In debug mode, also search for the type id.
found = (game_config::debug && translation::ci_search(type->id(), word)) ||
translation::ci_search(type->type_name(), word);
std::apply([&](auto&&... criterion) {
found = (translation::ci_search(criterion, word) || ...);
}, criteria);
if(!found) {
// one word doesn't match, we don't reach words.end()