Commit adaf3342 authored by nanahira's avatar nanahira

Merge branch 'patch-deck-category' of github.com:mercury233/ygopro into deckmg

parents 14c879d7 9806dea0
This diff is collapsed.
......@@ -60,10 +60,12 @@ public:
size_t pre_extrac;
size_t pre_sidec;
code_pointer draging_pointer;
int prev_category;
int prev_deck;
s32 prev_operation;
int prev_sel;
bool is_modified;
bool readonly;
std::unordered_map<int, int>* filterList;
std::vector<code_pointer> results;
......
......@@ -192,6 +192,37 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
deck = ndeck;
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, mainGame->gameConf.bot_deck_path);
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) {
#ifdef WIN32
FILE* fp = _wfopen(file, (wchar_t*)mode);
......@@ -204,11 +235,11 @@ FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
}
bool DeckManager::LoadDeck(const wchar_t* file) {
int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
wchar_t localfile[64];
myswprintf(localfile, L"./deck/%ls.ydk", file);
FILE* fp = OpenDeckFile(localfile, "r");
FILE* fp = OpenDeckFile(file, "r");
if(!fp) {
fp = OpenDeckFile(file, "r");
wchar_t localfile[64];
myswprintf(localfile, L"./deck/%ls.ydk", file);
fp = OpenDeckFile(localfile, "r");
}
if(!fp)
return false;
......@@ -234,11 +265,9 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
LoadDeck(current_deck, cardlist, mainc, sidec);
return true;
}
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* file) {
if(!FileSystem::IsDirExists(L"./deck") && !FileSystem::MakeDir(L"./deck"))
return false;
wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name);
FILE* fp = OpenDeckFile(file, "w");
if(!fp)
return false;
......@@ -254,9 +283,7 @@ bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
fclose(fp);
return true;
}
bool DeckManager::DeleteDeck(Deck& deck, const wchar_t* name) {
wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name);
bool DeckManager::DeleteDeck(const wchar_t* file) {
#ifdef WIN32
BOOL result = DeleteFileW(file);
return !!result;
......@@ -301,4 +328,31 @@ int DeckManager::SaveDeckToCode(Deck& deck, char* code) {
Base64::Encode(deckbuf, len, code, encoded_len);
return encoded_len;
}
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);
}
}
......@@ -41,14 +41,20 @@ public:
int CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
int LoadDeck(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);
bool LoadDeck(const wchar_t* file);
bool SaveDeck(Deck& deck, const wchar_t* name);
bool DeleteDeck(Deck& deck, const wchar_t* name);
bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(const wchar_t* file);
wchar_t DeckFormatBuffer[128];
int TypeCount(std::vector<code_pointer> list, unsigned int ctype);
bool LoadDeckFromCode(Deck& deck, const char *code, int len);
int SaveDeckToCode(Deck &deck, char *code);
bool CreateCategory(const wchar_t* name);
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name);
};
extern DeckManager deckManager;
......
......@@ -325,6 +325,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
}
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->env->addMessageBox(L"", msgbuf);
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true);
mainGame->gMutex.Unlock();
break;
......@@ -552,7 +553,8 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->stHostPrepDuelist[3]->setText(L"");
mainGame->stHostPrepOB->setText(L"");
mainGame->SetStaticText(mainGame->stHostPrepRule, 180, mainGame->guiFont, str.c_str());
mainGame->RefreshDeck(mainGame->cbDeckSelect);
mainGame->RefreshCategoryDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true);
if(mainGame->wCreateHost->isVisible())
mainGame->HideElement(mainGame->wCreateHost);
......
This diff is collapsed.
......@@ -22,11 +22,13 @@ struct Config {
wchar_t lastport[10];
wchar_t nickname[20];
wchar_t gamename[20];
wchar_t lastcategory[64];
wchar_t lastdeck[64];
wchar_t textfont[256];
wchar_t numfont[256];
wchar_t roompass[20];
wchar_t locale[64];
wchar_t bot_deck_path[64];
//settings
int chkMAutoPos;
int chkSTAutoPos;
......@@ -130,7 +132,9 @@ public:
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 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 RefreshSingleplay();
void RefreshBot();
......@@ -365,6 +369,7 @@ public:
irr::gui::IGUIStaticText* stHostPrepDuelist[4];
irr::gui::IGUICheckBox* chkHostPrepReady[4];
irr::gui::IGUIButton* btnHostPrepKick[4];
irr::gui::IGUIComboBox* cbCategorySelect;
irr::gui::IGUIComboBox* cbDeckSelect;
irr::gui::IGUIStaticText* stHostPrepRule;
irr::gui::IGUIStaticText* stHostPrepOB;
......@@ -488,8 +493,9 @@ public:
irr::gui::IGUIButton* btnEP;
//deck edit
irr::gui::IGUIStaticText* wDeckEdit;
irr::gui::IGUIComboBox* cbDBLFList;
irr::gui::IGUIComboBox* cbDBCategory;
irr::gui::IGUIComboBox* cbDBDecks;
irr::gui::IGUIButton* btnManageDeck;
irr::gui::IGUIButton* btnClearDeck;
irr::gui::IGUIButton* btnSortDeck;
irr::gui::IGUIButton* btnShuffleDeck;
......@@ -501,7 +507,6 @@ public:
irr::gui::IGUIButton* btnSideSort;
irr::gui::IGUIButton* btnSideReload;
irr::gui::IGUIEditBox* ebDeckname;
irr::gui::IGUIButton* btnRenameDeck;
irr::gui::IGUIButton* btnDeckCode;
//deck rename
irr::gui::IGUIWindow* wRenameDeck;
......@@ -514,7 +519,7 @@ public:
irr::gui::IGUIButton* btnDeckCodeYes;
irr::gui::IGUIButton* btnDeckCodeNo;
//
irr::gui::IGUIStaticText* stBanlist;
irr::gui::IGUIStaticText* stDBCategory;
irr::gui::IGUIStaticText* stDeck;
irr::gui::IGUIStaticText* stCategory;
irr::gui::IGUIStaticText* stLimit;
......@@ -525,6 +530,26 @@ public:
irr::gui::IGUIStaticText* stStar;
irr::gui::IGUIStaticText* stSearch;
irr::gui::IGUIStaticText* stScale;
//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* btnDMDeleteDeck;
irr::gui::IGUIButton* btnMoveDeck;
irr::gui::IGUIButton* btnCopyDeck;
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
irr::gui::IGUIStaticText* wFilter;
irr::gui::IGUIScrollBar* scrFilter;
......@@ -622,6 +647,7 @@ extern Game* mainGame;
#define CHECKBOX_HP_READY 125
#define BUTTON_HP_READY 126
#define BUTTON_HP_NOTREADY 127
#define COMBOBOX_HP_CATEGORY 128
#define LISTBOX_REPLAY_LIST 130
#define BUTTON_LOAD_REPLAY 131
#define BUTTON_CANCEL_REPLAY 132
......@@ -711,7 +737,9 @@ extern Game* mainGame;
#define BUTTON_SURRENDER_YES 297
#define BUTTON_SURRENDER_NO 298
#define COMBOBOX_DBLFLIST 301
#define BUTTON_MANAGE_DECK 300
#define COMBOBOX_DBCATEGORY 301
#define COMBOBOX_DBDECKS 302
#define BUTTON_CLEAR_DECK 303
#define BUTTON_SAVE_DECK 304
......@@ -735,6 +763,22 @@ extern Game* mainGame;
#define BUTTON_MARKS_FILTER 322
#define BUTTON_MARKERS_OK 323
#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_ENABLE_SOUND 361
#define CHECKBOX_ENABLE_MUSIC 362
......@@ -752,10 +796,6 @@ extern Game* mainGame;
#define CHECKBOX_REGEX 374
#define COMBOBOX_LOCALE 375
#define BUTTON_RENAME_DECK 386
#define BUTTON_RENAME_DECK_SAVE 387
#define BUTTON_RENAME_DECK_CANCEL 388
#define BUTTON_DECK_CODE 389
#define BUTTON_DECK_CODE_SAVE 390
#define BUTTON_DECK_CODE_CANCEL 391
......
......@@ -115,6 +115,7 @@ int main(int argc, char* argv[]) {
} else if(!wcscmp(wargv[i], L"-d")) { // Deck
++i;
if(i + 1 < wargc) { // select deck
ygo::mainGame->gameConf.lastcategory[0] = 0;
wcscpy(ygo::mainGame->gameConf.lastdeck, wargv[i]);
continue;
} else { // open deck
......
......@@ -12,6 +12,8 @@
namespace ygo {
void UpdateDeck() {
BufferIO::CopyWStr(mainGame->cbCategorySelect->getItem(mainGame->cbCategorySelect->getSelected()),
mainGame->gameConf.lastcategory, 64);
BufferIO::CopyWStr(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()),
mainGame->gameConf.lastdeck, 64);
char deckbuf[1024];
......@@ -141,6 +143,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_HP_DUELIST: {
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true);
DuelClient::SendPacketToServer(CTOS_HS_TODUELIST);
break;
......@@ -162,17 +165,19 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_HP_READY: {
if(mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()))) {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
break;
}
UpdateDeck();
DuelClient::SendPacketToServer(CTOS_HS_READY);
mainGame->cbCategorySelect->setEnabled(false);
mainGame->cbDeckSelect->setEnabled(false);
break;
}
case BUTTON_HP_NOTREADY: {
DuelClient::SendPacketToServer(CTOS_HS_NOTREADY);
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true);
break;
}
......@@ -374,7 +379,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_DECK_EDIT: {
mainGame->RefreshDeck(mainGame->cbDBDecks);
mainGame->RefreshCategoryDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
if(open_file && deckManager.LoadDeck(open_file_name)) {
#ifdef WIN32
wchar_t *dash = wcsrchr(open_file_name, L'\\');
......@@ -397,8 +402,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
}
open_file = false;
} else if(mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadDeck(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()));
} else if(mainGame->cbDBCategory->getSelected() != -1 && mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu);
......@@ -557,6 +562,23 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
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: {
switch(id) {
case CHECKBOX_HP_READY: {
......@@ -564,16 +586,18 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
mainGame->env->setFocus(mainGame->wHostPrepare);
if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) {
if(mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()))) {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false);
break;
}
UpdateDeck();
DuelClient::SendPacketToServer(CTOS_HS_READY);
mainGame->cbCategorySelect->setEnabled(false);
mainGame->cbDeckSelect->setEnabled(false);
} else {
DuelClient::SendPacketToServer(CTOS_HS_NOTREADY);
mainGame->cbCategorySelect->setEnabled(true);
mainGame->cbDeckSelect->setEnabled(true);
}
break;
......
......@@ -50,6 +50,31 @@ public:
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 void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) {
wchar_t findstr[1024];
wcscpy(findstr, wpath);
......@@ -59,7 +84,8 @@ public:
if(fh == INVALID_HANDLE_VALUE)
return;
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));
FindClose(fh);
}
......
......@@ -340,7 +340,7 @@
!system 1297 切洗手卡
!system 1298 辅助功能
!system 1299 加快动画效果
!system 1300 禁限卡表
!system 1300 卡组分类
!system 1301 卡组列表:
!system 1302 保存
!system 1303 另存
......@@ -367,6 +367,7 @@
!system 1325 关键字:
!system 1326 效果
!system 1327 搜索
!system 1328 管理
!system 1329 系列:
!system 1330 主卡组:
!system 1331 额外卡组:
......@@ -447,6 +448,27 @@
!system 1419 副卡组数量应不超过15张,当前卡组数量为%d张。
!system 1420 有额外卡组卡片存在于主卡组,可能是额外卡组数量超过15张。
!system 1421 宣言的卡不符合条件,或无法被主机识别。
!system 1450 卡包展示
!system 1451 人机卡组
!system 1452 未分类卡组
!system 1453 --------
!system 1460 卡组管理
!system 1461 新建分类
!system 1462 重命名分类
!system 1463 删除分类
!system 1464 新建卡组
!system 1465 重命名卡组
!system 1466 删除卡组
!system 1467 移动到分类
!system 1468 复制到分类
!system 1469 请输入分类名:
!system 1470 确实要删除此分类和分类下全部卡组吗?
!system 1471 请输入卡组名:
!system 1472 请选择要移动到的分类:
!system 1473 请选择要复制到的分类:
!system 1474 已存在同名分类
!system 1475 已存在同名卡组
!system 1476 删除失败
!system 1500 决斗结束。
!system 1501 录像结束。
!system 1502 连接已断开。
......
......@@ -32,8 +32,9 @@ auto_search_limit = 2
search_multiple_keywords = 1
search_regex = 0
ignore_deck_changes = 0
default_ot = 1
default_ot = ./windbot/decks
enable_bot_mode = 1
bot_deck_path =
quick_animation = 1
auto_save_replay = 1
window_maximized = 0
......
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