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) {
break;
}
case BUTTON_START_FILTER: {
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();
StartFilter();
if(!mainGame->gameConf.separate_clear_button)
ClearFilter();
break;
......@@ -285,12 +274,16 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case irr::gui::EGET_EDITBOX_ENTER: {
switch(id) {
case EDITBOX_KEYWORD: {
irr::SEvent me;
me.EventType = irr::EET_GUI_EVENT;
me.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED;
me.GUIEvent.Caller = mainGame->btnStartFilter;
me.GUIEvent.Element = mainGame->btnStartFilter;
mainGame->device->postEventFromUser(me);
StartFilter();
break;
}
}
break;
}
case irr::gui::EGET_EDITBOX_CHANGED: {
switch (id) {
case EDITBOX_KEYWORD: {
StartFilter();
break;
}
}
......@@ -810,6 +803,20 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
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() {
results.clear();
const wchar_t* pstr = mainGame->ebCardName->getText();
......@@ -903,12 +910,12 @@ void DeckBuilder::FilterCards() {
}
if(pstr) {
if(pstr[0] == L'$') {
if(wcsstr(text.name, &pstr[1]) == 0)
if(!CardNameContains(text.name, &pstr[1]))
continue;
} else if(pstr[0] == L'@' && set_code) {
if(!check_set_code(data, set_code)) continue;
} 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)))
continue;
}
......@@ -978,5 +985,44 @@ void DeckBuilder::SortList() {
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 {
public:
virtual bool OnEvent(const irr::SEvent& event);
void FilterCards();
void StartFilter();
void ClearFilter();
void ClearSearch();
void SortList();
bool CardNameContains(const wchar_t *haystack, const wchar_t *needle);
long long filter_effect;
unsigned int filter_type;
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