Commit 6edbb6d4 authored by mercury233's avatar mercury233

Merge branch 'master' of https://github.com/Fluorohydride/ygopro

parents 721a7ca7 0e7a5dc8
......@@ -1183,11 +1183,10 @@ bool ClientField::ShowSelectSum(bool panelmode) {
}
bool ClientField::CheckSelectSum() {
std::set<ClientCard*> selable;
std::set<ClientCard*>::iterator sit;
for(size_t i = 0; i < selectsum_all.size(); ++i) {
selectsum_all[i]->is_selectable = false;
selectsum_all[i]->is_selected = false;
selable.insert(selectsum_all[i]);
for(auto sit = selectsum_all.begin(); sit != selectsum_all.end(); ++sit) {
(*sit)->is_selectable = false;
(*sit)->is_selected = false;
selable.insert(*sit);
}
for(size_t i = 0; i < selected_cards.size(); ++i) {
if((int)i < must_select_count)
......@@ -1201,34 +1200,37 @@ bool ClientField::CheckSelectSum() {
if (select_mode == 0) {
bool ret = check_sel_sum_s(selable, 0, select_sumval);
selectable_cards.clear();
for(sit = selectsum_cards.begin(); sit != selectsum_cards.end(); ++sit) {
for(auto sit = selectsum_cards.begin(); sit != selectsum_cards.end(); ++sit) {
(*sit)->is_selectable = true;
selectable_cards.push_back(*sit);
}
return ret;
} else {
int op1, op2, mm = -1, ms, m, max = 0, sumc = 0, sums;
int mm = -1, mx = -1, max = 0, sumc = 0;
bool ret = false;
for (size_t i = 0; i < selected_cards.size(); ++i) {
op1 = selected_cards[i]->opParam & 0xffff;
op2 = selected_cards[i]->opParam >> 16;
m = (op2 > 0 && op1 > op2) ? op2 : op1;
max += op2 > op1 ? op2 : op1;
if (mm == -1 || m < mm)
mm = m;
sumc += m;
for (auto sit = selected_cards.begin(); sit != selected_cards.end(); ++sit) {
int op1 = (*sit)->opParam & 0xffff;
int op2 = (*sit)->opParam >> 16;
int opmin = (op2 > 0 && op1 > op2) ? op2 : op1;
int opmax = op2 > op1 ? op2 : op1;
if (mm == -1 || opmin < mm)
mm = opmin;
if (mx == -1 || opmax < mx)
mx = opmax;
sumc += opmin;
max += opmax;
}
if (select_sumval <= sumc)
return true;
if (select_sumval <= max)
if (select_sumval <= max && select_sumval > max - mx)
ret = true;
for(sit = selable.begin(); sit != selable.end(); ++sit) {
op1 = (*sit)->opParam & 0xffff;
op2 = (*sit)->opParam >> 16;
m = op1;
sums = sumc;
for(auto sit = selable.begin(); sit != selable.end(); ++sit) {
int op1 = (*sit)->opParam & 0xffff;
int op2 = (*sit)->opParam >> 16;
int m = op1;
int sums = sumc;
sums += m;
ms = mm;
int ms = mm;
if (ms == -1 || m < ms)
ms = m;
if (sums >= select_sumval) {
......@@ -1259,14 +1261,14 @@ bool ClientField::CheckSelectSum() {
}
}
selectable_cards.clear();
for(sit = selectsum_cards.begin(); sit != selectsum_cards.end(); ++sit) {
for(auto sit = selectsum_cards.begin(); sit != selectsum_cards.end(); ++sit) {
(*sit)->is_selectable = true;
selectable_cards.push_back(*sit);
}
return ret;
}
}
bool ClientField::check_min(std::set<ClientCard*>& left, std::set<ClientCard*>::iterator index, int min, int max) {
bool ClientField::check_min(const std::set<ClientCard*>& left, std::set<ClientCard*>::const_iterator index, int min, int max) {
if (index == left.end())
return false;
int op1 = (*index)->opParam & 0xffff;
......
......@@ -102,7 +102,7 @@ public:
void FadeCard(ClientCard* pcard, int alpha, int frame);
bool ShowSelectSum(bool panelmode);
bool CheckSelectSum();
bool check_min(std::set<ClientCard*>& left, std::set<ClientCard*>::iterator index, int min, int max);
bool check_min(const std::set<ClientCard*>& left, std::set<ClientCard*>::const_iterator index, int min, int max);
bool check_sel_sum_s(const std::set<ClientCard*>& left, int index, int acc);
void check_sel_sum_t(const std::set<ClientCard*>& left, int acc);
bool check_sum(std::set<ClientCard*>::const_iterator index, std::set<ClientCard*>::const_iterator end, int acc, int count);
......
......@@ -78,5 +78,7 @@ using namespace gui;
extern const unsigned short PRO_VERSION;
extern int enable_log;
extern bool exit_on_return;
extern bool open_file;
extern wchar_t open_file_name[256];
#endif
......@@ -9,7 +9,7 @@ DataManager dataManager;
bool DataManager::LoadDB(const char* file) {
sqlite3* pDB;
if(sqlite3_open(file, &pDB) != SQLITE_OK)
if(sqlite3_open_v2(file, &pDB, SQLITE_OPEN_READONLY, 0) != SQLITE_OK)
return Error(pDB);
sqlite3_stmt* pStmt;
const char* sql = "select * from datas,texts where datas.id=texts.id";
......
......@@ -88,7 +88,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
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->PopupElement(mainGame->wACMessage, 20);
}
......
......@@ -168,21 +168,28 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
deck = ndeck;
return true;
}
bool DeckManager::LoadDeck(const wchar_t* file) {
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;
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
#ifdef WIN32
FILE* fp = _wfopen(deck, L"r");
FILE* fp = _wfopen(file, (wchar_t*)mode);
#else
char deckfn[256];
BufferIO::EncodeUTF8(deck, deckfn);
FILE* fp = fopen(deckfn, "r");
char file2[256];
BufferIO::EncodeUTF8(file, file2);
FILE* fp = fopen(file2, mode);
#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)
return false;
int cardlist[128];
bool is_side = false;
char linebuf[256];
fseek(fp, 0, SEEK_END);
int fsize = ftell(fp);
......@@ -211,13 +218,7 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name);
#ifdef WIN32
FILE* fp = _wfopen(file, L"w");
#else
char filefn[256];
BufferIO::EncodeUTF8(file, filefn);
FILE* fp = fopen(filefn, "w");
#endif
FILE* fp = OpenDeckFile(file, "w");
if(!fp)
return false;
fprintf(fp, "#created by ...\n#main\n");
......
......@@ -40,6 +40,7 @@ public:
int CheckLFList(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
void LoadDeck(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 SaveDeck(Deck& deck, const wchar_t* name);
bool DeleteDeck(Deck& deck, const wchar_t* name);
......
......@@ -944,7 +944,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
desc = BufferIO::ReadInt32(pbuf);
pcard = mainGame->dField.GetCard(con, loc, seq);
mainGame->dField.activatable_cards.push_back(pcard);
mainGame->dField.activatable_descs.push_back(std::make_pair(desc,0));
mainGame->dField.activatable_descs.push_back(std::make_pair(desc, 0));
pcard->cmdFlag |= COMMAND_ACTIVATE;
if (pcard->location == LOCATION_GRAVE)
mainGame->dField.grave_act = true;
......@@ -3275,7 +3275,7 @@ void DuelClient::SetResponseI(int respI) {
*((int*)response_buf) = respI;
response_len = 4;
}
void DuelClient::SetResponseB(unsigned char * respB, unsigned char len) {
void DuelClient::SetResponseB(void* respB, unsigned char len) {
memcpy(response_buf, respB, len);
response_len = len;
}
......
......@@ -42,7 +42,7 @@ public:
static void HandleSTOCPacketLan(char* data, unsigned int len);
static int ClientAnalyze(char* msg, unsigned int len);
static void SetResponseI(int respI);
static void SetResponseB(unsigned char* respB, unsigned char len);
static void SetResponseB(void* respB, unsigned char len);
static void SendResponse();
static void SendPacketToServer(unsigned char proto) {
char* p = duel_client_write;
......
......@@ -386,18 +386,16 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case BUTTON_OPTION_OK: {
if (mainGame->dInfo.curMsg == MSG_SELECT_OPTION) {
DuelClient::SetResponseI(selected_option);
} else if (mainGame->dInfo.curMsg == MSG_SELECT_IDLECMD) {
int index = 0;
while(activatable_cards[index] != command_card || activatable_descs[index].first != select_options[selected_option]) index++;
DuelClient::SetResponseI((index << 16) + 5);
} else if (mainGame->dInfo.curMsg == MSG_SELECT_BATTLECMD) {
int index = 0;
while(activatable_cards[index] != command_card || activatable_descs[index].first != select_options[selected_option]) index++;
DuelClient::SetResponseI(index << 16);
} else {
int index = 0;
while(activatable_cards[index] != command_card || activatable_descs[index].first != select_options[selected_option]) index++;
DuelClient::SetResponseI(index);
if (mainGame->dInfo.curMsg == MSG_SELECT_IDLECMD) {
DuelClient::SetResponseI((index << 16) + 5);
} else if (mainGame->dInfo.curMsg == MSG_SELECT_BATTLECMD) {
DuelClient::SetResponseI(index << 16);
} else {
DuelClient::SetResponseI(index);
}
}
mainGame->HideElement(mainGame->wOptions, true);
break;
......@@ -487,7 +485,10 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case POSITION_HINT: {
selectable_cards.insert(selectable_cards.end(), conti_cards.begin(), conti_cards.end());
selectable_cards = conti_cards;
std::sort(selectable_cards.begin(), selectable_cards.end());
auto eit = std::unique(selectable_cards.begin(), selectable_cards.end());
selectable_cards.erase(eit, selectable_cards.end());
conti_selecting = true;
break;
}
......@@ -1326,8 +1327,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
int command_flag = 0;
if(conti_cards.size() == 0)
break;
if(conti_cards.size())
command_flag |= COMMAND_OPERATION;
command_flag |= COMMAND_OPERATION;
list_command = 1;
ShowMenu(command_flag, x, y);
break;
......@@ -1453,12 +1453,12 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
clicked_card->is_selectable = false;
select_counter_count--;
if (select_counter_count == 0) {
unsigned char respbuf[64];
unsigned short int respbuf[32];
for(size_t i = 0; i < selectable_cards.size(); ++i)
respbuf[i] = (selectable_cards[i]->opParam >> 16) - (selectable_cards[i]->opParam & 0xffff);
mainGame->stHintMsg->setVisible(false);
ClearSelect();
DuelClient::SetResponseB(respbuf, selectable_cards.size());
DuelClient::SetResponseB(respbuf, selectable_cards.size() * 2);
DuelClient::SendResponse();
} else {
wchar_t formatBuffer[2048];
......@@ -1860,7 +1860,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
case irr::EET_KEY_INPUT_EVENT: {
switch(event.KeyInput.Key) {
case irr::KEY_KEY_A: {
if(mainGame->gameConf.control_mode == 0) {
if(mainGame->gameConf.control_mode == 0 && !mainGame->HasFocus(EGUIET_EDIT_BOX)) {
mainGame->always_chain = event.KeyInput.PressedDown;
mainGame->ignore_chain = false;
mainGame->chain_when_avail = false;
......@@ -1869,7 +1869,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case irr::KEY_KEY_S: {
if(mainGame->gameConf.control_mode == 0) {
if(mainGame->gameConf.control_mode == 0 && !mainGame->HasFocus(EGUIET_EDIT_BOX)) {
mainGame->ignore_chain = event.KeyInput.PressedDown;
mainGame->always_chain = false;
mainGame->chain_when_avail = false;
......@@ -1878,7 +1878,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case irr::KEY_KEY_D: {
if(mainGame->gameConf.control_mode == 0) {
if(mainGame->gameConf.control_mode == 0 && !mainGame->HasFocus(EGUIET_EDIT_BOX)) {
mainGame->chain_when_avail = event.KeyInput.PressedDown;
mainGame->always_chain = false;
mainGame->ignore_chain = false;
......
......@@ -14,7 +14,7 @@
#include <dirent.h>
#endif
const unsigned short PRO_VERSION = 0x133C;
const unsigned short PRO_VERSION = 0x133D;
namespace ygo {
......@@ -55,11 +55,11 @@ bool Game::Initialize() {
imageManager.SetDevice(device);
if(!imageManager.Initial())
return false;
LoadExpansionDB();
if(!dataManager.LoadDB("cards.cdb"))
return false;
if(!dataManager.LoadStrings("strings.conf"))
return false;
RefreshExpansionDB();
dataManager.LoadStrings("./expansions/strings.conf");
env = device->getGUIEnvironment();
numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16);
......@@ -100,12 +100,12 @@ bool Game::Initialize() {
lstHostList->setItemHeight(18);
btnLanRefresh = env->addButton(rect<s32>(240, 325, 340, 350), wLanWindow, BUTTON_LAN_REFRESH, dataManager.GetSysString(1217));
env->addStaticText(dataManager.GetSysString(1221), rect<s32>(10, 360, 220, 380), false, false, wLanWindow);
ebJoinIP = env->addEditBox(gameConf.lastip, rect<s32>(110, 355, 250, 380), true, wLanWindow);
ebJoinIP->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
ebJoinPort = env->addEditBox(gameConf.lastport, rect<s32>(260, 355, 320, 380), true, wLanWindow);
ebJoinHost = env->addEditBox(gameConf.lasthost, rect<s32>(110, 355, 350, 380), true, wLanWindow);
ebJoinHost->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
ebJoinPort = env->addEditBox(gameConf.lastport, rect<s32>(360, 355, 420, 380), true, wLanWindow);
ebJoinPort->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
env->addStaticText(dataManager.GetSysString(1222), rect<s32>(10, 390, 220, 410), false, false, wLanWindow);
ebJoinPass = env->addEditBox(gameConf.roompass, rect<s32>(110, 385, 320, 410), true, wLanWindow);
ebJoinPass = env->addEditBox(gameConf.roompass, rect<s32>(110, 385, 420, 410), true, wLanWindow);
ebJoinPass->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
btnJoinHost = env->addButton(rect<s32>(460, 355, 570, 380), wLanWindow, BUTTON_JOIN_HOST, dataManager.GetSysString(1223));
btnJoinCancel = env->addButton(rect<s32>(460, 385, 570, 410), wLanWindow, BUTTON_JOIN_CANCEL, dataManager.GetSysString(1212));
......@@ -713,7 +713,7 @@ void Game::SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gu
dataManager.strBuffer[pbuffer] = 0;
pControl->setText(dataManager.strBuffer);
}
void Game::RefreshExpansionDB() {
void Game::LoadExpansionDB() {
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
......@@ -864,7 +864,7 @@ void Game::LoadConfig() {
gameConf.lastdeck[0] = 0;
gameConf.numfont[0] = 0;
gameConf.textfont[0] = 0;
gameConf.lastip[0] = 0;
gameConf.lasthost[0] = 0;
gameConf.lastport[0] = 0;
gameConf.roompass[0] = 0;
//settings
......@@ -902,9 +902,9 @@ void Game::LoadConfig() {
BufferIO::CopyWStr(wstr, gameConf.numfont, 256);
} else if(!strcmp(strbuf, "serverport")) {
gameConf.serverport = atoi(valbuf);
} else if(!strcmp(strbuf, "lastip")) {
} else if(!strcmp(strbuf, "lasthost")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.lastip, 20);
BufferIO::CopyWStr(wstr, gameConf.lasthost, 20);
} else if(!strcmp(strbuf, "lastport")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.lastport, 20);
......@@ -969,8 +969,8 @@ void Game::SaveConfig() {
BufferIO::EncodeUTF8(gameConf.numfont, linebuf);
fprintf(fp, "numfont = %s\n", linebuf);
fprintf(fp, "serverport = %d\n", gameConf.serverport);
BufferIO::EncodeUTF8(gameConf.lastip, linebuf);
fprintf(fp, "lastip = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.lasthost, linebuf);
fprintf(fp, "lasthost = %s\n", linebuf);
BufferIO::EncodeUTF8(gameConf.lastport, linebuf);
fprintf(fp, "lastport = %s\n", linebuf);
//settings
......
......@@ -16,7 +16,7 @@ struct Config {
unsigned short antialias;
unsigned short serverport;
unsigned char textfontsize;
wchar_t lastip[20];
wchar_t lasthost[100];
wchar_t lastport[10];
wchar_t nickname[20];
wchar_t gamename[20];
......@@ -82,7 +82,7 @@ public:
void BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar);
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 RefreshExpansionDB();
void LoadExpansionDB();
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay();
void RefreshSingleplay();
......@@ -218,7 +218,7 @@ public:
irr::gui::IGUIEditBox* ebNickName;
irr::gui::IGUIListBox* lstHostList;
irr::gui::IGUIButton* btnLanRefresh;
irr::gui::IGUIEditBox* ebJoinIP;
irr::gui::IGUIEditBox* ebJoinHost;
irr::gui::IGUIEditBox* ebJoinPort;
irr::gui::IGUIEditBox* ebJoinPass;
irr::gui::IGUIButton* btnJoinHost;
......
......@@ -5,6 +5,32 @@
int enable_log = 0;
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[]) {
#ifdef _WIN32
......@@ -22,46 +48,72 @@ int main(int argc, char* argv[]) {
return 0;
for(int i = 1; i < argc; ++i) {
/*command line args:
* -j: join host (host info from system.conf)
* -d: deck edit
* -r: replay */
if(argv[i][0] == '-' && argv[i][1] == 'e') {
#ifdef _WIN32
wchar_t fname[260];
MultiByteToWideChar(CP_ACP, 0, &argv[i][2], -1, fname, 260);
char fname2[260];
BufferIO::EncodeUTF8(fname, fname2);
ygo::dataManager.LoadDB(fname2);
#else
ygo::dataManager.LoadDB(&argv[i][2]);
#endif
} else if(!strcmp(argv[i], "-j") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-r") || !strcmp(argv[i], "-s")) {
char param[128];
GetParameter(param, &argv[i][2]);
ygo::dataManager.LoadDB(param);
}
if(!strcmp(argv[i], "-e")) { // extra database
++i;
char param[128];
GetParameter(param, &argv[i][0]);
ygo::dataManager.LoadDB(param);
continue;
} else if(!strcmp(argv[i], "-n")) { // nickName
++i;
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebNickName->setText(param);
continue;
} else if(!strcmp(argv[i], "-h")) { // Host address
++i;
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinHost->setText(param);
continue;
} else if(!strcmp(argv[i], "-p")) { // host Port
++i;
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinPort->setText(param);
continue;
} else if(!strcmp(argv[i], "-w")) { // host passWord
++i;
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinPass->setText(param);
continue;
} else if(!strcmp(argv[i], "-x")) { // eXit on return
exit_on_return = true;
irr::SEvent event;
event.EventType = irr::EET_GUI_EVENT;
event.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED;
if(!strcmp(argv[i], "-j")) {
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
event.GUIEvent.Caller = ygo::mainGame->btnJoinHost;
ygo::mainGame->device->postEventFromUser(event);
} else if(!strcmp(argv[i], "-d")) {
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);
} else if(!strcmp(argv[i], "-j")) { // Join host
ClickButton(ygo::mainGame->btnLanMode);
ClickButton(ygo::mainGame->btnJoinHost);
break;
} else if(!strcmp(argv[i], "-d")) { // Deck
if(i < argc) {
open_file = true;
GetParameterW(open_file_name, &argv[i + 1][0]);
}
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();
......
......@@ -31,38 +31,36 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_JOIN_HOST: {
#if WINVER >= 0x0600
struct addrinfo hints, *servinfo;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM; /* Datagram socket */
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
hints.ai_protocol = 0; /* Any protocol */
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
int status;
char hostname[100];
char ip[20];
const wchar_t* pstr = mainGame->ebJoinIP->getText();
BufferIO::CopyWStr(pstr, hostname, 100);
if ((status = getaddrinfo(hostname, NULL, &hints, &servinfo)) == -1) {
fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
//error handling
BufferIO::CopyWStr(pstr, ip, 16);
} else
inet_ntop(AF_INET, &(((struct sockaddr_in *)servinfo->ai_addr)->sin_addr), ip, 20);
freeaddrinfo(servinfo);
#else
char hostname[100];
char ip[20];
const wchar_t* pstr = mainGame->ebJoinIP->getText();
BufferIO::CopyWStr(pstr, hostname, 100);
const wchar_t* pstr = mainGame->ebJoinHost->getText();
BufferIO::CopyWStr(pstr, ip, 16);
#endif
unsigned int remote_addr = htonl(inet_addr(ip));
if(remote_addr == -1) {
char hostname[100];
char port[6];
BufferIO::CopyWStr(pstr, hostname, 100);
BufferIO::CopyWStr(mainGame->ebJoinPort->getText(), port, 6);
struct evutil_addrinfo hints;
struct evutil_addrinfo *answer = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = EVUTIL_AI_ADDRCONFIG;
int status=evutil_getaddrinfo(hostname, port, &hints, &answer);
if(status != 0) {
mainGame->gMutex.Lock();
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1412));
mainGame->gMutex.Unlock();
break;
} else {
sockaddr_in * sin = ((struct sockaddr_in *)answer->ai_addr);
evutil_inet_ntop(AF_INET, &(sin->sin_addr), ip, 20);
remote_addr = htonl(inet_addr(ip));
}
}
unsigned int remote_port = _wtoi(mainGame->ebJoinPort->getText());
BufferIO::CopyWStr(pstr, mainGame->gameConf.lastip, 20);
BufferIO::CopyWStr(pstr, mainGame->gameConf.lasthost, 100);
BufferIO::CopyWStr(mainGame->ebJoinPort->getText(), mainGame->gameConf.lastport, 20);
if(DuelClient::StartClient(remote_addr, remote_port, false)) {
mainGame->btnCreateHost->setEnabled(false);
......@@ -74,6 +72,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
case BUTTON_JOIN_CANCEL: {
mainGame->HideElement(mainGame->wLanWindow);
mainGame->ShowElement(mainGame->wMainMenu);
if(exit_on_return)
mainGame->device->closeDevice();
break;
}
case BUTTON_LAN_REFRESH: {
......@@ -160,10 +160,15 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_LOAD_REPLAY: {
if(mainGame->lstReplayList->getSelected() == -1)
break;
if(!ReplayMode::cur_replay.OpenReplay(mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected())))
break;
if(open_file) {
ReplayMode::cur_replay.OpenReplay(open_file_name);
open_file = false;
} 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->wCardImg->setVisible(true);
mainGame->wInfos->setVisible(true);
......@@ -198,7 +203,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_LOAD_SINGLEPLAY: {
if(mainGame->lstSinglePlayList->getSelected() == -1)
if(!open_file && mainGame->lstSinglePlayList->getSelected() == -1)
break;
mainGame->singleSignal.SetNoWait(false);
SingleMode::StartPlay();
......@@ -211,8 +216,32 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case BUTTON_DECK_EDIT: {
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()));
mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu);
mainGame->is_building = true;
mainGame->is_siding = false;
......@@ -266,7 +295,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int port = DuelClient::hosts[sel].port;
wchar_t buf[20];
myswprintf(buf, L"%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff, (addr >> 16) & 0xff, (addr >> 24) & 0xff);
mainGame->ebJoinIP->setText(buf);
mainGame->ebJoinHost->setText(buf);
myswprintf(buf, L"%d", port);
mainGame->ebJoinPort->setText(buf);
break;
......
......@@ -139,15 +139,24 @@ void Replay::SaveReplay(const wchar_t* name) {
fclose(fp);
}
bool Replay::OpenReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
#ifdef WIN32
fp = _wfopen(fname, L"rb");
fp = _wfopen(name, L"rb");
#else
char fname2[256];
BufferIO::EncodeUTF8(fname, fname2);
fp = fopen(fname2, "rb");
char name2[256];
BufferIO::EncodeUTF8(name, name2);
fp = fopen(name2, "rb");
#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)
return false;
fseek(fp, 0, SEEK_END);
......
......@@ -185,6 +185,8 @@ int ReplayMode::ReplayThread(void* param) {
mainGame->ShowElement(mainGame->wReplay);
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock();
if(exit_on_return)
mainGame->device->closeDevice();
}
return 0;
}
......
......@@ -29,11 +29,17 @@ void SingleMode::SetResponse(unsigned char* resp) {
set_responseb(pduel, resp);
}
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];
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;
time_t seed = time(0);
rnd.reset(seed);
......@@ -103,6 +109,8 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->ShowElement(mainGame->wSinglePlay);
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock();
if(exit_on_return)
mainGame->device->closeDevice();
}
return 0;
}
......
Subproject commit 43ef40d604e457656207a3621e03b3275a895484
Subproject commit d9661fcaa0a839786d17c9262bce636b82a7f126
Subproject commit eed9034a4ed68fad7253aad17ce22f2ca65ba0fc
Subproject commit fc34bc5cf0b20f7e4f753f7b5afa3c28de30a3bb
......@@ -363,6 +363,7 @@
!system 1409 等待更换副卡组中...
!system 1410 卡组数量与先前不符合。
!system 1411 版本不匹配(%X.0%X.%X)。
!system 1412 无法解析主机地址。
!system 1500 决斗结束。
!system 1501 录像结束。
!system 1502 连接已断开。
......
......@@ -9,7 +9,7 @@ lastdeck = new
textfont = c:/windows/fonts/msyh.ttf 14
numfont = c:/windows/fonts/arialbd.ttf
serverport = 7911
lastip = 127.0.0.1
lasthost = 127.0.0.1
lastport = 7911
autopos = 1
randompos = 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