Commit 0586ca05 authored by IceYGO's avatar IceYGO

Search the cards while typing in the deck editor and ignore the case

parent bc0181d3
......@@ -86,101 +86,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) {
FilterCards();
break;
}
filter_attrib = mainGame->cbAttribute->getItemData(mainGame->cbAttribute->getSelected());
filter_race = mainGame->cbRace->getItemData(mainGame->cbRace->getSelected());
const wchar_t* pstr = mainGame->ebAttack->getText();
if(*pstr == 0) filter_atktype = 0;
else {
if(*pstr == L'=') {
filter_atktype = 1;
filter_atk = BufferIO::GetVal(pstr + 1);
} else if(*pstr >= L'0' && *pstr <= L'9') {
filter_atktype = 1;
filter_atk = BufferIO::GetVal(pstr);
} else if(*pstr == L'>') {
if(*(pstr + 1) == L'=') {
filter_atktype = 2;
filter_atk = BufferIO::GetVal(pstr + 2);
} else {
filter_atktype = 3;
filter_atk = BufferIO::GetVal(pstr + 1);
}
} else if(*pstr == L'<') {
if(*(pstr + 1) == L'=') {
filter_atktype = 4;
filter_atk = BufferIO::GetVal(pstr + 2);
} else {
filter_atktype = 5;
filter_atk = BufferIO::GetVal(pstr + 1);
}
} else if(*pstr == L'?') {
filter_atktype = 6;
} else filter_atktype = 0;
}
pstr = mainGame->ebDefence->getText();
if(*pstr == 0) filter_deftype = 0;
else {
if(*pstr == L'=') {
filter_deftype = 1;
filter_def = BufferIO::GetVal(pstr + 1);
} else if(*pstr >= L'0' && *pstr <= L'9') {
filter_deftype = 1;
filter_def = BufferIO::GetVal(pstr);
} else if(*pstr == L'>') {
if(*(pstr + 1) == L'=') {
filter_deftype = 2;
filter_def = BufferIO::GetVal(pstr + 2);
} else {
filter_deftype = 3;
filter_def = BufferIO::GetVal(pstr + 1);
}
} else if(*pstr == L'<') {
if(*(pstr + 1) == L'=') {
filter_deftype = 4;
filter_def = BufferIO::GetVal(pstr + 2);
} else {
filter_deftype = 5;
filter_def = BufferIO::GetVal(pstr + 1);
}
} else if(*pstr == L'?') {
filter_deftype = 6;
} else filter_deftype = 0;
}
pstr = mainGame->ebStar->getText();
if(*pstr == 0) filter_lvtype = 0;
else {
if(*pstr == L'=') {
filter_lvtype = 1;
filter_lv = BufferIO::GetVal(pstr + 1);
} else if(*pstr >= L'0' && *pstr <= L'9') {
filter_lvtype = 1;
filter_lv = BufferIO::GetVal(pstr);
} else if(*pstr == L'>') {
if(*(pstr + 1) == L'=') {
filter_lvtype = 2;
filter_lv = BufferIO::GetVal(pstr + 2);
} else {
filter_lvtype = 3;
filter_lv = BufferIO::GetVal(pstr + 1);
}
} else if(*pstr == L'<') {
if(*(pstr + 1) == L'=') {
filter_lvtype = 4;
filter_lv = BufferIO::GetVal(pstr + 2);
} else {
filter_lvtype = 5;
filter_lv = BufferIO::GetVal(pstr + 1);
}
} else filter_lvtype = 0;
}
FilterCards();
StartFilter();
break;
}
case BUTTON_CATEGORY_OK: {
......@@ -227,12 +133,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;
}
}
......@@ -645,6 +555,123 @@ 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) {
FilterCards();
return;
}
filter_attrib = mainGame->cbAttribute->getItemData(mainGame->cbAttribute->getSelected());
filter_race = mainGame->cbRace->getItemData(mainGame->cbRace->getSelected());
const wchar_t* pstr = mainGame->ebAttack->getText();
if (*pstr == 0) filter_atktype = 0;
else {
if (*pstr == L'=') {
filter_atktype = 1;
filter_atk = BufferIO::GetVal(pstr + 1);
}
else if (*pstr >= L'0' && *pstr <= L'9') {
filter_atktype = 1;
filter_atk = BufferIO::GetVal(pstr);
}
else if (*pstr == L'>') {
if (*(pstr + 1) == L'=') {
filter_atktype = 2;
filter_atk = BufferIO::GetVal(pstr + 2);
}
else {
filter_atktype = 3;
filter_atk = BufferIO::GetVal(pstr + 1);
}
}
else if (*pstr == L'<') {
if (*(pstr + 1) == L'=') {
filter_atktype = 4;
filter_atk = BufferIO::GetVal(pstr + 2);
}
else {
filter_atktype = 5;
filter_atk = BufferIO::GetVal(pstr + 1);
}
}
else if (*pstr == L'?') {
filter_atktype = 6;
}
else filter_atktype = 0;
}
pstr = mainGame->ebDefence->getText();
if (*pstr == 0) filter_deftype = 0;
else {
if (*pstr == L'=') {
filter_deftype = 1;
filter_def = BufferIO::GetVal(pstr + 1);
}
else if (*pstr >= L'0' && *pstr <= L'9') {
filter_deftype = 1;
filter_def = BufferIO::GetVal(pstr);
}
else if (*pstr == L'>') {
if (*(pstr + 1) == L'=') {
filter_deftype = 2;
filter_def = BufferIO::GetVal(pstr + 2);
}
else {
filter_deftype = 3;
filter_def = BufferIO::GetVal(pstr + 1);
}
}
else if (*pstr == L'<') {
if (*(pstr + 1) == L'=') {
filter_deftype = 4;
filter_def = BufferIO::GetVal(pstr + 2);
}
else {
filter_deftype = 5;
filter_def = BufferIO::GetVal(pstr + 1);
}
}
else if (*pstr == L'?') {
filter_deftype = 6;
}
else filter_deftype = 0;
}
pstr = mainGame->ebStar->getText();
if (*pstr == 0) filter_lvtype = 0;
else {
if (*pstr == L'=') {
filter_lvtype = 1;
filter_lv = BufferIO::GetVal(pstr + 1);
}
else if (*pstr >= L'0' && *pstr <= L'9') {
filter_lvtype = 1;
filter_lv = BufferIO::GetVal(pstr);
}
else if (*pstr == L'>') {
if (*(pstr + 1) == L'=') {
filter_lvtype = 2;
filter_lv = BufferIO::GetVal(pstr + 2);
}
else {
filter_lvtype = 3;
filter_lv = BufferIO::GetVal(pstr + 1);
}
}
else if (*pstr == L'<') {
if (*(pstr + 1) == L'=') {
filter_lvtype = 4;
filter_lv = BufferIO::GetVal(pstr + 2);
}
else {
filter_lvtype = 5;
filter_lv = BufferIO::GetVal(pstr + 1);
}
}
else filter_lvtype = 0;
}
FilterCards();
}
void DeckBuilder::FilterCards() {
results.clear();
const wchar_t* pstr = mainGame->ebCardName->getText();
......@@ -724,7 +751,7 @@ 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) {
unsigned long long sc = data.setcode;
......@@ -743,7 +770,7 @@ void DeckBuilder::FilterCards() {
}
if(!res) continue;
} else {
if(wcsstr(text.name, pstr) == 0 && wcsstr(text.text, pstr) == 0)
if(!CardNameContains(text.name, pstr) && wcsstr(text.text, pstr) == 0)
continue;
}
}
......@@ -769,5 +796,44 @@ void DeckBuilder::FilterCards() {
for(int i = 0; i < 32; ++i)
mainGame->chkCategory[i]->setChecked(false);
}
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;
}
}
......@@ -11,7 +11,9 @@ namespace ygo {
class DeckBuilder: public irr::IEventReceiver {
public:
virtual bool OnEvent(const irr::SEvent& event);
void StartFilter();
void FilterCards();
bool CardNameContains(const wchar_t *haystack, const wchar_t *needle);
long long filter_effect;
unsigned int filter_type;
......
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