Commit bddef3d5 authored by mercury233's avatar mercury233 Committed by GitHub

add ready button (#2021)

parent 2165f36f
......@@ -360,6 +360,8 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
}
for(int i = 0; i < 4; ++i)
mainGame->chkHostPrepReady[i]->setChecked(false);
mainGame->btnHostPrepReady->setVisible(true);
mainGame->btnHostPrepNotReady->setVisible(false);
mainGame->dInfo.time_limit = pkt->info.time_limit;
mainGame->dInfo.time_left[0] = 0;
mainGame->dInfo.time_left[1] = 0;
......@@ -412,9 +414,18 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->chkHostPrepReady[selftype]->setChecked(false);
mainGame->btnHostPrepDuelist->setEnabled(false);
mainGame->btnHostPrepOB->setEnabled(true);
mainGame->btnHostPrepReady->setVisible(true);
mainGame->btnHostPrepNotReady->setVisible(false);
} else {
mainGame->btnHostPrepDuelist->setEnabled(true);
mainGame->btnHostPrepOB->setEnabled(false);
mainGame->btnHostPrepReady->setVisible(false);
mainGame->btnHostPrepNotReady->setVisible(false);
}
if(mainGame->chkHostPrepReady[0]->isChecked() && mainGame->chkHostPrepReady[1]->isChecked()) {
mainGame->btnHostPrepStart->setEnabled(true);
} else {
mainGame->btnHostPrepStart->setEnabled(false);
}
} else {
if(selftype < 4) {
......@@ -436,8 +447,18 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
if(selftype < 4) {
mainGame->chkHostPrepReady[selftype]->setEnabled(true);
mainGame->btnHostPrepOB->setEnabled(true);
mainGame->btnHostPrepReady->setVisible(true);
mainGame->btnHostPrepNotReady->setVisible(false);
} else {
mainGame->btnHostPrepOB->setEnabled(false);
mainGame->btnHostPrepReady->setVisible(false);
mainGame->btnHostPrepNotReady->setVisible(false);
}
if(mainGame->chkHostPrepReady[0]->isChecked() && mainGame->chkHostPrepReady[1]->isChecked()
&& mainGame->chkHostPrepReady[2]->isChecked() && mainGame->chkHostPrepReady[3]->isChecked()) {
mainGame->btnHostPrepStart->setEnabled(true);
} else {
mainGame->btnHostPrepStart->setEnabled(false);
}
}
mainGame->dInfo.player_type = selftype;
......@@ -675,8 +696,16 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
BufferIO::CopyWStr(prename, mainGame->dInfo.clientname_tag, 20);
} else if(state == PLAYERCHANGE_READY) {
mainGame->chkHostPrepReady[pos]->setChecked(true);
if(pos == selftype) {
mainGame->btnHostPrepReady->setVisible(false);
mainGame->btnHostPrepNotReady->setVisible(true);
}
} else if(state == PLAYERCHANGE_NOTREADY) {
mainGame->chkHostPrepReady[pos]->setChecked(false);
if(pos == selftype) {
mainGame->btnHostPrepReady->setVisible(true);
mainGame->btnHostPrepNotReady->setVisible(false);
}
} else if(state == PLAYERCHANGE_LEAVE) {
mainGame->stHostPrepDuelist[pos]->setText(L"");
mainGame->chkHostPrepReady[pos]->setChecked(false);
......@@ -688,6 +717,12 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->chkHostPrepReady[pos]->setChecked(false);
mainGame->stHostPrepOB->setText(watchbuf);
}
if(mainGame->chkHostPrepReady[0]->isChecked() && mainGame->chkHostPrepReady[1]->isChecked()
&& (!mainGame->dInfo.isTag || (mainGame->chkHostPrepReady[2]->isChecked() && mainGame->chkHostPrepReady[3]->isChecked()))) {
mainGame->btnHostPrepStart->setEnabled(true);
} else {
mainGame->btnHostPrepStart->setEnabled(false);
}
mainGame->gMutex.Unlock();
break;
}
......
......@@ -191,8 +191,11 @@ bool Game::Initialize() {
env->addStaticText(dataManager.GetSysString(1254), rect<s32>(10, 235, 110, 255), false, false, wHostPrepare);
cbDeckSelect = env->addComboBox(rect<s32>(120, 230, 270, 255), wHostPrepare);
cbDeckSelect->setMaxSelectionRows(10);
btnHostPrepReady = env->addButton(rect<s32>(170, 180, 270, 205), wHostPrepare, BUTTON_HP_READY, dataManager.GetSysString(1218));
btnHostPrepNotReady = env->addButton(rect<s32>(170, 180, 270, 205), wHostPrepare, BUTTON_HP_NOTREADY, dataManager.GetSysString(1219));
btnHostPrepNotReady->setVisible(false);
btnHostPrepStart = env->addButton(rect<s32>(230, 280, 340, 305), wHostPrepare, BUTTON_HP_START, dataManager.GetSysString(1215));
btnHostPrepCancel = env->addButton(rect<s32>(350, 280, 460, 305), wHostPrepare, BUTTON_HP_CANCEL, dataManager.GetSysString(1212));
btnHostPrepCancel = env->addButton(rect<s32>(350, 280, 460, 305), wHostPrepare, BUTTON_HP_CANCEL, dataManager.GetSysString(1210));
//img
wCardImg = env->addStaticText(L"", rect<s32>(1, 1, 199, 273), true, false, 0, -1, true);
wCardImg->setBackgroundColor(0xc0c0c0c0);
......
......@@ -262,6 +262,8 @@ public:
irr::gui::IGUIComboBox* cbDeckSelect;
irr::gui::IGUIStaticText* stHostPrepRule;
irr::gui::IGUIStaticText* stHostPrepOB;
irr::gui::IGUIButton* btnHostPrepReady;
irr::gui::IGUIButton* btnHostPrepNotReady;
irr::gui::IGUIButton* btnHostPrepStart;
irr::gui::IGUIButton* btnHostPrepCancel;
//replay
......@@ -462,6 +464,8 @@ extern Game* mainGame;
#define BUTTON_HP_CANCEL 123
#define BUTTON_HP_KICK 124
#define CHECKBOX_HP_READY 125
#define BUTTON_HP_READY 126
#define BUTTON_HP_NOTREADY 127
#define LISTBOX_REPLAY_LIST 130
#define BUTTON_LOAD_REPLAY 131
#define BUTTON_CANCEL_REPLAY 132
......
......@@ -10,6 +10,21 @@
namespace ygo {
void UpdateDeck() {
BufferIO::CopyWStr(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()),
mainGame->gameConf.lastdeck, 64);
char deckbuf[1024];
char* pdeck = deckbuf;
BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size());
BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size());
for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.main[i]->first);
for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.extra[i]->first);
for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.side[i]->first);
DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf);
}
bool MenuHandler::OnEvent(const irr::SEvent& event) {
switch(event.EventType) {
case irr::EET_GUI_EVENT: {
......@@ -128,10 +143,22 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
DuelClient::SendPacketToServer(CTOS_HS_KICK, csk);
break;
}
case BUTTON_HP_START: {
if(!mainGame->chkHostPrepReady[0]->isChecked()
|| !mainGame->chkHostPrepReady[1]->isChecked())
case BUTTON_HP_READY: {
if(mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()))) {
break;
}
UpdateDeck();
DuelClient::SendPacketToServer(CTOS_HS_READY);
mainGame->cbDeckSelect->setEnabled(false);
break;
}
case BUTTON_HP_NOTREADY: {
DuelClient::SendPacketToServer(CTOS_HS_NOTREADY);
mainGame->cbDeckSelect->setEnabled(true);
break;
}
case BUTTON_HP_START: {
DuelClient::SendPacketToServer(CTOS_HS_START);
break;
}
......@@ -308,19 +335,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false);
break;
}
BufferIO::CopyWStr(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()),
mainGame->gameConf.lastdeck, 64);
char deckbuf[1024];
char* pdeck = deckbuf;
BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size());
BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size());
for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.main[i]->first);
for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.extra[i]->first);
for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.side[i]->first);
DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf);
UpdateDeck();
DuelClient::SendPacketToServer(CTOS_HS_READY);
mainGame->cbDeckSelect->setEnabled(false);
} else {
......
......@@ -269,6 +269,7 @@ void SingleDuel::PlayerReady(DuelPlayer* dp, bool is_ready) {
ready[dp->type] = is_ready;
STOC_HS_PlayerChange scpc;
scpc.status = (dp->type << 4) | (is_ready ? PLAYERCHANGE_READY : PLAYERCHANGE_NOTREADY);
NetServer::SendPacketToPlayer(players[dp->type], STOC_HS_PLAYER_CHANGE, scpc);
if(players[1 - dp->type])
NetServer::SendPacketToPlayer(players[1 - dp->type], STOC_HS_PLAYER_CHANGE, scpc);
for(auto pit = observers.begin(); pit != observers.end(); ++pit)
......
......@@ -240,7 +240,7 @@ void TagDuel::PlayerReady(DuelPlayer* dp, bool is_ready) {
STOC_HS_PlayerChange scpc;
scpc.status = (dp->type << 4) | (is_ready ? PLAYERCHANGE_READY : PLAYERCHANGE_NOTREADY);
for(int i = 0; i < 4; ++i)
if(players[i] && players[i] != dp)
if(players[i])
NetServer::SendPacketToPlayer(players[i], STOC_HS_PLAYER_CHANGE, scpc);
for(auto pit = observers.begin(); pit != observers.end(); ++pit)
NetServer::SendPacketToPlayer(*pit, STOC_HS_PLAYER_CHANGE, scpc);
......
......@@ -249,6 +249,8 @@
!system 1215 开始
!system 1216 消息
!system 1217 刷新主机
!system 1218 准备
!system 1219 取消准备
!system 1220 昵称:
!system 1221 主机信息:
!system 1222 主机密码:
......
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