Commit b565e865 authored by nanahira's avatar nanahira Committed by mercury233

search cards with multiple keywords (#2100)

parent 8e4194c5
...@@ -776,6 +776,34 @@ void DeckBuilder::StartFilter() { ...@@ -776,6 +776,34 @@ void DeckBuilder::StartFilter() {
void DeckBuilder::FilterCards() { void DeckBuilder::FilterCards() {
results.clear(); results.clear();
const wchar_t* pstr = mainGame->ebCardName->getText(); const wchar_t* pstr = mainGame->ebCardName->getText();
std::wstring str = std::wstring(pstr);
std::vector<std::wstring> query_elements;
std::vector<std::vector<std::wstring>::iterator> query_elements_track;
size_t element_start = 0;
while(mainGame->gameConf.search_multiple_keywords) {
size_t element_end = str.find_first_of(mainGame->gameConf.search_multiple_keywords == 1 ? L' ' : L'+', element_start);
if(element_end == std::wstring::npos)
break;
size_t length = element_end - element_start;
if(length > 0) {
query_elements.push_back(str.substr(element_start, length));
element_start = element_end + 1;
} else
element_start++;
}
query_elements.push_back(str.substr(element_start));
std::unordered_map<std::wstring, unsigned int> set_code_map;
for(auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); elements_iterator++) {
const wchar_t* element_pointer = elements_iterator->c_str();
if(element_pointer[0] == L'@')
set_code_map[*elements_iterator] = dataManager.GetSetCode(&element_pointer[1]);
else
set_code_map[*elements_iterator] = dataManager.GetSetCode(&element_pointer[0]);
if(element_pointer[0] == 0 || (element_pointer[0] == L'$' && element_pointer[1] == 0) || (element_pointer[0] == L'@' && element_pointer[1] == 0))
query_elements_track.push_back(elements_iterator);
}
for(auto elements_track_iterator = query_elements_track.begin(); elements_track_iterator != query_elements_track.end(); elements_track_iterator++)
query_elements.erase(*elements_track_iterator);
unsigned int set_code = 0; unsigned int set_code = 0;
if(pstr[0] == L'@') if(pstr[0] == L'@')
set_code = dataManager.GetSetCode(&pstr[1]); set_code = dataManager.GetSetCode(&pstr[1]);
...@@ -856,24 +884,39 @@ void DeckBuilder::FilterCards() { ...@@ -856,24 +884,39 @@ void DeckBuilder::FilterCards() {
if(filter_lm == 7 && data.ot != 4) if(filter_lm == 7 && data.ot != 4)
continue; continue;
} }
if(pstr) { bool is_target = true;
if(pstr[0] == L'$') { for (auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); elements_iterator++) {
if(!CardNameContains(text.name.c_str(), &pstr[1])) const wchar_t* element_pointer = elements_iterator->c_str();
continue; if (element_pointer[0] == L'$') {
} else if(pstr[0] == L'@' && set_code) { if(!CardNameContains(text.name.c_str(), &element_pointer[1])){
if(!check_set_code(data, set_code)) continue; is_target = false;
break;
}
}
else if (element_pointer[0] == L'@' && set_code_map[*elements_iterator]) {
if(!check_set_code(data, set_code_map[*elements_iterator])) {
is_target = false;
break;
}
} else { } else {
int trycode = BufferIO::GetVal(pstr); int trycode = BufferIO::GetVal(elements_iterator->c_str());
bool tryresult = dataManager.GetData(trycode, 0); bool tryresult = dataManager.GetData(trycode, 0);
if(!tryresult && !CardNameContains(text.name.c_str(), pstr) && text.text.find(pstr) == std::wstring::npos if(!tryresult && !CardNameContains(text.name.c_str(), elements_iterator->c_str()) && text.text.find(elements_iterator->c_str()) == std::wstring::npos
&& (!set_code || !check_set_code(data, set_code))) && (!set_code_map[*elements_iterator] || !check_set_code(data, set_code_map[*elements_iterator]))) {
continue; is_target = false;
if (tryresult && data.code != trycode break;
&& !(data.alias == trycode && (data.alias - data.code < CARD_ARTWORK_VERSIONS_OFFSET || data.code - data.alias < CARD_ARTWORK_VERSIONS_OFFSET))) }
continue; if(tryresult && data.code != trycode
&& !(data.alias == trycode && (data.alias - data.code < CARD_ARTWORK_VERSIONS_OFFSET || data.code - data.alias < CARD_ARTWORK_VERSIONS_OFFSET))) {
is_target = false;
break;
}
} }
} }
results.push_back(ptr); if(is_target)
results.push_back(ptr);
else
continue;
} }
myswprintf(result_string, L"%d", results.size()); myswprintf(result_string, L"%d", results.size());
if(results.size() > 7) { if(results.size() > 7) {
......
...@@ -1797,6 +1797,15 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -1797,6 +1797,15 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
switch(id) { switch(id) {
case CHECKBOX_AUTO_SEARCH: { case CHECKBOX_AUTO_SEARCH: {
mainGame->gameConf.auto_search_limit = mainGame->chkAutoSearch->isChecked() ? 0 : -1; mainGame->gameConf.auto_search_limit = mainGame->chkAutoSearch->isChecked() ? 0 : -1;
if(mainGame->is_building && !mainGame->is_siding)
mainGame->deckBuilder.InstantSearch();
return true;
break;
}
case CHECKBOX_MULTI_KEYWORDS: {
mainGame->gameConf.search_multiple_keywords = mainGame->chkMultiKeywords->isChecked() ? 1 : 0;
if(mainGame->is_building && !mainGame->is_siding)
mainGame->deckBuilder.InstantSearch();
return true; return true;
break; break;
} }
......
...@@ -297,6 +297,9 @@ bool Game::Initialize() { ...@@ -297,6 +297,9 @@ bool Game::Initialize() {
chkAutoSearch = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_AUTO_SEARCH, dataManager.GetSysString(1358)); chkAutoSearch = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_AUTO_SEARCH, dataManager.GetSysString(1358));
chkAutoSearch->setChecked(gameConf.auto_search_limit >= 0); chkAutoSearch->setChecked(gameConf.auto_search_limit >= 0);
posY += 30; posY += 30;
chkMultiKeywords = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_MULTI_KEYWORDS, dataManager.GetSysString(1378));
chkMultiKeywords->setChecked(gameConf.search_multiple_keywords > 0);
posY += 30;
chkEnableSound = env->addCheckBox(gameConf.enable_sound, rect<s32>(posX, posY, posX + 120, posY + 25), tabSystem, -1, dataManager.GetSysString(1279)); chkEnableSound = env->addCheckBox(gameConf.enable_sound, rect<s32>(posX, posY, posX + 120, posY + 25), tabSystem, -1, dataManager.GetSysString(1279));
chkEnableSound->setChecked(gameConf.enable_sound); chkEnableSound->setChecked(gameConf.enable_sound);
scrSoundVolume = env->addScrollBar(true, rect<s32>(posX + 126, posY + 4, posX + 260, posY + 21), tabSystem, SCROLL_VOLUME); scrSoundVolume = env->addScrollBar(true, rect<s32>(posX + 126, posY + 4, posX + 260, posY + 21), tabSystem, SCROLL_VOLUME);
...@@ -978,6 +981,7 @@ void Game::LoadConfig() { ...@@ -978,6 +981,7 @@ void Game::LoadConfig() {
gameConf.draw_field_spell = 1; gameConf.draw_field_spell = 1;
gameConf.separate_clear_button = 1; gameConf.separate_clear_button = 1;
gameConf.auto_search_limit = -1; gameConf.auto_search_limit = -1;
gameConf.search_multiple_keywords = 1;
gameConf.chkIgnoreDeckChanges = 0; gameConf.chkIgnoreDeckChanges = 0;
gameConf.defaultOT = 1; gameConf.defaultOT = 1;
gameConf.enable_bot_mode = 0; gameConf.enable_bot_mode = 0;
...@@ -1044,6 +1048,8 @@ void Game::LoadConfig() { ...@@ -1044,6 +1048,8 @@ void Game::LoadConfig() {
gameConf.separate_clear_button = atoi(valbuf); gameConf.separate_clear_button = atoi(valbuf);
} else if(!strcmp(strbuf, "auto_search_limit")) { } else if(!strcmp(strbuf, "auto_search_limit")) {
gameConf.auto_search_limit = atoi(valbuf); gameConf.auto_search_limit = atoi(valbuf);
} else if(!strcmp(strbuf, "search_multiple_keywords")) {
gameConf.search_multiple_keywords = atoi(valbuf);
} else if(!strcmp(strbuf, "ignore_deck_changes")) { } else if(!strcmp(strbuf, "ignore_deck_changes")) {
gameConf.chkIgnoreDeckChanges = atoi(valbuf); gameConf.chkIgnoreDeckChanges = atoi(valbuf);
} else if(!strcmp(strbuf, "default_ot")) { } else if(!strcmp(strbuf, "default_ot")) {
...@@ -1123,6 +1129,8 @@ void Game::SaveConfig() { ...@@ -1123,6 +1129,8 @@ void Game::SaveConfig() {
fprintf(fp, "separate_clear_button = %d\n", gameConf.separate_clear_button); fprintf(fp, "separate_clear_button = %d\n", gameConf.separate_clear_button);
fprintf(fp, "#auto_search_limit >= 0: Start search automatically when the user enters N chars\n"); fprintf(fp, "#auto_search_limit >= 0: Start search automatically when the user enters N chars\n");
fprintf(fp, "auto_search_limit = %d\n", gameConf.auto_search_limit); fprintf(fp, "auto_search_limit = %d\n", gameConf.auto_search_limit);
fprintf(fp, "#search_multiple_keywords = 0: Disable. 1: Search mutiple keywords with separator \" \". 2: with separator \"+\"\n");
fprintf(fp, "search_multiple_keywords = %d\n", gameConf.search_multiple_keywords);
fprintf(fp, "ignore_deck_changes = %d\n", (chkIgnoreDeckChanges->isChecked() ? 1 : 0)); fprintf(fp, "ignore_deck_changes = %d\n", (chkIgnoreDeckChanges->isChecked() ? 1 : 0));
fprintf(fp, "default_ot = %d\n", gameConf.defaultOT); fprintf(fp, "default_ot = %d\n", gameConf.defaultOT);
fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode); fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode);
......
...@@ -39,6 +39,7 @@ struct Config { ...@@ -39,6 +39,7 @@ struct Config {
int draw_field_spell; int draw_field_spell;
int separate_clear_button; int separate_clear_button;
int auto_search_limit; int auto_search_limit;
int search_multiple_keywords;
int chkIgnoreDeckChanges; int chkIgnoreDeckChanges;
int defaultOT; int defaultOT;
int enable_bot_mode; int enable_bot_mode;
...@@ -248,6 +249,7 @@ public: ...@@ -248,6 +249,7 @@ public:
irr::gui::IGUICheckBox* chkHideHintButton; irr::gui::IGUICheckBox* chkHideHintButton;
irr::gui::IGUICheckBox* chkIgnoreDeckChanges; irr::gui::IGUICheckBox* chkIgnoreDeckChanges;
irr::gui::IGUICheckBox* chkAutoSearch; irr::gui::IGUICheckBox* chkAutoSearch;
irr::gui::IGUICheckBox* chkMultiKeywords;
irr::gui::IGUICheckBox* chkEnableSound; irr::gui::IGUICheckBox* chkEnableSound;
irr::gui::IGUICheckBox* chkEnableMusic; irr::gui::IGUICheckBox* chkEnableMusic;
irr::gui::IGUIScrollBar* scrSoundVolume; irr::gui::IGUIScrollBar* scrSoundVolume;
...@@ -625,6 +627,7 @@ extern Game* mainGame; ...@@ -625,6 +627,7 @@ extern Game* mainGame;
#define BUTTON_LOAD_SINGLEPLAY 351 #define BUTTON_LOAD_SINGLEPLAY 351
#define BUTTON_CANCEL_SINGLEPLAY 352 #define BUTTON_CANCEL_SINGLEPLAY 352
#define CHECKBOX_AUTO_SEARCH 360 #define CHECKBOX_AUTO_SEARCH 360
#define CHECKBOX_MULTI_KEYWORDS 372
#define CHECKBOX_ENABLE_SOUND 361 #define CHECKBOX_ENABLE_SOUND 361
#define CHECKBOX_ENABLE_MUSIC 362 #define CHECKBOX_ENABLE_MUSIC 362
#define SCROLL_VOLUME 363 #define SCROLL_VOLUME 363
......
...@@ -400,6 +400,7 @@ ...@@ -400,6 +400,7 @@
!system 1372 守备↑ !system 1372 守备↑
!system 1373 名称↓ !system 1373 名称↓
!system 1374 连接标记 !system 1374 连接标记
!system 1378 使用多个关键词搜索卡片
!system 1380 人机模式 !system 1380 人机模式
!system 1381 残局模式 !system 1381 残局模式
!system 1382 人机信息: !system 1382 人机信息:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment