Commit 317ce145 authored by mercury233's avatar mercury233

Merge branch 'feature-deck-autosearch' of https://github.com/IceYGO/ygopro into temp-merge

parents 2df085c6 0586ca05
...@@ -159,18 +159,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -159,18 +159,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break; break;
} }
case BUTTON_START_FILTER: { case BUTTON_START_FILTER: {
filter_type = mainGame->cbCardType->getSelected(); StartFilter();
filter_type2 = mainGame->cbCardType2->getItemData(mainGame->cbCardType2->getSelected());
filter_lm = mainGame->cbLimit->getSelected();
if(filter_type == 1) {
filter_attrib = mainGame->cbAttribute->getItemData(mainGame->cbAttribute->getSelected());
filter_race = mainGame->cbRace->getItemData(mainGame->cbRace->getSelected());
filter_atk = parse_filter(mainGame->ebAttack->getText(), &filter_atktype);
filter_def = parse_filter(mainGame->ebDefense->getText(), &filter_deftype);
filter_lv = parse_filter(mainGame->ebStar->getText(), &filter_lvtype);
filter_scl = parse_filter(mainGame->ebScale->getText(), &filter_scltype);
}
FilterCards();
if(!mainGame->gameConf.separate_clear_button) if(!mainGame->gameConf.separate_clear_button)
ClearFilter(); ClearFilter();
break; break;
...@@ -285,12 +274,16 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -285,12 +274,16 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case irr::gui::EGET_EDITBOX_ENTER: { case irr::gui::EGET_EDITBOX_ENTER: {
switch(id) { switch(id) {
case EDITBOX_KEYWORD: { case EDITBOX_KEYWORD: {
irr::SEvent me; StartFilter();
me.EventType = irr::EET_GUI_EVENT; break;
me.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED; }
me.GUIEvent.Caller = mainGame->btnStartFilter; }
me.GUIEvent.Element = mainGame->btnStartFilter; break;
mainGame->device->postEventFromUser(me); }
case irr::gui::EGET_EDITBOX_CHANGED: {
switch (id) {
case EDITBOX_KEYWORD: {
StartFilter();
break; break;
} }
} }
...@@ -810,6 +803,20 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -810,6 +803,20 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
} }
return false; return false;
} }
void DeckBuilder::StartFilter() {
filter_type = mainGame->cbCardType->getSelected();
filter_type2 = mainGame->cbCardType2->getItemData(mainGame->cbCardType2->getSelected());
filter_lm = mainGame->cbLimit->getSelected();
if(filter_type == 1) {
filter_attrib = mainGame->cbAttribute->getItemData(mainGame->cbAttribute->getSelected());
filter_race = mainGame->cbRace->getItemData(mainGame->cbRace->getSelected());
filter_atk = parse_filter(mainGame->ebAttack->getText(), &filter_atktype);
filter_def = parse_filter(mainGame->ebDefense->getText(), &filter_deftype);
filter_lv = parse_filter(mainGame->ebStar->getText(), &filter_lvtype);
filter_scl = parse_filter(mainGame->ebScale->getText(), &filter_scltype);
}
FilterCards();
}
void DeckBuilder::FilterCards() { void DeckBuilder::FilterCards() {
results.clear(); results.clear();
const wchar_t* pstr = mainGame->ebCardName->getText(); const wchar_t* pstr = mainGame->ebCardName->getText();
...@@ -903,12 +910,12 @@ void DeckBuilder::FilterCards() { ...@@ -903,12 +910,12 @@ void DeckBuilder::FilterCards() {
} }
if(pstr) { if(pstr) {
if(pstr[0] == L'$') { if(pstr[0] == L'$') {
if(wcsstr(text.name, &pstr[1]) == 0) if(!CardNameContains(text.name, &pstr[1]))
continue; continue;
} else if(pstr[0] == L'@' && set_code) { } else if(pstr[0] == L'@' && set_code) {
if(!check_set_code(data, set_code)) continue; if(!check_set_code(data, set_code)) continue;
} else { } else {
if(wcsstr(text.name, pstr) == 0 && wcsstr(text.text, pstr) == 0 if(!CardNameContains(text.name, pstr) && wcsstr(text.text, pstr) == 0
&& (!set_code || !check_set_code(data, set_code))) && (!set_code || !check_set_code(data, set_code)))
continue; continue;
} }
...@@ -978,5 +985,44 @@ void DeckBuilder::SortList() { ...@@ -978,5 +985,44 @@ void DeckBuilder::SortList() {
break; break;
} }
} }
static inline wchar_t NormalizeChar(wchar_t c) {
// Convert all symbols and punctuations to space.
if (c != 0 && c < 128 && !isalnum(c)) {
return ' ';
}
// Convert latin chararacters to uppercase to ignore case.
if (c < 128 && isalpha(c)) {
return toupper(c);
}
// Remove some accentued characters that are not supported by the editbox.
if (c >= 232 && c <= 235) {
return 'E';
}
if (c >= 238 && c <= 239) {
return 'I';
}
return c;
}
bool DeckBuilder::CardNameContains(const wchar_t *haystack, const wchar_t *needle)
{
if (!needle[0]) {
return true;
}
int i = 0;
int j = 0;
while (haystack[i]) {
wchar_t ca = NormalizeChar(haystack[i]);
wchar_t cb = NormalizeChar(needle[j]);
if (ca == cb) {
j++;
if (!needle[j]) {
return true;
}
} else {
j = 0;
}
i++;
}
return false;
}
} }
...@@ -12,10 +12,13 @@ class DeckBuilder: public irr::IEventReceiver { ...@@ -12,10 +12,13 @@ class DeckBuilder: public irr::IEventReceiver {
public: public:
virtual bool OnEvent(const irr::SEvent& event); virtual bool OnEvent(const irr::SEvent& event);
void FilterCards(); void FilterCards();
void StartFilter();
void ClearFilter(); void ClearFilter();
void ClearSearch(); void ClearSearch();
void SortList(); void SortList();
bool CardNameContains(const wchar_t *haystack, const wchar_t *needle);
long long filter_effect; long long filter_effect;
unsigned int filter_type; unsigned int filter_type;
unsigned int filter_type2; unsigned int filter_type2;
......
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