Commit 5ff31121 authored by nanahira's avatar nanahira

regex

parent b565e865
......@@ -1444,11 +1444,11 @@ void ClientField::UpdateDeclarableCodeType(bool enter) {
mainGame->lstANCard->clear();
ancard.clear();
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
//datas.alias can be double card names or alias
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);
ancard.insert(ancard.begin(), cit->first);
} else {
......@@ -1491,11 +1491,11 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) {
mainGame->lstANCard->clear();
ancard.clear();
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
//datas.alias can be double card names or alias
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);
ancard.insert(ancard.begin(), cit->first);
} else {
......
#include "data_manager.h"
#include "game.h"
#include <stdio.h>
namespace ygo {
......@@ -183,7 +184,7 @@ const wchar_t* DataManager::GetSetName(int code) {
unsigned int DataManager::GetSetCode(const wchar_t* setname) {
for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) {
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 0;
......
......@@ -902,6 +902,7 @@ void DeckBuilder::FilterCards() {
int trycode = BufferIO::GetVal(elements_iterator->c_str());
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
&& !mainGame->CheckRegEx(text.text, elements_iterator->c_str())
&& (!set_code_map[*elements_iterator] || !check_set_code(data, set_code_map[*elements_iterator]))) {
is_target = false;
break;
......@@ -969,7 +970,7 @@ void DeckBuilder::SortList() {
auto left = results.begin();
const wchar_t* pstr = mainGame->ebCardName->getText();
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);
++left;
}
......@@ -1017,6 +1018,8 @@ bool DeckBuilder::CardNameContains(const wchar_t *haystack, const wchar_t *needl
if (!haystack) {
return false;
}
if(mainGame->CheckRegEx(haystack, needle))
return true;
int i = 0;
int j = 0;
while (haystack[i]) {
......
......@@ -1809,6 +1809,13 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true;
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;
}
case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked())
soundManager.StopBGM();
......
......@@ -9,6 +9,7 @@
#include "duelclient.h"
#include "netserver.h"
#include "single_mode.h"
#include <regex>
const unsigned short PRO_VERSION = 0x1346;
......@@ -300,6 +301,9 @@ bool Game::Initialize() {
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;
chkRegex = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_REGEX, dataManager.GetSysString(1379));
chkRegex->setChecked(gameConf.search_regex > 0);
posY += 30;
chkEnableSound = env->addCheckBox(gameConf.enable_sound, rect<s32>(posX, posY, posX + 120, posY + 25), tabSystem, -1, dataManager.GetSysString(1279));
chkEnableSound->setChecked(gameConf.enable_sound);
scrSoundVolume = env->addScrollBar(true, rect<s32>(posX + 126, posY + 4, posX + 260, posY + 21), tabSystem, SCROLL_VOLUME);
......@@ -982,6 +986,7 @@ void Game::LoadConfig() {
gameConf.separate_clear_button = 1;
gameConf.auto_search_limit = -1;
gameConf.search_multiple_keywords = 1;
gameConf.search_regex = 0;
gameConf.chkIgnoreDeckChanges = 0;
gameConf.defaultOT = 1;
gameConf.enable_bot_mode = 0;
......@@ -1050,6 +1055,8 @@ void Game::LoadConfig() {
gameConf.auto_search_limit = atoi(valbuf);
} else if(!strcmp(strbuf, "search_multiple_keywords")) {
gameConf.search_multiple_keywords = atoi(valbuf);
} else if(!strcmp(strbuf, "search_regex")) {
gameConf.search_regex = atoi(valbuf);
} else if(!strcmp(strbuf, "ignore_deck_changes")) {
gameConf.chkIgnoreDeckChanges = atoi(valbuf);
} else if(!strcmp(strbuf, "default_ot")) {
......@@ -1131,6 +1138,7 @@ void Game::SaveConfig() {
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, "search_regex = %d\n", gameConf.search_regex);
fprintf(fp, "ignore_deck_changes = %d\n", (chkIgnoreDeckChanges->isChecked() ? 1 : 0));
fprintf(fp, "default_ot = %d\n", gameConf.defaultOT);
fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode);
......@@ -1390,6 +1398,34 @@ void Game::FlashWindow() {
FlashWindowEx(&fi);
#endif
}
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;
}
void Game::SetCursor(ECURSOR_ICON icon) {
ICursorControl* cursor = mainGame->device->getCursorControl();
if(cursor->getActiveIcon() != icon) {
......
......@@ -40,6 +40,7 @@ struct Config {
int separate_clear_button;
int auto_search_limit;
int search_multiple_keywords;
int search_regex;
int chkIgnoreDeckChanges;
int defaultOT;
int enable_bot_mode;
......@@ -143,6 +144,8 @@ public:
int LocalPlayer(int player);
const wchar_t* LocalName(int local_player);
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 {
irr::gui::IGUIElement* focus = env->getFocus();
......@@ -250,6 +253,7 @@ public:
irr::gui::IGUICheckBox* chkIgnoreDeckChanges;
irr::gui::IGUICheckBox* chkAutoSearch;
irr::gui::IGUICheckBox* chkMultiKeywords;
irr::gui::IGUICheckBox* chkRegex;
irr::gui::IGUICheckBox* chkEnableSound;
irr::gui::IGUICheckBox* chkEnableMusic;
irr::gui::IGUIScrollBar* scrSoundVolume;
......@@ -628,6 +632,7 @@ extern Game* mainGame;
#define BUTTON_CANCEL_SINGLEPLAY 352
#define CHECKBOX_AUTO_SEARCH 360
#define CHECKBOX_MULTI_KEYWORDS 372
#define CHECKBOX_REGEX 373
#define CHECKBOX_ENABLE_SOUND 361
#define CHECKBOX_ENABLE_MUSIC 362
#define SCROLL_VOLUME 363
......
......@@ -401,6 +401,7 @@
!system 1373 名称↓
!system 1374 连接标记
!system 1378 使用多个关键词搜索卡片
!system 1379 使用正则表达式搜索卡片
!system 1380 人机模式
!system 1381 残局模式
!system 1382 人机信息:
......
......@@ -27,6 +27,8 @@ draw_field_spell = 1
separate_clear_button = 1
#auto_search_limit >= 0: Start search automatically when the user enters N chars
auto_search_limit = -1
search_multiple_keywords = 1
search_regex = 0
ignore_deck_changes = 0
default_ot = 1
enable_bot_mode = 0
......
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