Commit 818c283f authored by VanillaSalt's avatar VanillaSalt

sort

parent 6272c66e
#include "client_card.h"
#include "client_field.h"
#include "data_manager.h"
#include "game.h"
namespace ygo {
......@@ -215,10 +216,60 @@ bool ClientCard::deck_sort_lv(code_pointer p1, code_pointer p2) {
return p1->second.attack > p2->second.attack;
if(p1->second.defence != p2->second.defence)
return p1->second.defence > p2->second.defence;
else return p1->first < p2->first;
return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_atk(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.defence != p2->second.defence)
return p1->second.defence > p2->second.defence;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
int type1 = (p1->second.type & 0x8020c0) ? (p1->second.type & 0x8020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x8020c0) ? (p2->second.type & 0x8020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_def(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
if(p1->second.defence != p2->second.defence)
return p1->second.defence > p2->second.defence;
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
int type1 = (p1->second.type & 0x8020c0) ? (p1->second.type & 0x8020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x8020c0) ? (p2->second.type & 0x8020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_name(code_pointer p1, code_pointer p2) {
CardString cstr1;
CardString cstr2;
dataManager.GetString(p1->second.code, &cstr1);
dataManager.GetString(p2->second.code, &cstr2);
int res = wcscmp(cstr1.name, cstr2.name);
if(res != 0)
return res < 0;
return p1->first < p2->first;
}
}
......@@ -112,6 +112,9 @@ public:
void ClearTarget();
static bool client_card_sort(ClientCard* c1, ClientCard* c2);
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2);
static bool deck_sort_def(code_pointer l1, code_pointer l2);
static bool deck_sort_name(code_pointer l1, code_pointer l2);
};
}
......
......@@ -110,6 +110,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
mainGame->wDeckEdit->setVisible(false);
mainGame->wCategories->setVisible(false);
mainGame->wFilter->setVisible(false);
mainGame->wSort->setVisible(false);
mainGame->wCardImg->setVisible(false);
mainGame->wInfos->setVisible(false);
mainGame->PopupElement(mainGame->wMainMenu);
......@@ -322,6 +323,12 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
}
break;
}
case COMBOBOX_SORTTYPE: {
SortList();
mainGame->env->setFocus(0);
break;
}
}
}
......@@ -767,7 +774,7 @@ void DeckBuilder::FilterCards() {
mainGame->scrFilter->setVisible(false);
mainGame->scrFilter->setPos(0);
}
std::sort(results.begin(), results.end(), ClientCard::deck_sort_lv);
SortList();
}
void DeckBuilder::ClearSearch() {
mainGame->cbCardType->setSelected(0);
......@@ -794,5 +801,21 @@ void DeckBuilder::ClearFilter() {
for(int i = 0; i < 32; ++i)
mainGame->chkCategory[i]->setChecked(false);
}
void DeckBuilder::SortList() {
switch(mainGame->cbSortType->getSelected()) {
case 0:
std::sort(results.begin(), results.end(), ClientCard::deck_sort_lv);
break;
case 1:
std::sort(results.begin(), results.end(), ClientCard::deck_sort_atk);
break;
case 2:
std::sort(results.begin(), results.end(), ClientCard::deck_sort_def);
break;
case 3:
std::sort(results.begin(), results.end(), ClientCard::deck_sort_name);
break;
}
}
}
......@@ -14,6 +14,7 @@ public:
void FilterCards();
void ClearFilter();
void ClearSearch();
void SortList();
long long filter_effect;
unsigned int filter_type;
......
......@@ -280,6 +280,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->wPhase->setVisible(false);
mainGame->wDeckEdit->setVisible(false);
mainGame->wFilter->setVisible(false);
mainGame->wSort->setVisible(false);
mainGame->btnSideOK->setVisible(true);
if(mainGame->dInfo.player_type < 7)
mainGame->btnLeaveGame->setVisible(false);
......
......@@ -461,6 +461,12 @@ bool Game::Initialize() {
scrFilter->setLargeStep(10);
scrFilter->setSmallStep(1);
scrFilter->setVisible(false);
//sort type
wSort = env->addStaticText(L"", rect<s32>(930, 132, 1020, 156), true, false, 0, -1, true);
cbSortType = env->addComboBox(rect<s32>(10, 2, 85, 22), wSort, COMBOBOX_SORTTYPE);
for(int i = 1370; i <= 1373; i++)
cbSortType->addItem(dataManager.GetSysString(i));
wSort->setVisible(false);
//replay window
wReplay = env->addWindow(rect<s32>(220, 100, 800, 520), false, dataManager.GetSysString(1202));
wReplay->getCloseButton()->setVisible(false);
......@@ -970,8 +976,8 @@ void Game::ShowCardInfo(int code) {
myswprintf(formatBuffer, L"[%ls] %ls/%ls", dataManager.FormatType(cd.type), dataManager.FormatRace(cd.race), dataManager.FormatAttribute(cd.attribute));
stInfo->setText(formatBuffer);
int form = 0x2605;
if(cd.type & TYPE_XYZ) ++form ;
myswprintf(formatBuffer, L"[%c%d] ",form,cd.level);
if(cd.type & TYPE_XYZ) ++form;
myswprintf(formatBuffer, L"[%c%d] ", form, cd.level);
wchar_t adBuffer[16];
if(cd.attack < 0 && cd.defence < 0)
myswprintf(adBuffer, L"?/?");
......
......@@ -369,6 +369,9 @@ public:
irr::gui::IGUIWindow* wCategories;
irr::gui::IGUICheckBox* chkCategory[32];
irr::gui::IGUIButton* btnCategoryOK;
//sort type
irr::gui::IGUIStaticText* wSort;
irr::gui::IGUIComboBox* cbSortType;
//replay save
irr::gui::IGUIWindow* wReplaySave;
irr::gui::IGUIEditBox* ebRSName;
......@@ -505,4 +508,5 @@ extern Game* mainGame;
#define LISTBOX_SINGLEPLAY_LIST 350
#define BUTTON_LOAD_SINGLEPLAY 351
#define BUTTON_CANCEL_SINGLEPLAY 352
#define COMBOBOX_SORTTYPE 370
#endif // GAME_H
......@@ -220,6 +220,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->wCardImg->setVisible(true);
mainGame->wDeckEdit->setVisible(true);
mainGame->wFilter->setVisible(true);
mainGame->wSort->setVisible(true);
mainGame->btnSideOK->setVisible(false);
mainGame->deckBuilder.filterList = deckManager._lfList[0].content;
mainGame->cbDBLFList->setSelected(0);
......
Subproject commit 60b891ab59cb34d31a584f7a9de98a78c7af4afb
Subproject commit 7059fdaede394163a2f718ce6a50bafb151fe5f4
Subproject commit 40925d41110b1b3674bd43f7a308ae2aa2ba4e0e
Subproject commit 9f3a2f3659f31bcb50c188a2e92107980531af75
......@@ -331,6 +331,10 @@
!system 1353 播放起始于回合:
!system 1354 不显示卡片系列
!system 1360 上一步
!system 1370 星数↑
!system 1371 攻击↑
!system 1372 守备↑
!system 1373 名称↓
!system 1390 等待行动中...
!system 1391 等待行动中....
!system 1392 等待行动中.....
......
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