Commit 16bccfc7 authored by fallenstardust's avatar fallenstardust

适配Android卡组管理

parent 3a5df330
This diff is collapsed.
...@@ -66,10 +66,12 @@ public: ...@@ -66,10 +66,12 @@ public:
size_t pre_extrac; size_t pre_extrac;
size_t pre_sidec; size_t pre_sidec;
code_pointer draging_pointer; code_pointer draging_pointer;
int prev_category;
int prev_deck; int prev_deck;
s32 prev_operation; s32 prev_operation;
int prev_sel; int prev_sel;
bool is_modified; bool is_modified;
bool readonly;
std::unordered_map<int, int>* filterList; std::unordered_map<int, int>* filterList;
std::vector<code_pointer> results; std::vector<code_pointer> results;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "data_manager.h" #include "data_manager.h"
#include "network.h" #include "network.h"
#include "game.h" #include "game.h"
#include "myfilesystem.h"
#include <algorithm> #include <algorithm>
namespace ygo { namespace ygo {
...@@ -56,23 +57,6 @@ void DeckManager::LoadLFList(const char* path, bool load_none) { ...@@ -56,23 +57,6 @@ void DeckManager::LoadLFList(const char* path, bool load_none) {
nolimit.content = new std::unordered_map<int, int>; nolimit.content = new std::unordered_map<int, int>;
_lfList.push_back(nolimit); _lfList.push_back(nolimit);
} }
bool DeckManager::RenameDeck(const wchar_t* oldname, const wchar_t* newname) {
wchar_t oldfname[256];
wchar_t newfname[256];
myswprintf(oldfname, L"./deck/%ls.ydk", oldname);
myswprintf(newfname, L"./deck/%ls.ydk", newname);
#ifdef WIN32
BOOL result = MoveFileW(oldfname, newfname);
return !!result;
#else
char oldfilefn[256];
char newfilefn[256];
BufferIO::EncodeUTF8(oldfname, oldfilefn);
BufferIO::EncodeUTF8(newfname, newfilefn);
int result = rename(oldfilefn, newfilefn);
return result == 0;
#endif
}
wchar_t* DeckManager::GetLFListName(int lfhash) { wchar_t* DeckManager::GetLFListName(int lfhash) {
for(size_t i = 0; i < _lfList.size(); ++i) { for(size_t i = 0; i < _lfList.size(); ++i) {
if(_lfList[i].hash == (unsigned int)lfhash) { if(_lfList[i].hash == (unsigned int)lfhash) {
...@@ -206,6 +190,37 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) { ...@@ -206,6 +190,37 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
deck = ndeck; deck = ndeck;
return true; return true;
} }
void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text) {
wchar_t catepath[256];
switch(index) {
case 0:
myswprintf(catepath, L"./pack");
break;
case 1:
myswprintf(catepath, L"./windbot/Decks");
break;
case -1:
case 2:
case 3:
myswprintf(catepath, L"./deck");
break;
default:
myswprintf(catepath, L"./deck/%ls", text);
}
BufferIO::CopyWStr(catepath, ret, 256);
}
void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
wchar_t filepath[256];
wchar_t catepath[256];
GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText());
myswprintf(filepath, L"%ls/%ls.ydk", catepath, cbDeck->getItem(cbDeck->getSelected()));
BufferIO::CopyWStr(filepath, ret, 256);
}
bool DeckManager::LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
wchar_t filepath[256];
GetDeckFile(filepath, cbCategory, cbDeck);
return LoadDeck(filepath);
}
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) { FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
#ifdef WIN32 #ifdef WIN32
FILE* fp = _wfopen(file, (wchar_t*)mode); FILE* fp = _wfopen(file, (wchar_t*)mode);
...@@ -218,11 +233,11 @@ FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) { ...@@ -218,11 +233,11 @@ FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
} }
bool DeckManager::LoadDeck(const wchar_t* file) { bool DeckManager::LoadDeck(const wchar_t* file) {
int sp = 0, ct = 0, mainc = 0, sidec = 0, code; int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
wchar_t localfile[64]; FILE* fp = OpenDeckFile(file, "r");
myswprintf(localfile, L"./deck/%ls.ydk", file);
FILE* fp = OpenDeckFile(localfile, "r");
if(!fp) { if(!fp) {
fp = OpenDeckFile(file, "r"); wchar_t localfile[64];
myswprintf(localfile, L"./deck/%ls.ydk", file);
fp = OpenDeckFile(localfile, "r");
} }
if(!fp) if(!fp)
return false; return false;
...@@ -248,9 +263,9 @@ bool DeckManager::LoadDeck(const wchar_t* file) { ...@@ -248,9 +263,9 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
LoadDeck(current_deck, cardlist, mainc, sidec); LoadDeck(current_deck, cardlist, mainc, sidec);
return true; return true;
} }
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) { bool DeckManager::SaveDeck(Deck& deck, const wchar_t* file) {
wchar_t file[64]; if(!FileSystem::IsDirExists(L"./deck") && !FileSystem::MakeDir(L"./deck"))
myswprintf(file, L"./deck/%ls.ydk", name); return false;
FILE* fp = OpenDeckFile(file, "w"); FILE* fp = OpenDeckFile(file, "w");
if(!fp) if(!fp)
return false; return false;
...@@ -266,9 +281,7 @@ bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) { ...@@ -266,9 +281,7 @@ bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
fclose(fp); fclose(fp);
return true; return true;
} }
bool DeckManager::DeleteDeck(Deck& deck, const wchar_t* name) { bool DeckManager::DeleteDeck(const wchar_t* file) {
wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name);
#ifdef WIN32 #ifdef WIN32
BOOL result = DeleteFileW(file); BOOL result = DeleteFileW(file);
return !!result; return !!result;
...@@ -279,6 +292,34 @@ bool DeckManager::DeleteDeck(Deck& deck, const wchar_t* name) { ...@@ -279,6 +292,34 @@ bool DeckManager::DeleteDeck(Deck& deck, const wchar_t* name) {
return result == 0; return result == 0;
#endif #endif
} }
bool DeckManager::CreateCategory(const wchar_t* name) {
if(!FileSystem::IsDirExists(L"./deck") && !FileSystem::MakeDir(L"./deck"))
return false;
if(name[0] == 0)
return false;
wchar_t localname[256];
myswprintf(localname, L"./deck/%ls", name);
return FileSystem::MakeDir(localname);
}
bool DeckManager::RenameCategory(const wchar_t* oldname, const wchar_t* newname) {
if(!FileSystem::IsDirExists(L"./deck") && !FileSystem::MakeDir(L"./deck"))
return false;
if(newname[0] == 0)
return false;
wchar_t oldlocalname[256];
wchar_t newlocalname[256];
myswprintf(oldlocalname, L"./deck/%ls", oldname);
myswprintf(newlocalname, L"./deck/%ls", newname);
return FileSystem::Rename(oldlocalname, newlocalname);
}
bool DeckManager::DeleteCategory(const wchar_t* name) {
wchar_t localname[256];
myswprintf(localname, L"./deck/%ls", name);
if(!FileSystem::IsDirExists(localname))
return false;
return FileSystem::DeleteDir(localname);
}
int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) { int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) {
int res = 0; int res = 0;
for(size_t i = 0; i < list.size(); ++i) { for(size_t i = 0; i < list.size(); ++i) {
...@@ -288,4 +329,5 @@ int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) { ...@@ -288,4 +329,5 @@ int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) {
} }
return res; return res;
} }
} }
...@@ -40,11 +40,16 @@ public: ...@@ -40,11 +40,16 @@ public:
int CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg); int CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec); int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec); bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
FILE* OpenDeckFile(const wchar_t * file, const char * mode); FILE* OpenDeckFile(const wchar_t * file, const char * mode);
bool LoadDeck(const wchar_t* file); bool LoadDeck(const wchar_t* file);
bool SaveDeck(Deck& deck, const wchar_t* name); bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(Deck& deck, const wchar_t* name); bool DeleteDeck(const wchar_t* file);
static bool RenameDeck(const wchar_t* oldname, const wchar_t* newname); bool CreateCategory(const wchar_t* name);
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name);
int TypeCount(std::vector<code_pointer> list, unsigned int ctype); int TypeCount(std::vector<code_pointer> list, unsigned int ctype);
}; };
......
...@@ -308,6 +308,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -308,6 +308,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
} }
} }
mainGame->env->addMessageBox(L"", msgbuf); mainGame->env->addMessageBox(L"", msgbuf);
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true); mainGame->cbDeckSelect->setEnabled(true);
mainGame->gMutex.unlock(); mainGame->gMutex.unlock();
break; break;
...@@ -341,7 +342,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -341,7 +342,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
} }
case STOC_SELECT_TP: { case STOC_SELECT_TP: {
mainGame->gMutex.lock(); mainGame->gMutex.lock();
mainGame->PopupElement(mainGame->wFTSelect); mainGame->ShowElement(mainGame->wFTSelect);
mainGame->gMutex.unlock(); mainGame->gMutex.unlock();
break; break;
} }
...@@ -471,7 +472,8 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -471,7 +472,8 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->stHostPrepDuelist[3]->setText(L""); mainGame->stHostPrepDuelist[3]->setText(L"");
mainGame->stHostPrepOB->setText(L""); mainGame->stHostPrepOB->setText(L"");
mainGame->SetStaticText(mainGame->stHostPrepRule, 180 * mainGame->xScale, mainGame->guiFont, str.c_str()); mainGame->SetStaticText(mainGame->stHostPrepRule, 180 * mainGame->xScale, mainGame->guiFont, str.c_str());
mainGame->RefreshDeck(mainGame->cbDeckSelect); mainGame->RefreshCategoryDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true); mainGame->cbDeckSelect->setEnabled(true);
if(mainGame->wCreateHost->isVisible()) if(mainGame->wCreateHost->isVisible())
mainGame->HideElement(mainGame->wCreateHost); mainGame->HideElement(mainGame->wCreateHost);
......
This diff is collapsed.
...@@ -23,10 +23,12 @@ struct Config { ...@@ -23,10 +23,12 @@ struct Config {
wchar_t lastport[10]; wchar_t lastport[10];
wchar_t nickname[20]; wchar_t nickname[20];
wchar_t gamename[20]; wchar_t gamename[20];
wchar_t lastcategory[64];
wchar_t lastdeck[64]; wchar_t lastdeck[64];
wchar_t textfont[256]; wchar_t textfont[256];
wchar_t numfont[256]; wchar_t numfont[256];
wchar_t roompass[20]; wchar_t roompass[20];
wchar_t bot_deck_path[64];
//settings //settings
int chkMAutoPos; int chkMAutoPos;
int chkSTAutoPos; int chkSTAutoPos;
...@@ -119,7 +121,9 @@ public: ...@@ -119,7 +121,9 @@ public:
void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text); void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text);
void SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, u32 pos = 0); void SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, u32 pos = 0);
void LoadExpansions(); void LoadExpansions();
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck); void RefreshCategoryDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck, bool selectlastused = true);
void RefreshDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
void RefreshDeck(const wchar_t* deckpath, irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay(); void RefreshReplay();
void RefreshSingleplay(); void RefreshSingleplay();
void RefreshBot(); void RefreshBot();
...@@ -302,6 +306,7 @@ public: ...@@ -302,6 +306,7 @@ public:
irr::gui::IGUIStaticText* stHostPrepDuelist[4]; irr::gui::IGUIStaticText* stHostPrepDuelist[4];
irr::gui::IGUICheckBox* chkHostPrepReady[4]; irr::gui::IGUICheckBox* chkHostPrepReady[4];
irr::gui::IGUIButton* btnHostPrepKick[4]; irr::gui::IGUIButton* btnHostPrepKick[4];
irr::gui::IGUIComboBox* cbCategorySelect;
irr::gui::IGUIComboBox* cbDeckSelect; irr::gui::IGUIComboBox* cbDeckSelect;
irr::gui::IGUIStaticText* stHostPrepRule; irr::gui::IGUIStaticText* stHostPrepRule;
irr::gui::IGUIStaticText* stHostPrepOB; irr::gui::IGUIStaticText* stHostPrepOB;
...@@ -427,8 +432,9 @@ public: ...@@ -427,8 +432,9 @@ public:
irr::gui::IGUIButton* btnEP; irr::gui::IGUIButton* btnEP;
//deck edit //deck edit
irr::gui::IGUIStaticText* wDeckEdit; irr::gui::IGUIStaticText* wDeckEdit;
irr::gui::IGUIComboBox* cbDBLFList; irr::gui::IGUIComboBox* cbDBCategory;
irr::gui::IGUIComboBox* cbDBDecks; irr::gui::IGUIComboBox* cbDBDecks;
irr::gui::IGUIButton* btnManageDeck;
irr::gui::IGUIButton* btnClearDeck; irr::gui::IGUIButton* btnClearDeck;
irr::gui::IGUIButton* btnSortDeck; irr::gui::IGUIButton* btnSortDeck;
irr::gui::IGUIButton* btnShuffleDeck; irr::gui::IGUIButton* btnShuffleDeck;
...@@ -440,7 +446,7 @@ public: ...@@ -440,7 +446,7 @@ public:
irr::gui::IGUIButton* btnSideSort; irr::gui::IGUIButton* btnSideSort;
irr::gui::IGUIButton* btnSideReload; irr::gui::IGUIButton* btnSideReload;
irr::gui::IGUIEditBox* ebDeckname; irr::gui::IGUIEditBox* ebDeckname;
irr::gui::IGUIStaticText* stBanlist; irr::gui::IGUIStaticText* stDBCategory;
irr::gui::IGUIStaticText* stDeck; irr::gui::IGUIStaticText* stDeck;
irr::gui::IGUIStaticText* stCategory; irr::gui::IGUIStaticText* stCategory;
irr::gui::IGUIStaticText* stLimit; irr::gui::IGUIStaticText* stLimit;
...@@ -451,12 +457,26 @@ public: ...@@ -451,12 +457,26 @@ public:
irr::gui::IGUIStaticText* stStar; irr::gui::IGUIStaticText* stStar;
irr::gui::IGUIStaticText* stSearch; irr::gui::IGUIStaticText* stSearch;
irr::gui::IGUIStaticText* stScale; irr::gui::IGUIStaticText* stScale;
//deck rename //deck manage
irr::gui::IGUIWindow* wDeckManage;
irr::gui::IGUIListBox* lstCategories;
irr::gui::IGUIListBox* lstDecks;
irr::gui::IGUIButton* btnNewCategory;
irr::gui::IGUIButton* btnRenameCategory;
irr::gui::IGUIButton* btnDeleteCategory;
irr::gui::IGUIButton* btnNewDeck;
irr::gui::IGUIButton* btnRenameDeck; irr::gui::IGUIButton* btnRenameDeck;
irr::gui::IGUIWindow* wRenameDeck; irr::gui::IGUIButton* btnDMDeleteDeck;
irr::gui::IGUIEditBox* ebREName; irr::gui::IGUIButton* btnMoveDeck;
irr::gui::IGUIButton* btnREYes; irr::gui::IGUIButton* btnCopyDeck;
irr::gui::IGUIButton* btnRENo; irr::gui::IGUIWindow* wDMQuery;
irr::gui::IGUIStaticText* stDMMessage;
irr::gui::IGUIStaticText* stDMMessage2;
irr::gui::IGUIEditBox* ebDMName;
irr::gui::IGUIComboBox* cbDMCategory;
irr::gui::IGUIButton* btnDMOK;
irr::gui::IGUIButton* btnDMCancel;
irr::gui::IGUIComboBox* cbLFList;
//filter //filter
irr::gui::IGUIStaticText* wFilter; irr::gui::IGUIStaticText* wFilter;
irr::gui::IGUIScrollBar* scrFilter; irr::gui::IGUIScrollBar* scrFilter;
...@@ -568,6 +588,7 @@ extern Game* mainGame; ...@@ -568,6 +588,7 @@ extern Game* mainGame;
#define CHECKBOX_HP_READY 125 #define CHECKBOX_HP_READY 125
#define BUTTON_HP_READY 126 #define BUTTON_HP_READY 126
#define BUTTON_HP_NOTREADY 127 #define BUTTON_HP_NOTREADY 127
#define COMBOBOX_HP_CATEGORY 128
#define LISTBOX_REPLAY_LIST 130 #define LISTBOX_REPLAY_LIST 130
#define BUTTON_LOAD_REPLAY 131 #define BUTTON_LOAD_REPLAY 131
#define BUTTON_CANCEL_REPLAY 132 #define BUTTON_CANCEL_REPLAY 132
...@@ -656,8 +677,8 @@ extern Game* mainGame; ...@@ -656,8 +677,8 @@ extern Game* mainGame;
#define BUTTON_CARD_DISP_OK 296 #define BUTTON_CARD_DISP_OK 296
#define BUTTON_SURRENDER_YES 297 #define BUTTON_SURRENDER_YES 297
#define BUTTON_SURRENDER_NO 298 #define BUTTON_SURRENDER_NO 298
#define BUTTON_MANAGE_DECK 300
#define COMBOBOX_DBLFLIST 301 #define COMBOBOX_DBCATEGORY 301
#define COMBOBOX_DBDECKS 302 #define COMBOBOX_DBDECKS 302
#define BUTTON_CLEAR_DECK 303 #define BUTTON_CLEAR_DECK 303
#define BUTTON_SAVE_DECK 304 #define BUTTON_SAVE_DECK 304
...@@ -682,13 +703,26 @@ extern Game* mainGame; ...@@ -682,13 +703,26 @@ extern Game* mainGame;
#define BUTTON_MARKERS_OK 323 #define BUTTON_MARKERS_OK 323
#define COMBOBOX_SORTTYPE 324 #define COMBOBOX_SORTTYPE 324
#define WINDOW_DECK_MANAGE 330
#define BUTTON_NEW_CATEGORY 331
#define BUTTON_RENAME_CATEGORY 332
#define BUTTON_DELETE_CATEGORY 333
#define BUTTON_NEW_DECK 334
#define BUTTON_RENAME_DECK 335
#define BUTTON_DELETE_DECK_DM 336
#define BUTTON_MOVE_DECK 337
#define BUTTON_COPY_DECK 338
#define LISTBOX_CATEGORIES 339
#define LISTBOX_DECKS 340
#define BUTTON_DM_OK 341
#define BUTTON_DM_CANCEL 342
#define COMBOBOX_LFLIST 349
#define CHECKBOX_AUTO_SEARCH 360 #define CHECKBOX_AUTO_SEARCH 360
#define CHECKBOX_DRAW_FIELD_SPELL 361 #define CHECKBOX_DRAW_FIELD_SPELL 361
#define CHECKBOX_MULTI_KEYWORDS 372
#define CHECKBOX_PREFER_EXPANSION 373
#define CHECKBOX_DISABLE_CHAT 364 #define CHECKBOX_DISABLE_CHAT 364
//ygomobile function
#define BUTTON_RENAME_DECK 365
#define BUTTON_RENAME_DECK_SAVE 366
#define BUTTON_RENAME_DECK_CANCEL 367
#define CHECKBOX_QUICK_ANIMATION 369 #define CHECKBOX_QUICK_ANIMATION 369
#define SCROLL_TAB_HELPER 370 #define SCROLL_TAB_HELPER 370
#define SCROLL_TAB_SYSTEM 371 #define SCROLL_TAB_SYSTEM 371
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
namespace ygo { namespace ygo {
void UpdateDeck() { void UpdateDeck() {
BufferIO::CopyWStr(mainGame->cbCategorySelect->getItem(mainGame->cbCategorySelect->getSelected()),
mainGame->gameConf.lastcategory, 64);
BufferIO::CopyWStr(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()), BufferIO::CopyWStr(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()),
mainGame->gameConf.lastdeck, 64); mainGame->gameConf.lastdeck, 64);
...@@ -52,7 +54,6 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -52,7 +54,6 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
} }
switch(event.GUIEvent.EventType) { switch(event.GUIEvent.EventType) {
//dont merge these cases
case irr::gui::EGET_BUTTON_CLICKED: { case irr::gui::EGET_BUTTON_CLICKED: {
switch(id) { switch(id) {
case BUTTON_MODE_EXIT: { case BUTTON_MODE_EXIT: {
...@@ -180,18 +181,20 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -180,18 +181,20 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
} }
case BUTTON_HP_READY: { case BUTTON_HP_READY: {
mainGame->soundEffectPlayer->doPressButton(); mainGame->soundEffectPlayer->doPressButton();
if(mainGame->cbDeckSelect->getSelected() == -1 || if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()))) { !deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
break; break;
} }
UpdateDeck(); UpdateDeck();
DuelClient::SendPacketToServer(CTOS_HS_READY); DuelClient::SendPacketToServer(CTOS_HS_READY);
mainGame->cbCategorySelect->setEnabled(false);
mainGame->cbDeckSelect->setEnabled(false); mainGame->cbDeckSelect->setEnabled(false);
break; break;
} }
case BUTTON_HP_NOTREADY: { case BUTTON_HP_NOTREADY: {
mainGame->soundEffectPlayer->doPressButton(); mainGame->soundEffectPlayer->doPressButton();
DuelClient::SendPacketToServer(CTOS_HS_NOTREADY); DuelClient::SendPacketToServer(CTOS_HS_NOTREADY);
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true); mainGame->cbDeckSelect->setEnabled(true);
break; break;
} }
...@@ -295,42 +298,6 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -295,42 +298,6 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->ShowElement(mainGame->wMainMenu); mainGame->ShowElement(mainGame->wMainMenu);
break; break;
} }
case BUTTON_EXPORT_DECK: {
if(mainGame->lstReplayList->getSelected() == -1)
break;
Replay replay;
wchar_t ex_filename[256];
wchar_t namebuf[4][20];
wchar_t filename[256];
myswprintf(ex_filename, L"%ls", mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected()));
if(!replay.OpenReplay(ex_filename))
break;
const ReplayHeader& rh = replay.pheader;
if(rh.flag & REPLAY_SINGLE_MODE)
break;
int max = (rh.flag & REPLAY_TAG) ? 4 : 2;
//player name
for(int i = 0; i < max; ++i)
replay.ReadName(namebuf[i]);
//skip pre infos
for(int i = 0; i < 4; ++i)
replay.ReadInt32();
//deck
for(int i = 0; i < max; ++i) {
int main = replay.ReadInt32();
Deck tmp_deck;
for(int j = 0; j < main; ++j)
tmp_deck.main.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
int extra = replay.ReadInt32();
for(int j = 0; j < extra; ++j)
tmp_deck.extra.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
myswprintf(filename, L"%ls %ls", ex_filename, namebuf[i]);
deckManager.SaveDeck(tmp_deck, filename);
}
mainGame->stACMessage->setText(dataManager.GetSysString(1335));
mainGame->PopupElement(mainGame->wACMessage, 20);
break;
}
//TEST BOT MODE //TEST BOT MODE
case BUTTON_BOT_START: { case BUTTON_BOT_START: {
int sel = mainGame->lstBotList->getSelected(); int sel = mainGame->lstBotList->getSelected();
...@@ -417,11 +384,12 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -417,11 +384,12 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
} }
case BUTTON_DECK_EDIT: { case BUTTON_DECK_EDIT: {
mainGame->RefreshCategoryDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->soundEffectPlayer->doPressButton(); mainGame->soundEffectPlayer->doPressButton();
mainGame->RefreshDeck(mainGame->cbDBDecks); if(mainGame->cbDBCategory->getSelected() != -1 && mainGame->cbDBDecks->getSelected() != -1) {
if(mainGame->cbDBDecks->getSelected() != -1) deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadDeck(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()));
mainGame->ebDeckname->setText(L""); mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu); mainGame->HideElement(mainGame->wMainMenu);
mainGame->deckBuilder.Initialize(); mainGame->deckBuilder.Initialize();
break; break;
...@@ -574,6 +542,23 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -574,6 +542,23 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
} }
break; break;
} }
case irr::gui::EGET_COMBO_BOX_CHANGED: {
switch(id) {
case COMBOBOX_HP_CATEGORY: {
int catesel = mainGame->cbCategorySelect->getSelected();
if(catesel == 3) {
catesel = 2;
mainGame->cbCategorySelect->setSelected(2);
}
if(catesel >= 0) {
mainGame->RefreshDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
mainGame->cbDeckSelect->setSelected(0);
}
break;
}
}
break;
}
case irr::gui::EGET_CHECKBOX_CHANGED: { case irr::gui::EGET_CHECKBOX_CHANGED: {
switch(id) { switch(id) {
case CHECKBOX_HP_READY: { case CHECKBOX_HP_READY: {
...@@ -581,16 +566,18 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -581,16 +566,18 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
mainGame->env->setFocus(mainGame->wHostPrepare); mainGame->env->setFocus(mainGame->wHostPrepare);
if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) { if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) {
if(mainGame->cbDeckSelect->getSelected() == -1 || if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()))) { !deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false); static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false);
break; break;
} }
UpdateDeck(); UpdateDeck();
DuelClient::SendPacketToServer(CTOS_HS_READY); DuelClient::SendPacketToServer(CTOS_HS_READY);
mainGame->cbCategorySelect->setEnabled(false);
mainGame->cbDeckSelect->setEnabled(false); mainGame->cbDeckSelect->setEnabled(false);
} else { } else {
DuelClient::SendPacketToServer(CTOS_HS_NOTREADY); DuelClient::SendPacketToServer(CTOS_HS_NOTREADY);
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true); mainGame->cbDeckSelect->setEnabled(true);
} }
break; break;
......
...@@ -50,6 +50,37 @@ public: ...@@ -50,6 +50,37 @@ public:
return MakeDir(wdir); return MakeDir(wdir);
} }
static bool Rename(const wchar_t* woldname, const wchar_t* wnewname) {
return MoveFileW(woldname, wnewname);
}
static bool Rename(const char* oldname, const char* newname) {
wchar_t woldname[1024];
wchar_t wnewname[1024];
BufferIO::DecodeUTF8(oldname, woldname);
BufferIO::DecodeUTF8(newname, wnewname);
return Rename(woldname, wnewname);
}
static bool DeleteDir(const wchar_t* wdir) {
wchar_t pdir[256];
BufferIO::CopyWStr(wdir, pdir, 256);
pdir[wcslen(wdir) + 1] = 0;
SHFILEOPSTRUCTW lpFileOp;
lpFileOp.hwnd = NULL;
lpFileOp.wFunc = FO_DELETE;
lpFileOp.pFrom = pdir;
lpFileOp.pTo = 0;
lpFileOp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
return SHFileOperationW(&lpFileOp) == 0;
}
static bool DeleteDir(const char* dir) {
wchar_t wdir[1024];
BufferIO::DecodeUTF8(dir, wdir);
return DeleteDir(wdir);
}
static void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) { static void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) {
wchar_t findstr[1024]; wchar_t findstr[1024];
wcscpy(findstr, wpath); wcscpy(findstr, wpath);
...@@ -59,7 +90,8 @@ public: ...@@ -59,7 +90,8 @@ public:
if(fh == INVALID_HANDLE_VALUE) if(fh == INVALID_HANDLE_VALUE)
return; return;
do { do {
cb(fdataw.cFileName, (fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); if(mywcsncasecmp(fdataw.cFileName, L".", 1) && mywcsncasecmp(fdataw.cFileName, L"..", 2))
cb(fdataw.cFileName, (fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
} while(FindNextFileW(fh, &fdataw)); } while(FindNextFileW(fh, &fdataw));
FindClose(fh); FindClose(fh);
} }
...@@ -110,6 +142,48 @@ public: ...@@ -110,6 +142,48 @@ public:
BufferIO::EncodeUTF8(wdir, dir); BufferIO::EncodeUTF8(wdir, dir);
return MakeDir(dir); return MakeDir(dir);
} }
static bool Rename(const wchar_t* woldname, const wchar_t* wnewname) {
char oldname[1024];
char newname[1024];
BufferIO::EncodeUTF8(woldname, oldname);
BufferIO::EncodeUTF8(wnewname, newname);
return Rename(oldname, newname);
}
static bool Rename(const char* oldname, const char* newname) {
return rename(oldname, newname) == 0;
}
static bool DeleteDir(const wchar_t* wdir) {
char dir[1024];
BufferIO::EncodeUTF8(wdir, dir);
return DeleteDir(dir);
}
static bool DeleteDir(const char* dir) {
bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
return;
char full_path[256];
sprintf(full_path, "%s/%s", dir, name);
if (isdir)
{
if(!DeleteDir(full_path))
success = false;
}
else
{
if(unlink(full_path) != 0)
success = false;
}
});
if (rmdir(dir) != 0)
success = false;
return success;
}
struct file_unit { struct file_unit {
std::string filename; std::string filename;
...@@ -132,6 +206,8 @@ public: ...@@ -132,6 +206,8 @@ public:
stat(fname, &fileStat); stat(fname, &fileStat);
funit.filename = std::string(dirp->d_name); funit.filename = std::string(dirp->d_name);
funit.is_dir = S_ISDIR(fileStat.st_mode); funit.is_dir = S_ISDIR(fileStat.st_mode);
if(funit.is_dir && (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0))
continue;
file_list.push_back(funit); file_list.push_back(funit);
} }
closedir(dir); closedir(dir);
......
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