Commit eb60a60b authored by VanillaSalt's avatar VanillaSalt

improve SortList()

parent 6e54a79c
...@@ -263,11 +263,9 @@ bool ClientCard::deck_sort_def(code_pointer p1, code_pointer p2) { ...@@ -263,11 +263,9 @@ bool ClientCard::deck_sort_def(code_pointer p1, code_pointer p2) {
return p1->first < p2->first; return p1->first < p2->first;
} }
bool ClientCard::deck_sort_name(code_pointer p1, code_pointer p2) { bool ClientCard::deck_sort_name(code_pointer p1, code_pointer p2) {
CardString cstr1; const wchar_t* name1 = dataManager.GetName(p1->first);
CardString cstr2; const wchar_t* name2 = dataManager.GetName(p2->first);
dataManager.GetString(p1->second.code, &cstr1); int res = wcscmp(name1, name2);
dataManager.GetString(p2->second.code, &cstr2);
int res = wcscmp(cstr1.name, cstr2.name);
if(res != 0) if(res != 0)
return res < 0; return res < 0;
return p1->first < p2->first; return p1->first < p2->first;
......
...@@ -41,7 +41,7 @@ struct CardString { ...@@ -41,7 +41,7 @@ struct CardString {
wchar_t* text; wchar_t* text;
wchar_t* desc[16]; wchar_t* desc[16];
}; };
typedef std::unordered_map<unsigned int, CardDataC>::iterator code_pointer; typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer;
class ClientCard { class ClientCard {
public: public:
......
...@@ -896,29 +896,28 @@ void DeckBuilder::ClearFilter() { ...@@ -896,29 +896,28 @@ void DeckBuilder::ClearFilter() {
mainGame->chkCategory[i]->setChecked(false); mainGame->chkCategory[i]->setChecked(false);
} }
void DeckBuilder::SortList() { 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) {
std::iter_swap(left, it);
++left;
}
}
switch(mainGame->cbSortType->getSelected()) { switch(mainGame->cbSortType->getSelected()) {
case 0: case 0:
std::sort(results.begin(), results.end(), ClientCard::deck_sort_lv); std::sort(left, results.end(), ClientCard::deck_sort_lv);
break; break;
case 1: case 1:
std::sort(results.begin(), results.end(), ClientCard::deck_sort_atk); std::sort(left, results.end(), ClientCard::deck_sort_atk);
break; break;
case 2: case 2:
std::sort(results.begin(), results.end(), ClientCard::deck_sort_def); std::sort(left, results.end(), ClientCard::deck_sort_def);
break; break;
case 3: case 3:
std::sort(results.begin(), results.end(), ClientCard::deck_sort_name); std::sort(left, results.end(), ClientCard::deck_sort_name);
break; break;
} }
const wchar_t* pstr = mainGame->ebCardName->getText();
for (size_t i = 0, pos = 0; i < results.size(); ++i){
code_pointer ptr = results[i];
if (wcscmp(pstr, dataManager.GetName(ptr->first))==0) {
results.insert(results.begin() + pos, ptr);
results.erase(results.begin() + i + 1);
pos++;
}
}
} }
} }
Subproject commit 0c58f35e90a3baa10af009776235a53e11eae620 Subproject commit 9e7c8ca88d6ad773f299d19bc1f01f1af496a6ab
Subproject commit 4de8d4093e5767d90696c8abdd2f1d75215d6adb Subproject commit d10310ac812e85972884eaaf83f870e23c871f1c
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