Commit 2fa138f1 authored by DailyShana's avatar DailyShana

Merge #1900

parents 9449eec5 f35ecc7d
...@@ -73,5 +73,7 @@ using namespace gui; ...@@ -73,5 +73,7 @@ using namespace gui;
extern const unsigned short PRO_VERSION; extern const unsigned short PRO_VERSION;
extern int enable_log; extern int enable_log;
extern bool exit_on_return; extern bool exit_on_return;
extern bool open_file;
extern wchar_t open_file_name[256];
#endif #endif
...@@ -88,7 +88,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -88,7 +88,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break; break;
} }
case BUTTON_SAVE_DECK: { case BUTTON_SAVE_DECK: {
if(deckManager.SaveDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()))) { int sel = mainGame->cbDBDecks->getSelected();
if(sel>-1 && deckManager.SaveDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(sel))) {
mainGame->stACMessage->setText(dataManager.GetSysString(1335)); mainGame->stACMessage->setText(dataManager.GetSysString(1335));
mainGame->PopupElement(mainGame->wACMessage, 20); mainGame->PopupElement(mainGame->wACMessage, 20);
} }
......
...@@ -168,21 +168,28 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) { ...@@ -168,21 +168,28 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
deck = ndeck; deck = ndeck;
return true; return true;
} }
bool DeckManager::LoadDeck(const wchar_t* file) { FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
wchar_t deck[64];
myswprintf(deck, L"./deck/%ls.ydk", file);
int cardlist[128];
bool is_side = false;
#ifdef WIN32 #ifdef WIN32
FILE* fp = _wfopen(deck, L"r"); FILE* fp = _wfopen(file, (wchar_t*)mode);
#else #else
char deckfn[256]; char file2[256];
BufferIO::EncodeUTF8(deck, deckfn); BufferIO::EncodeUTF8(file, file2);
FILE* fp = fopen(deckfn, "r"); FILE* fp = fopen(file2, mode);
#endif #endif
return fp;
}
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");
if(!fp) {
fp = OpenDeckFile(file, "r");
}
if(!fp) if(!fp)
return false; return false;
int cardlist[128];
bool is_side = false;
char linebuf[256]; char linebuf[256];
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
int fsize = ftell(fp); int fsize = ftell(fp);
...@@ -211,13 +218,7 @@ bool DeckManager::LoadDeck(const wchar_t* file) { ...@@ -211,13 +218,7 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) { bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
wchar_t file[64]; wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name); myswprintf(file, L"./deck/%ls.ydk", name);
#ifdef WIN32 FILE* fp = OpenDeckFile(file, "w");
FILE* fp = _wfopen(file, L"w");
#else
char filefn[256];
BufferIO::EncodeUTF8(file, filefn);
FILE* fp = fopen(filefn, "w");
#endif
if(!fp) if(!fp)
return false; return false;
fprintf(fp, "#created by ...\n#main\n"); fprintf(fp, "#created by ...\n#main\n");
......
...@@ -40,6 +40,7 @@ public: ...@@ -40,6 +40,7 @@ public:
int CheckLFList(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg); int CheckLFList(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
void LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec); void 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);
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* name);
bool DeleteDeck(Deck& deck, const wchar_t* name); bool DeleteDeck(Deck& deck, const wchar_t* name);
......
...@@ -5,6 +5,34 @@ ...@@ -5,6 +5,34 @@
int enable_log = 0; int enable_log = 0;
bool exit_on_return = false; bool exit_on_return = false;
bool open_file = false;
wchar_t open_file_name[256] = L"";
void GetParameter(char* param, const char* arg) {
#ifdef _WIN32
wchar_t arg1[260];
MultiByteToWideChar(CP_ACP, 0, arg, -1, arg1, 260);
BufferIO::EncodeUTF8(arg1, param);
#else
strcpy(param, arg1);
#endif
}
void GetParameterW(wchar_t* param, const char* arg) {
#ifdef _WIN32
MultiByteToWideChar(CP_ACP, 0, arg, -1, param, 260);
#else
BufferIO::DecodeUTF8(arg, param);
#endif
}
void ClickButton(irr::gui::IGUIElement* btn) {
irr::SEvent event;
event.EventType = irr::EET_GUI_EVENT;
event.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED;
event.GUIEvent.Caller = btn;
ygo::mainGame->device->postEventFromUser(event);
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
#ifdef _WIN32 #ifdef _WIN32
...@@ -22,47 +50,64 @@ int main(int argc, char* argv[]) { ...@@ -22,47 +50,64 @@ int main(int argc, char* argv[]) {
return 0; return 0;
for(int i = 1; i < argc; ++i) { for(int i = 1; i < argc; ++i) {
/*command line args: if(!strcmp(argv[i], "-e")) { // extra database
* -j: join host (host info from system.conf) ++i;
* -d: deck edit char param[128];
* -r: replay */ GetParameter(param, &argv[i][0]);
if(argv[i][0] == '-' && argv[i][1] == 'e') { ygo::dataManager.LoadDB(param);
#ifdef _WIN32 } else if(!strcmp(argv[i], "-n")) { // nickName
wchar_t fname[260]; ++i;
MultiByteToWideChar(CP_ACP, 0, &argv[i][2], -1, fname, 260); wchar_t param[128];
char fname2[260]; GetParameterW(param, &argv[i][0]);
BufferIO::EncodeUTF8(fname, fname2); ygo::mainGame->ebNickName->setText(param);
ygo::dataManager.LoadDB(fname2); } else if(!strcmp(argv[i], "-h")) { // Host address
#else ++i;
ygo::dataManager.LoadDB(&argv[i][2]); wchar_t param[128];
#endif GetParameterW(param, &argv[i][0]);
} else if(!strcmp(argv[i], "-j") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-r") || !strcmp(argv[i], "-s")) { ygo::mainGame->ebJoinIP->setText(param);
} else if(!strcmp(argv[i], "-p")) { // host Port
++i;
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinPort->setText(param);
} else if(!strcmp(argv[i], "-w")) { // host passWord
++i;
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinPass->setText(param);
} else if(!strcmp(argv[i], "-x")) { // eXit on return
exit_on_return = true; exit_on_return = true;
irr::SEvent event; } else if(!strcmp(argv[i], "-j")) { // Join host
event.EventType = irr::EET_GUI_EVENT; ClickButton(ygo::mainGame->btnLanMode);
event.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED; ClickButton(ygo::mainGame->btnJoinHost);
if(!strcmp(argv[i], "-j")) { break;
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu); } else if(!strcmp(argv[i], "-d")) { // Deck
event.GUIEvent.Caller = ygo::mainGame->btnJoinHost; if(i < argc) {
ygo::mainGame->device->postEventFromUser(event); open_file = true;
} else if(!strcmp(argv[i], "-d")) { GetParameterW(open_file_name, &argv[i + 1][0]);
event.GUIEvent.Caller = ygo::mainGame->btnDeckEdit;
ygo::mainGame->device->postEventFromUser(event);
} else if(!strcmp(argv[i], "-r")) {
event.GUIEvent.Caller = ygo::mainGame->btnReplayMode;
ygo::mainGame->device->postEventFromUser(event);
ygo::mainGame->lstReplayList->setSelected(0);
event.GUIEvent.Caller = ygo::mainGame->btnLoadReplay;
ygo::mainGame->device->postEventFromUser(event);
} else if(!strcmp(argv[i], "-s")) {
event.GUIEvent.Caller = ygo::mainGame->btnServerMode;
ygo::mainGame->device->postEventFromUser(event);
ygo::mainGame->lstSinglePlayList->setSelected(0);
event.GUIEvent.Caller = ygo::mainGame->btnLoadSinglePlay;
ygo::mainGame->device->postEventFromUser(event);
} }
ClickButton(ygo::mainGame->btnDeckEdit);
break;
} else if(!strcmp(argv[i], "-r")) { // Replay
if(i < argc) {
open_file = true;
GetParameterW(open_file_name, &argv[i + 1][0]);
}
ClickButton(ygo::mainGame->btnReplayMode);
if(open_file)
ClickButton(ygo::mainGame->btnLoadReplay);
break;
} else if(!strcmp(argv[i], "-s")) { // Single
if(i < argc) {
open_file = true;
GetParameterW(open_file_name, &argv[i + 1][0]);
}
ClickButton(ygo::mainGame->btnServerMode);
if(open_file)
ClickButton(ygo::mainGame->btnLoadSinglePlay);
break;
} }
} }
ygo::mainGame->MainLoop(); ygo::mainGame->MainLoop();
#ifdef _WIN32 #ifdef _WIN32
......
...@@ -74,6 +74,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -74,6 +74,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
case BUTTON_JOIN_CANCEL: { case BUTTON_JOIN_CANCEL: {
mainGame->HideElement(mainGame->wLanWindow); mainGame->HideElement(mainGame->wLanWindow);
mainGame->ShowElement(mainGame->wMainMenu); mainGame->ShowElement(mainGame->wMainMenu);
if(exit_on_return)
mainGame->device->closeDevice();
break; break;
} }
case BUTTON_LAN_REFRESH: { case BUTTON_LAN_REFRESH: {
...@@ -160,10 +162,15 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -160,10 +162,15 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
} }
case BUTTON_LOAD_REPLAY: { case BUTTON_LOAD_REPLAY: {
if(mainGame->lstReplayList->getSelected() == -1) if(open_file) {
break; ReplayMode::cur_replay.OpenReplay(open_file_name);
if(!ReplayMode::cur_replay.OpenReplay(mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected()))) open_file = false;
break; } else {
if(mainGame->lstReplayList->getSelected() == -1)
break;
if(!ReplayMode::cur_replay.OpenReplay(mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected())))
break;
}
mainGame->imgCard->setImage(imageManager.tCover[0]); mainGame->imgCard->setImage(imageManager.tCover[0]);
mainGame->wCardImg->setVisible(true); mainGame->wCardImg->setVisible(true);
mainGame->wInfos->setVisible(true); mainGame->wInfos->setVisible(true);
...@@ -198,7 +205,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -198,7 +205,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
} }
case BUTTON_LOAD_SINGLEPLAY: { case BUTTON_LOAD_SINGLEPLAY: {
if(mainGame->lstSinglePlayList->getSelected() == -1) if(!open_file && mainGame->lstSinglePlayList->getSelected() == -1)
break; break;
mainGame->singleSignal.SetNoWait(false); mainGame->singleSignal.SetNoWait(false);
SingleMode::StartPlay(); SingleMode::StartPlay();
...@@ -211,8 +218,32 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -211,8 +218,32 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
} }
case BUTTON_DECK_EDIT: { case BUTTON_DECK_EDIT: {
mainGame->RefreshDeck(mainGame->cbDBDecks); mainGame->RefreshDeck(mainGame->cbDBDecks);
if(mainGame->cbDBDecks->getSelected() != -1) if(open_file && deckManager.LoadDeck(open_file_name)) {
#ifdef WIN32
wchar_t *dash = wcsrchr(open_file_name, L'\\');
#else
wchar_t *dash = wcsrchr(open_file_name, L'/');
#endif
wchar_t *dot = wcsrchr(open_file_name, L'.');
if(dash && dot) {
wchar_t deck_name[256];
wcsncpy(deck_name, dash + 1, dot - dash - 1);
deck_name[dot - dash - 1] = L'\0';
mainGame->ebDeckname->setText(deck_name);
mainGame->cbDBDecks->setSelected(-1);
} else {
for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) {
if(!wcscmp(mainGame->cbDBDecks->getItem(i), open_file_name)) {
mainGame->cbDBDecks->setSelected(i);
break;
}
}
}
open_file = false;
} else if(mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadDeck(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected())); deckManager.LoadDeck(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()));
mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu); mainGame->HideElement(mainGame->wMainMenu);
mainGame->is_building = true; mainGame->is_building = true;
mainGame->is_siding = false; mainGame->is_siding = false;
......
...@@ -139,15 +139,24 @@ void Replay::SaveReplay(const wchar_t* name) { ...@@ -139,15 +139,24 @@ void Replay::SaveReplay(const wchar_t* name) {
fclose(fp); fclose(fp);
} }
bool Replay::OpenReplay(const wchar_t* name) { bool Replay::OpenReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
#ifdef WIN32 #ifdef WIN32
fp = _wfopen(fname, L"rb"); fp = _wfopen(name, L"rb");
#else #else
char fname2[256]; char name2[256];
BufferIO::EncodeUTF8(fname, fname2); BufferIO::EncodeUTF8(name, name2);
fp = fopen(fname2, "rb"); fp = fopen(name2, "rb");
#endif #endif
if(!fp) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
#ifdef WIN32
fp = _wfopen(fname, L"rb");
#else
char fname2[256];
BufferIO::EncodeUTF8(fname, fname2);
fp = fopen(fname2, "rb");
#endif
}
if(!fp) if(!fp)
return false; return false;
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
......
...@@ -185,6 +185,8 @@ int ReplayMode::ReplayThread(void* param) { ...@@ -185,6 +185,8 @@ int ReplayMode::ReplayThread(void* param) {
mainGame->ShowElement(mainGame->wReplay); mainGame->ShowElement(mainGame->wReplay);
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock(); mainGame->gMutex.Unlock();
if(exit_on_return)
mainGame->device->closeDevice();
} }
return 0; return 0;
} }
......
...@@ -29,11 +29,17 @@ void SingleMode::SetResponse(unsigned char* resp) { ...@@ -29,11 +29,17 @@ void SingleMode::SetResponse(unsigned char* resp) {
set_responseb(pduel, resp); set_responseb(pduel, resp);
} }
int SingleMode::SinglePlayThread(void* param) { int SingleMode::SinglePlayThread(void* param) {
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(mainGame->lstSinglePlayList->getSelected());
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
char fname2[256]; char fname2[256];
size_t slen = BufferIO::EncodeUTF8(fname, fname2); size_t slen;
if(open_file) {
slen = BufferIO::EncodeUTF8(open_file_name, fname2);
open_file = false;
} else {
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(mainGame->lstSinglePlayList->getSelected());
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
slen = BufferIO::EncodeUTF8(fname, fname2);
}
mtrandom rnd; mtrandom rnd;
time_t seed = time(0); time_t seed = time(0);
rnd.reset(seed); rnd.reset(seed);
...@@ -103,6 +109,8 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -103,6 +109,8 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->ShowElement(mainGame->wSinglePlay); mainGame->ShowElement(mainGame->wSinglePlay);
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock(); mainGame->gMutex.Unlock();
if(exit_on_return)
mainGame->device->closeDevice();
} }
return 0; return 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