Commit 1a80d68f authored by nanahira's avatar nanahira

Merge branch 'regex'

parents b9203f46 3247e2ef
...@@ -1477,11 +1477,11 @@ void ClientField::UpdateDeclarableCodeType(bool enter) { ...@@ -1477,11 +1477,11 @@ void ClientField::UpdateDeclarableCodeType(bool enter) {
return; return;
} }
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) { for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
if(cit->second.name.find(pname) != std::wstring::npos) { if(cit->second.name.find(pname) != std::wstring::npos || mainGame->CheckRegEx(cit->second.name, pname)) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
//datas.alias can be double card names or alias //datas.alias can be double card names or alias
if(is_declarable(cp->second, declarable_type)) { if(is_declarable(cp->second, declarable_type)) {
if(pname == cit->second.name) { //exact match if(pname == cit->second.name || mainGame->CheckRegEx(cit->second.name, pname, true)) { //exact match
mainGame->lstANCard->insertItem(0, cit->second.name.c_str(), -1); mainGame->lstANCard->insertItem(0, cit->second.name.c_str(), -1);
ancard.insert(ancard.begin(), cit->first); ancard.insert(ancard.begin(), cit->first);
} else { } else {
...@@ -1524,11 +1524,11 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) { ...@@ -1524,11 +1524,11 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) {
return; return;
} }
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) { for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
if(cit->second.name.find(pname) != std::wstring::npos) { if(cit->second.name.find(pname) != std::wstring::npos || mainGame->CheckRegEx(cit->second.name, pname)) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
//datas.alias can be double card names or alias //datas.alias can be double card names or alias
if(is_declarable(cp->second, opcode)) { if(is_declarable(cp->second, opcode)) {
if(pname == cit->second.name) { //exact match if(pname == cit->second.name || mainGame->CheckRegEx(cit->second.name, pname, true)) { //exact match
mainGame->lstANCard->insertItem(0, cit->second.name.c_str(), -1); mainGame->lstANCard->insertItem(0, cit->second.name.c_str(), -1);
ancard.insert(ancard.begin(), cit->first); ancard.insert(ancard.begin(), cit->first);
} else { } else {
......
#include "data_manager.h" #include "data_manager.h"
#include "game.h"
#include <stdio.h> #include <stdio.h>
namespace ygo { namespace ygo {
...@@ -189,7 +190,7 @@ const wchar_t* DataManager::GetSetName(int code) { ...@@ -189,7 +190,7 @@ const wchar_t* DataManager::GetSetName(int code) {
unsigned int DataManager::GetSetCode(const wchar_t* setname) { unsigned int DataManager::GetSetCode(const wchar_t* setname) {
for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) { for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) {
auto xpos = csit->second.find_first_of(L'|');//setname|extra info auto xpos = csit->second.find_first_of(L'|');//setname|extra info
if(csit->second.compare(0, xpos, setname) == 0) if(csit->second.compare(0, xpos, setname) == 0 || mainGame->CheckRegEx(csit->second, setname, true))
return csit->first; return csit->first;
} }
return 0; return 0;
......
...@@ -944,6 +944,7 @@ void DeckBuilder::FilterCards() { ...@@ -944,6 +944,7 @@ void DeckBuilder::FilterCards() {
int trycode = BufferIO::GetVal(elements_iterator->c_str()); 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(), elements_iterator->c_str()) && text.text.find(elements_iterator->c_str()) == std::wstring::npos if(!tryresult && !CardNameContains(text.name.c_str(), elements_iterator->c_str()) && text.text.find(elements_iterator->c_str()) == std::wstring::npos
&& !mainGame->CheckRegEx(text.text, elements_iterator->c_str())
&& (!set_code_map[*elements_iterator] || !check_set_code(data, set_code_map[*elements_iterator]))) { && (!set_code_map[*elements_iterator] || !check_set_code(data, set_code_map[*elements_iterator]))) {
is_target = false; is_target = false;
break; break;
...@@ -1011,7 +1012,7 @@ void DeckBuilder::SortList() { ...@@ -1011,7 +1012,7 @@ void DeckBuilder::SortList() {
auto left = results.begin(); auto left = results.begin();
const wchar_t* pstr = mainGame->ebCardName->getText(); const wchar_t* pstr = mainGame->ebCardName->getText();
for(auto it = results.begin(); it != results.end(); ++it) { for(auto it = results.begin(); it != results.end(); ++it) {
if(wcscmp(pstr, dataManager.GetName((*it)->first)) == 0) { if(wcscmp(pstr, dataManager.GetName((*it)->first)) == 0 || mainGame->CheckRegEx(dataManager.GetName((*it)->first), pstr, true)) {
std::iter_swap(left, it); std::iter_swap(left, it);
++left; ++left;
} }
...@@ -1059,6 +1060,8 @@ bool DeckBuilder::CardNameContains(const wchar_t *haystack, const wchar_t *needl ...@@ -1059,6 +1060,8 @@ bool DeckBuilder::CardNameContains(const wchar_t *haystack, const wchar_t *needl
if (!haystack) { if (!haystack) {
return false; return false;
} }
if(mainGame->CheckRegEx(haystack, needle))
return true;
int i = 0; int i = 0;
int j = 0; int j = 0;
while (haystack[i]) { while (haystack[i]) {
......
...@@ -1858,6 +1858,13 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -1858,6 +1858,13 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true; return true;
break; break;
} }
case CHECKBOX_REGEX: {
mainGame->gameConf.search_regex = mainGame->chkRegex->isChecked() ? 1 : 0;
if(mainGame->is_building && !mainGame->is_siding)
mainGame->deckBuilder.InstantSearch();
return true;
break;
}
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
case CHECKBOX_ENABLE_MUSIC: { case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked()) if(!mainGame->chkEnableMusic->isChecked())
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "netserver.h" #include "netserver.h"
#include "single_mode.h" #include "single_mode.h"
#include <sstream> #include <sstream>
#include <regex>
unsigned short PRO_VERSION = 0x1346; unsigned short PRO_VERSION = 0x1346;
...@@ -343,6 +344,9 @@ bool Game::Initialize() { ...@@ -343,6 +344,9 @@ bool Game::Initialize() {
chkMultiKeywords = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_MULTI_KEYWORDS, dataManager.GetSysString(1377)); chkMultiKeywords = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_MULTI_KEYWORDS, dataManager.GetSysString(1377));
chkMultiKeywords->setChecked(gameConf.search_multiple_keywords > 0); chkMultiKeywords->setChecked(gameConf.search_multiple_keywords > 0);
posY += 30; posY += 30;
chkRegex = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_REGEX, dataManager.GetSysString(1378));
chkRegex->setChecked(gameConf.search_regex > 0);
posY += 30;
env->addStaticText(dataManager.GetSysString(1282), rect<s32>(posX + 23, posY + 3, posX + 120, posY + 28), false, false, tabSystem); env->addStaticText(dataManager.GetSysString(1282), rect<s32>(posX + 23, posY + 3, posX + 120, posY + 28), false, false, tabSystem);
btnWinResizeS = env->addButton(rect<s32>(posX + 115, posY, posX + 145, posY + 25), tabSystem, BUTTON_WINDOW_RESIZE_S, dataManager.GetSysString(1283)); btnWinResizeS = env->addButton(rect<s32>(posX + 115, posY, posX + 145, posY + 25), tabSystem, BUTTON_WINDOW_RESIZE_S, dataManager.GetSysString(1283));
btnWinResizeM = env->addButton(rect<s32>(posX + 150, posY, posX + 180, posY + 25), tabSystem, BUTTON_WINDOW_RESIZE_M, dataManager.GetSysString(1284)); btnWinResizeM = env->addButton(rect<s32>(posX + 150, posY, posX + 180, posY + 25), tabSystem, BUTTON_WINDOW_RESIZE_M, dataManager.GetSysString(1284));
...@@ -1125,6 +1129,7 @@ void Game::LoadConfig() { ...@@ -1125,6 +1129,7 @@ void Game::LoadConfig() {
gameConf.separate_clear_button = 1; gameConf.separate_clear_button = 1;
gameConf.auto_search_limit = 0; gameConf.auto_search_limit = 0;
gameConf.search_multiple_keywords = 1; gameConf.search_multiple_keywords = 1;
gameConf.search_regex = 0;
gameConf.chkIgnoreDeckChanges = 0; gameConf.chkIgnoreDeckChanges = 0;
gameConf.defaultOT = 1; gameConf.defaultOT = 1;
gameConf.enable_bot_mode = 1; gameConf.enable_bot_mode = 1;
...@@ -1202,6 +1207,8 @@ void Game::LoadConfig() { ...@@ -1202,6 +1207,8 @@ void Game::LoadConfig() {
gameConf.auto_search_limit = atoi(valbuf); gameConf.auto_search_limit = atoi(valbuf);
} else if(!strcmp(strbuf, "search_multiple_keywords")) { } else if(!strcmp(strbuf, "search_multiple_keywords")) {
gameConf.search_multiple_keywords = atoi(valbuf); gameConf.search_multiple_keywords = atoi(valbuf);
} else if(!strcmp(strbuf, "search_regex")) {
gameConf.search_regex = 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")) {
...@@ -1318,6 +1325,8 @@ void Game::LoadConfig() { ...@@ -1318,6 +1325,8 @@ void Game::LoadConfig() {
gameConf.auto_search_limit = atoi(valbuf); gameConf.auto_search_limit = atoi(valbuf);
} else if(!strcmp(strbuf, "search_multiple_keywords")) { } else if(!strcmp(strbuf, "search_multiple_keywords")) {
gameConf.search_multiple_keywords = atoi(valbuf); gameConf.search_multiple_keywords = atoi(valbuf);
} else if(!strcmp(strbuf, "search_regex")) {
gameConf.search_regex = 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")) {
...@@ -1448,6 +1457,7 @@ void Game::SaveConfig() { ...@@ -1448,6 +1457,7 @@ void Game::SaveConfig() {
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 = 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, "search_multiple_keywords = %d\n", gameConf.search_multiple_keywords);
fprintf(fp, "search_regex = %d\n", gameConf.search_regex);
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);
...@@ -2078,6 +2088,34 @@ void Game::takeScreenshot() { ...@@ -2078,6 +2088,34 @@ void Game::takeScreenshot() {
} else } else
device->getLogger()->log(L"Failed to take screenshot.", irr::ELL_WARNING); device->getLogger()->log(L"Failed to take screenshot.", irr::ELL_WARNING);
} }
bool Game::CheckRegEx(const wchar_t* text, const wchar_t* exp, bool exact) {
if(!gameConf.search_regex)
return false;
bool result;
try {
if(exact)
result = std::regex_match(text, std::wregex(exp));
else
result = std::regex_search(text, std::wregex(exp));
} catch(...) {
result = false;
}
return result;
}
bool Game::CheckRegEx(std::wstring text, const wchar_t* exp, bool exact) {
if(!gameConf.search_regex)
return false;
bool result;
try {
if(exact)
result = std::regex_match(text, std::wregex(exp));
else
result = std::regex_search(text, std::wregex(exp));
} catch(...) {
result = false;
}
return result;
}
const char* Game::GetLocaleDir(const char* dir) { const char* Game::GetLocaleDir(const char* dir) {
if(!gameConf.locale || !wcscmp(gameConf.locale, L"default")) if(!gameConf.locale || !wcscmp(gameConf.locale, L"default"))
return dir; return dir;
......
...@@ -42,6 +42,7 @@ struct Config { ...@@ -42,6 +42,7 @@ struct Config {
int separate_clear_button; int separate_clear_button;
int auto_search_limit; int auto_search_limit;
int search_multiple_keywords; int search_multiple_keywords;
int search_regex;
int chkIgnoreDeckChanges; int chkIgnoreDeckChanges;
int defaultOT; int defaultOT;
int enable_bot_mode; int enable_bot_mode;
...@@ -170,6 +171,8 @@ public: ...@@ -170,6 +171,8 @@ public:
int LocalPlayer(int player); int LocalPlayer(int player);
const wchar_t* LocalName(int local_player); const wchar_t* LocalName(int local_player);
const char* GetLocaleDir(const char* dir); const char* GetLocaleDir(const char* dir);
bool CheckRegEx(const wchar_t* text, const wchar_t* exp, bool exact = false);
bool CheckRegEx(std::wstring text, const wchar_t* exp, bool exact = false);
bool HasFocus(EGUI_ELEMENT_TYPE type) const { bool HasFocus(EGUI_ELEMENT_TYPE type) const {
irr::gui::IGUIElement* focus = env->getFocus(); irr::gui::IGUIElement* focus = env->getFocus();
...@@ -307,6 +310,7 @@ public: ...@@ -307,6 +310,7 @@ public:
irr::gui::IGUICheckBox* chkIgnoreDeckChanges; irr::gui::IGUICheckBox* chkIgnoreDeckChanges;
irr::gui::IGUICheckBox* chkAutoSearch; irr::gui::IGUICheckBox* chkAutoSearch;
irr::gui::IGUICheckBox* chkMultiKeywords; irr::gui::IGUICheckBox* chkMultiKeywords;
irr::gui::IGUICheckBox* chkRegex;
irr::gui::IGUICheckBox* chkEnableSound; irr::gui::IGUICheckBox* chkEnableSound;
irr::gui::IGUICheckBox* chkEnableMusic; irr::gui::IGUICheckBox* chkEnableMusic;
irr::gui::IGUIScrollBar* scrSoundVolume; irr::gui::IGUIScrollBar* scrSoundVolume;
...@@ -719,6 +723,7 @@ extern Game* mainGame; ...@@ -719,6 +723,7 @@ extern Game* mainGame;
#define SCROLL_TAB_SYSTEM 351 #define SCROLL_TAB_SYSTEM 351
#define CHECKBOX_AUTO_SEARCH 360 #define CHECKBOX_AUTO_SEARCH 360
#define CHECKBOX_MULTI_KEYWORDS 372 #define CHECKBOX_MULTI_KEYWORDS 372
#define CHECKBOX_REGEX 373
#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
......
...@@ -407,6 +407,7 @@ ...@@ -407,6 +407,7 @@
!system 1375 自动保存录像 !system 1375 自动保存录像
!system 1376 录像已自动保存为%ls.yrp !system 1376 录像已自动保存为%ls.yrp
!system 1377 使用多个关键词搜索卡片 !system 1377 使用多个关键词搜索卡片
!system 1378 使用正则表达式搜索卡片
!system 1380 人机模式 !system 1380 人机模式
!system 1381 残局模式 !system 1381 残局模式
!system 1382 人机信息: !system 1382 人机信息:
......
...@@ -30,9 +30,12 @@ separate_clear_button = 1 ...@@ -30,9 +30,12 @@ separate_clear_button = 1
auto_search_limit = 2 auto_search_limit = 2
#search_multiple_keywords = 0: Disable. 1: Search mutiple keywords with separator " ". 2: with separator "+" #search_multiple_keywords = 0: Disable. 1: Search mutiple keywords with separator " ". 2: with separator "+"
search_multiple_keywords = 1 search_multiple_keywords = 1
search_regex = 0
ignore_deck_changes = 0 ignore_deck_changes = 0
default_ot = 1 default_ot = 1
enable_bot_mode = 1 enable_bot_mode = 1
quick_animation = 1
auto_save_replay = 1
window_maximized = 0 window_maximized = 0
window_width = 1024 window_width = 1024
window_height = 640 window_height = 640
......
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