mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-24 02:13:02 -07:00
[Card] Add a setting for the language used in card search
Localized card names and texts can now be searched too, controlled by a 'Language used in card search' toggle (English, selected card language, or both) on the general settings page. Untranslated cards always keep matching in English. Removed the redundant local copy of the URL templates list in the localized picture loader while here.
This commit is contained in:
parent
1c93309952
commit
e029173e29
20 changed files with 360 additions and 52 deletions
|
|
@ -65,7 +65,13 @@ void CardSearchModel::updateSearchResults(const QString &query)
|
|||
continue;
|
||||
}
|
||||
|
||||
const QString lowerName = card->getName().toLower();
|
||||
// The completer suggestions match against the same languages the card
|
||||
// search uses, so typing a localized name finds the card.
|
||||
QString matchName = card->getName();
|
||||
if (searchLanguageMode != CardSearchLanguage::English && !searchLanguage.isEmpty() && searchLanguage != "en") {
|
||||
matchName = card->getLocalizedName(searchLanguage);
|
||||
}
|
||||
const QString lowerName = matchName.toLower();
|
||||
if (!lowerName.contains(lowerQuery)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -79,11 +85,17 @@ void CardSearchModel::updateSearchResults(const QString &query)
|
|||
}
|
||||
}
|
||||
|
||||
auto sortByDistanceThenLength = [](const SearchResult &a, const SearchResult &b) {
|
||||
auto sortByDistanceThenLength = [this](const SearchResult &a, const SearchResult &b) {
|
||||
QString nameA = a.card->getName();
|
||||
QString nameB = b.card->getName();
|
||||
if (searchLanguageMode != CardSearchLanguage::English && !searchLanguage.isEmpty() && searchLanguage != "en") {
|
||||
nameA = a.card->getLocalizedName(searchLanguage);
|
||||
nameB = b.card->getLocalizedName(searchLanguage);
|
||||
}
|
||||
if (a.distance != b.distance) {
|
||||
return a.distance < b.distance;
|
||||
}
|
||||
return a.card->getName().size() < b.card->getName().size();
|
||||
return nameA.size() < nameB.size();
|
||||
};
|
||||
|
||||
std::sort(prefixMatches.begin(), prefixMatches.end(), sortByDistanceThenLength);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue