Warning, file /games/ksirk/ksirk/kgamewinslots.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of KsirK. 0002 Copyright (C) 2001-2007 Gael de Chalendar (aka Kleag) <kleag@free.fr> 0003 0004 KsirK is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, either version 2 0007 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA 0018 */ 0019 0020 // application specific includes 0021 #include "kgamewin.h" 0022 #include "ksirksettings.h" 0023 #include "newgamesetup.h" 0024 #include "Sprites/backgnd.h" 0025 #include "Sprites/arrowsprite.h" 0026 #include "Dialogs/newGameSummaryWidget.h" 0027 #include "GameLogic/newplayerdata.h" 0028 0029 #include <KAboutApplicationDialog> 0030 #include <KToolBar> 0031 0032 #include "GameLogic/KMessageParts.h" 0033 #include "GameLogic/gameautomaton.h" 0034 #include "GameLogic/country.h" 0035 #include "GameLogic/onu.h" 0036 #include "GameLogic/goal.h" 0037 #include "SaveLoad/ksirkgamexmlloader.h" 0038 #include "Sprites/animspritesgroup.h" 0039 #include "Dialogs/jabbergameui.h" 0040 #include "Dialogs/kplayersetupwidget.h" 0041 #include "Jabber/kmessagejabber.h" 0042 0043 #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API 0044 #include <libkdegamesprivate/kgame/kmessageserver.h> 0045 0046 // STL include files 0047 #include <fstream> 0048 0049 // include files for QT 0050 #include <QCursor> 0051 #include <QScrollBar> 0052 #include <QUuid> 0053 #include <QTextStream> 0054 #include <QInputDialog> 0055 #include <QFileDialog> 0056 #include <QUrl> 0057 0058 // include files for KDE 0059 #include <KLocalizedString> 0060 #include <KConfig> 0061 #include "ksirk_debug.h" 0062 0063 #include <KGamePopupItem> 0064 #include <KPasswordDialog> 0065 #include <tcpconnectwidget.h> 0066 0067 namespace Ksirk 0068 { 0069 using namespace GameLogic; 0070 0071 // void KGameWindow::slotTimerEvent() 0072 void KGameWindow::mouseMoveEvent ( QMouseEvent * event ) 0073 { 0074 // qCDebug(KSIRK_LOG); 0075 QString countryName; 0076 QPoint mousePos; 0077 QPoint mousePosGlobal; 0078 QPointF mousePosition; 0079 Country *mouseLocalisation; 0080 0081 if (m_frame == nullptr || m_reinitializingGame) 0082 { 0083 return; 0084 } 0085 mousePosGlobal = event->globalPos(); 0086 mousePos = m_frame->mapFromGlobal(mousePosGlobal); 0087 mousePosition = m_frame->mapToScene(mousePos); 0088 mouseLocalisation = clickIn(mousePosition); 0089 countryName = (mouseLocalisation) ? mouseLocalisation->name() : ""; 0090 if (mouseLocalisation) 0091 { 0092 if (m_mouseLocalisation && m_mouseLocalisation!=mouseLocalisation) 0093 { 0094 m_mouseLocalisation->clearHighlighting(); 0095 m_mouseLocalisation = mouseLocalisation; 0096 mouseLocalisation->highlight(Qt::white, 0.5); 0097 } 0098 else if (m_mouseLocalisation == nullptr) 0099 { 0100 m_mouseLocalisation = mouseLocalisation; 0101 mouseLocalisation->highlight(Qt::white, 0.5); 0102 } 0103 if (!countryName.isEmpty()) 0104 { 0105 QString status1Text = ""; 0106 const Player* player = mouseLocalisation-> owner(); 0107 if (player) 0108 { 0109 status1Text = i18np("%2 belongs to %3. 1 army.","%2 belongs to %3. %1 armies.",mouseLocalisation->nbArmies(),i18n(countryName.toUtf8().data()),player->name()); 0110 } 0111 0112 //QT5 statusBar()-> changeItem(status1Text, ID_STATUS_MSG); 0113 } 0114 } 0115 else 0116 { 0117 if (m_mouseLocalisation!=nullptr) 0118 { 0119 m_mouseLocalisation->clearHighlighting(); 0120 m_mouseLocalisation = nullptr; 0121 } 0122 //QT5 statusBar()-> changeItem("", ID_STATUS_MSG); // Reset 0123 } 0124 int borderScrollSize = 50; 0125 if ( (!m_timer.isActive()) 0126 && ( ((mousePos.x() < borderScrollSize) && (mousePos.x() >= 0) 0127 && (mousePos.y() >= 0) && (mousePos.y() <= m_frame-> viewport()->height())) 0128 || ((mousePos.x() > m_frame->viewport()->width() -borderScrollSize) && 0129 (mousePos.x() <= m_frame-> viewport()->width()) 0130 && (mousePos.y() >= 0) && (mousePos.y() <= m_frame-> viewport()->height())) 0131 || ((mousePos.y() < borderScrollSize) && (mousePos.y() >= 0) 0132 && (mousePos.x() >= 0) && (mousePos.x() <= m_frame-> viewport()->width())) 0133 || ((mousePos.y() > m_frame-> viewport()->height() -borderScrollSize) && 0134 (mousePos.y() <= m_frame-> viewport()->height()) 0135 && (mousePos.x() >= 0) && (mousePos.x() <= m_frame-> viewport()->width())) 0136 ) 0137 ) 0138 // safety check for NULL arrow pointers, can happen with Qt 4.5 0139 if (m_uparrow == nullptr || m_downarrow == nullptr || m_leftarrow == nullptr || m_rightarrow == nullptr) 0140 { 0141 return; 0142 } 0143 if (currentWidget() != nullptr) 0144 { 0145 m_timer.start(200); 0146 if ((mousePos.y() < borderScrollSize) && (mousePos.y() >= 0) 0147 && (mousePos.x() >= 0) && (mousePos.x() <= m_frame-> viewport()->width())) 0148 { 0149 QPointF pos = currentWidget()->mapToScene(QPoint(m_frame->viewport()->width()/2,0)); 0150 pos = pos + QPointF(-(m_uparrow->boundingRect().width()/2),m_uparrow->boundingRect().height()); 0151 m_uparrow->setPos(pos); 0152 m_uparrow->setActive(true); 0153 } 0154 if ((mousePos.y() > m_frame->viewport()->height() -borderScrollSize) && 0155 (mousePos.y() <= m_frame->viewport()->height()) 0156 && (mousePos.x() >= 0) && (mousePos.x() <= m_frame-> viewport()->width())) 0157 { 0158 QPointF pos = currentWidget()->mapToScene(QPoint(m_frame->viewport()->width()/2,m_frame->viewport()->height())); 0159 pos = pos - QPointF(m_downarrow->boundingRect().width()/2,m_downarrow->boundingRect().height()); 0160 m_downarrow->setPos(pos); 0161 m_downarrow->setActive(true); 0162 } 0163 if ((mousePos.x() < borderScrollSize) && (mousePos.x() >= 0) 0164 && (mousePos.y() >= 0) && (mousePos.y() <= m_frame-> viewport()->height())) 0165 { 0166 QPointF pos = currentWidget()->mapToScene(QPoint(0,m_frame->viewport()->height()/2)); 0167 pos = pos + QPointF(m_leftarrow->boundingRect().width(),-(m_leftarrow->boundingRect().height()/2)); 0168 m_leftarrow->setPos(pos); 0169 m_leftarrow->setActive(true); 0170 } 0171 if ((mousePos.x() > m_frame->viewport()->width() -borderScrollSize) && 0172 (mousePos.x() <= m_frame-> viewport()->width()) 0173 && (mousePos.y() >= 0) && (mousePos.y() <= m_frame-> viewport()->height())) 0174 { 0175 QPointF pos = currentWidget()->mapToScene(QPoint(m_frame->viewport()->width(),m_frame->viewport()->height()/2)); 0176 pos = pos - QPointF(m_rightarrow->boundingRect().width(),m_rightarrow->boundingRect().height()/2); 0177 m_rightarrow->setPos(pos); 0178 m_rightarrow->setActive(true); 0179 m_rightarrow->update(); 0180 } 0181 } 0182 if (m_frame && m_frame->horizontalScrollBar()->value() == m_frame->horizontalScrollBar()->maximum()) 0183 { 0184 m_rightarrow->hide(); 0185 } 0186 else 0187 { 0188 m_rightarrow->show(); 0189 } 0190 if (m_frame && m_frame->verticalScrollBar()->value() == m_frame->verticalScrollBar()->maximum()) 0191 { 0192 m_downarrow->hide(); 0193 } 0194 else 0195 { 0196 m_downarrow->show(); 0197 } 0198 if (m_frame && m_frame->verticalScrollBar()->value() == m_frame->verticalScrollBar()->minimum()) 0199 { 0200 m_uparrow->hide(); 0201 } 0202 else 0203 { 0204 m_uparrow->show(); 0205 } 0206 } 0207 0208 void KGameWindow::evenementTimer() 0209 { //Appel du Timer toutes les 50 ms 0210 QPoint mousePos; 0211 QPointF mousePosition; 0212 0213 // qCDebug(KSIRK_LOG) << "KGameWindow::evenementTimer"; 0214 mousePos = QCursor::pos(); 0215 mousePosition = m_frame-> mapFromGlobal(mousePos); 0216 // qCDebug(KSIRK_LOG) << "mousePosition = ( " << mousePosition.x() << " , " << mousePosition.y() << " )"; 0217 // qCDebug(KSIRK_LOG) << "m_frame = ( " << m_frame-> viewport()->width() << " , " << m_frame-> viewport()->height() << " )"; 0218 0219 bool restart = false; 0220 int borderScrollSize = 50; 0221 int borderScrollSpeed = 40; 0222 if ((mousePosition.x() < borderScrollSize) && (mousePosition.x() >= 0) 0223 && (mousePosition.y() >= 0) && (mousePosition.y() <= m_frame-> viewport()->height())) 0224 { 0225 // qCDebug(KSIRK_LOG) << "scrollRight"; 0226 m_frame->horizontalScrollBar()->setValue(m_frame->horizontalScrollBar()->value() - borderScrollSpeed); 0227 if (m_frame->horizontalScrollBar()->value() == m_frame->horizontalScrollBar()->minimum()) 0228 { 0229 m_leftarrow->hide(); 0230 } 0231 else 0232 { 0233 m_leftarrow->show(); 0234 } 0235 m_leftarrow->setActive(true); 0236 restart = true; 0237 } 0238 else 0239 { 0240 m_leftarrow->setActive(false); 0241 } 0242 QPointF pos = currentWidget()->mapToScene(QPoint(0,m_frame->viewport()->height()/2)); 0243 pos = pos + QPointF(m_leftarrow->boundingRect().width(),-(m_leftarrow->boundingRect().height()/2)); 0244 m_leftarrow->setPos(pos); 0245 0246 if ((mousePosition.x() > m_frame-> viewport()->width() -borderScrollSize) && 0247 (mousePosition.x() <= m_frame-> viewport()->width()) 0248 && (mousePosition.y() >= 0) && (mousePosition.y() <= m_frame-> viewport()->height())) 0249 { 0250 // qCDebug(KSIRK_LOG) << "scrollLeft"; 0251 m_frame-> horizontalScrollBar()->setValue ( m_frame-> horizontalScrollBar()->value() + borderScrollSpeed); 0252 m_rightarrow->setActive(true); 0253 m_rightarrow->update(); 0254 restart = true; 0255 } 0256 else 0257 { 0258 m_rightarrow->setActive(false); 0259 } 0260 pos = currentWidget()->mapToScene(QPoint(m_frame->viewport()->width(),m_frame->viewport()->height()/2)); 0261 pos = pos - QPointF(m_rightarrow->boundingRect().width(),m_rightarrow->boundingRect().height()/2); 0262 m_rightarrow->setPos(pos); 0263 0264 if ((mousePosition.y() < borderScrollSize) && (mousePosition.y() >= 0) 0265 && (mousePosition.x() >= 0) && (mousePosition.x() <= m_frame-> viewport()->width())) 0266 { 0267 // qCDebug(KSIRK_LOG) << "scrollDown"; 0268 m_frame-> verticalScrollBar()->setValue ( m_frame-> verticalScrollBar()->value() - borderScrollSpeed); 0269 m_uparrow->setActive(true); 0270 restart = true; 0271 } 0272 else 0273 { 0274 m_uparrow->setActive(false); 0275 } 0276 pos = currentWidget()->mapToScene(QPoint(m_frame->viewport()->width()/2,0)); 0277 pos = pos + QPointF(-(m_uparrow->boundingRect().width()/2),m_uparrow->boundingRect().height()); 0278 m_uparrow->setPos(pos); 0279 0280 if ((mousePosition.y() > m_frame-> viewport()->height() -borderScrollSize) && 0281 (mousePosition.y() <= m_frame-> viewport()->height()) 0282 && (mousePosition.x() >= 0) && (mousePosition.x() <= m_frame-> viewport()->width())) 0283 { 0284 // qCDebug(KSIRK_LOG) << "scrollUp " << m_frame-> verticalScrollBar()->value() 0285 // << "("<< m_frame-> verticalScrollBar()->minimum() 0286 // << ", " << m_frame-> verticalScrollBar()->maximum() << ")"; 0287 m_frame-> verticalScrollBar()->setValue ( m_frame-> verticalScrollBar()->value() + borderScrollSpeed); 0288 m_downarrow->setActive(true); 0289 restart = true; 0290 } 0291 else 0292 { 0293 m_downarrow->setActive(false); 0294 } 0295 pos = currentWidget()->mapToScene(QPoint(m_frame->viewport()->width()/2,m_frame->viewport()->height())); 0296 pos = pos - QPointF(m_downarrow->boundingRect().width()/2,m_downarrow->boundingRect().height()); 0297 m_downarrow->setPos(pos); 0298 0299 if ( m_animFighters->isEmpty() ) 0300 { 0301 if ( m_secondCountry && !( m_secondCountry-> owner() ) ) 0302 qCCritical(KSIRK_LOG) << m_secondCountry-> name() << " does not belong to anybody !"; 0303 // handling of the AI player actions 0304 /*if ( !( ( ( currentPlayer() && currentPlayer()-> isAI() ) 0305 || ( ( isMyState(GameLogic::GameAutomaton::WAITDEFENSE) ) && ( m_secondCountry ) && (m_secondCountry->owner()) 0306 && ( m_secondCountry->owner()->isAI() ) ) ) ) ) { 0307 toolBar("gameActionsToolBar")-> show(); 0308 }*/ 0309 } 0310 0311 if (m_frame->horizontalScrollBar()->value() == m_frame->horizontalScrollBar()->minimum()) 0312 { 0313 m_leftarrow->hide(); 0314 } 0315 else 0316 { 0317 m_leftarrow->show(); 0318 } 0319 if (m_frame->horizontalScrollBar()->value() == m_frame->horizontalScrollBar()->maximum()) 0320 { 0321 m_rightarrow->hide(); 0322 } 0323 else 0324 { 0325 m_rightarrow->show(); 0326 } 0327 if (m_frame->verticalScrollBar()->value() == m_frame->verticalScrollBar()->maximum()) 0328 { 0329 m_downarrow->hide(); 0330 } 0331 else 0332 { 0333 m_downarrow->show(); 0334 } 0335 if (m_frame->verticalScrollBar()->value() == m_frame->verticalScrollBar()->minimum()) 0336 { 0337 m_uparrow->hide(); 0338 } 0339 else 0340 { 0341 m_uparrow->show(); 0342 } 0343 0344 // qCDebug(KSIRK_LOG) << "OUT KGameWindow::evenementTimer"; 0345 if (restart) 0346 { 0347 // qCDebug(KSIRK_LOG) << "restarting timer"; 0348 m_timer.start(200); 0349 } 0350 } 0351 0352 void KGameWindow::slotLeftButtonDown(const QPointF& point) 0353 { 0354 // qCDebug(KSIRK_LOG) << "slotLeftButtonDown"; 0355 // if (currentPlayer() && !(currentPlayer()-> isAI()) ) 0356 m_automaton->gameEvent("actionLButtonDown", point); 0357 } 0358 0359 void KGameWindow::slotLeftButtonUp(const QPointF& point) 0360 { 0361 // qCDebug(KSIRK_LOG) << "slotLeftButtonUp"; 0362 // if (currentPlayer() && ! (currentPlayer()-> isAI()) ) 0363 m_automaton->gameEvent("actionLButtonUp", point); 0364 } 0365 0366 void KGameWindow::slotRightButtonDown(const QPointF& point) 0367 { 0368 qCDebug(KSIRK_LOG); 0369 // if (currentPlayer() && ! (currentPlayer()-> isAI()) ) 0370 m_automaton->gameEvent("actionRButtonDown", point); 0371 return; 0372 } 0373 0374 void KGameWindow::slotRightButtonUp(const QPointF& point) 0375 { 0376 qCDebug(KSIRK_LOG); 0377 // if (currentPlayer() && ! (currentPlayer()-> isAI()) ) 0378 m_automaton->gameEvent("actionRButtonUp", point); 0379 return; 0380 } 0381 0382 void KGameWindow::slotArena(bool isCheck) 0383 { 0384 if (isCheck) 0385 { 0386 m_useArena = true; 0387 qCDebug(KSIRK_LOG) << "*******Arena On******" << m_useArena; 0388 } 0389 else 0390 { 0391 m_useArena = false; 0392 qCDebug(KSIRK_LOG) << "*******Arena Off******" << m_useArena; 0393 } 0394 } 0395 0396 void KGameWindow::slotJabberGame() 0397 { 0398 m_jabberGameWidget->init(m_automaton); 0399 m_jabberGameWidget->setPreviousGuiIndex(m_centralWidget->currentIndex()); 0400 m_centralWidget->setCurrentIndex(JABBERGAME_INDEX); 0401 } 0402 0403 void KGameWindow::slotNewGame() 0404 { 0405 // qCDebug(KSIRK_LOG) << "Slot new game: posting event actionNewGame"; 0406 actionNewGame(GameAutomaton::None); 0407 } 0408 0409 void KGameWindow::slotNewJabberGame() 0410 { 0411 actionNewGame(GameAutomaton::Jabber); 0412 } 0413 0414 void KGameWindow::slotNewSocketGame() 0415 { 0416 // qCDebug(KSIRK_LOG) << "Slot new game: posting event actionNewGame"; 0417 // QPoint point; 0418 actionNewGame(GameAutomaton::Socket); 0419 0420 /// @TODO set the state to init when new game is started 0421 /* if (actionNewGame()) 0422 { 0423 m_automaton->state(GameAutomaton::INIT); 0424 }*/ 0425 // m_automaton->gameEvent("actionNewGame", point); 0426 } 0427 0428 void KGameWindow::slotOpenGame() 0429 { 0430 qCDebug(KSIRK_LOG) << "Slot open game: posting event actionOpenGame"; 0431 QPoint point; 0432 m_automaton->gameEvent("actionOpenGame", point); 0433 // actionOpenGame(); 0434 } 0435 0436 void KGameWindow::slotSaveGame() 0437 { 0438 if (m_message == nullptr) 0439 { 0440 setupPopupMessage(); 0441 } 0442 if (m_automaton->isAdmin()) 0443 { 0444 if (isMyState(GameLogic::GameAutomaton::WAITDEFENSE)) 0445 { 0446 m_message->setMessageTimeout(3000); 0447 m_message->showMessage(i18n("Cannot save when waiting for a defense."), 0448 KGamePopupItem::TopLeft, 0449 KGamePopupItem::ReplacePrevious); 0450 return; 0451 } 0452 if (m_fileName.isEmpty()) 0453 { 0454 QString fileName = QFileDialog::getSaveFileName (this, i18nc("@title:window", "KsirK - Save Game"), QString(), "*.xml"); 0455 if ( fileName.isEmpty()) 0456 { 0457 m_message->setMessageTimeout(3000); 0458 m_message->showMessage(i18n("Saving canceled"), KGamePopupItem::TopLeft, 0459 KGamePopupItem::ReplacePrevious); 0460 return; 0461 } 0462 m_fileName = fileName; 0463 } 0464 QFile file(m_fileName); 0465 file.open(QIODevice::WriteOnly); 0466 QTextStream ofs(&file); 0467 ofs.setCodec("UTF-8"); 0468 saveXml(ofs); 0469 m_message->setMessageTimeout(3000); 0470 m_message->showMessage(i18n("Game saved to %1",m_fileName), 0471 KGamePopupItem::TopLeft, KGamePopupItem::ReplacePrevious); 0472 } 0473 else 0474 { 0475 m_message->setMessageTimeout(3000); 0476 m_message->showMessage( 0477 i18n("Only game master can save the game in network playing."), 0478 KGamePopupItem::TopLeft, KGamePopupItem::ReplacePrevious); 0479 } 0480 } 0481 0482 void KGameWindow::slotRecycling() 0483 { 0484 qCDebug(KSIRK_LOG); 0485 QPoint point; 0486 m_automaton->gameEvent("actionRecycling", point); 0487 } 0488 0489 void KGameWindow::slotRecyclingFinished() 0490 { 0491 qCDebug(KSIRK_LOG); 0492 QPoint point; 0493 m_rightDock->hide(); 0494 m_automaton->gameEvent("actionRecyclingFinished", point); 0495 } 0496 0497 void KGameWindow::slotNextPlayer() 0498 { 0499 qCDebug(KSIRK_LOG); 0500 QPoint point; 0501 m_automaton->gameEvent("actionNextPlayer", point); 0502 } 0503 0504 void KGameWindow::slotAttack1() 0505 { 0506 QPoint point; 0507 m_automaton->gameEvent("actionAttack1", point); 0508 } 0509 0510 void KGameWindow::slotAttack2() 0511 { 0512 QPoint point; 0513 m_automaton->gameEvent("actionAttack2", point); 0514 } 0515 0516 void KGameWindow::slotAttack3() 0517 { 0518 QPoint point; 0519 m_automaton->gameEvent("actionAttack3", point); 0520 } 0521 0522 void KGameWindow::slotDefense1() 0523 { 0524 QPoint point; 0525 m_automaton->gameEvent("actionDefense1", point); 0526 } 0527 0528 void KGameWindow::slotDefense2() 0529 { 0530 QPoint point; 0531 m_automaton->gameEvent("actionDefense2", point); 0532 } 0533 0534 void KGameWindow::slotInvade1() 0535 { 0536 QPoint point; 0537 m_automaton->gameEvent("actionInvade1", point); 0538 } 0539 0540 void KGameWindow::slotInvade5() 0541 { 0542 QPoint point; 0543 m_automaton->gameEvent("actionInvade5", point); 0544 } 0545 0546 void KGameWindow::slotInvade10() 0547 { 0548 QPoint point; 0549 m_automaton->gameEvent("actionInvade10", point); 0550 } 0551 0552 void KGameWindow::slotInvasionFinished() 0553 { 0554 QPoint point; 0555 m_automaton->gameEvent("actionInvasionFinished", point); 0556 } 0557 0558 void KGameWindow::slotRetreat1() 0559 { 0560 QPoint point; 0561 m_automaton->gameEvent("actionRetreat1", point); 0562 } 0563 0564 void KGameWindow::slotRetreat5() 0565 { 0566 QPoint point; 0567 m_automaton->gameEvent("actionRetreat5", point); 0568 } 0569 0570 void KGameWindow::slotRetreat10() 0571 { 0572 QPoint point; 0573 m_automaton->gameEvent("actionRetreat10", point); 0574 } 0575 0576 void KGameWindow::slotMove() 0577 { 0578 QPoint point; 0579 m_automaton->gameEvent("actionMove", point); 0580 } 0581 0582 void KGameWindow::slotCancel() 0583 { 0584 QPoint point; 0585 m_automaton->gameEvent("actionCancel", point); 0586 } 0587 0588 void KGameWindow::slotDumpGameInformations() 0589 { 0590 // qCDebug(KSIRK_LOG) << "Game information : "; 0591 // qCDebug(KSIRK_LOG) << " state : " << GameStateNames[getState()]; 0592 // qCDebug(KSIRK_LOG) << " current player : " 0593 // << ((currentPlayer()) ? currentPlayer()-> name() : "nobody"); 0594 } 0595 0596 void KGameWindow::slotFinishMoves() 0597 { 0598 qCDebug(KSIRK_LOG); 0599 QByteArray buffer; 0600 QDataStream stream(&buffer, QIODevice::WriteOnly); 0601 m_automaton->sendMessage(buffer,FinishMoves); 0602 } 0603 0604 void KGameWindow::slotShowAboutApplication() 0605 { 0606 //qCDebug(KSIRK_LOG) << "Dans mon About !"; 0607 0608 /* KAboutApplication kAA; 0609 kAA.exec();*/ 0610 #if 0 //QT5 0611 KAboutApplicationDialog dialog(KGlobal::mainComponent().aboutData(), this); 0612 dialog.exec(); 0613 #endif 0614 } 0615 0616 void KGameWindow::slotJoinNetworkGame() 0617 { 0618 qCDebug(KSIRK_LOG); 0619 QPoint point; 0620 m_automaton->gameEvent("actionJoinNetworkGame", point); 0621 } 0622 0623 void KGameWindow::slotConnectToServer() 0624 { 0625 qCDebug(KSIRK_LOG); 0626 m_newGameSetup->setHost(m_tcpConnectWidget->hostEdit->text()); 0627 m_newGameSetup->setTcpPort(m_tcpConnectWidget->portEdit->value()); 0628 m_automaton->setGameStatus(KGame::End); 0629 m_reinitializingGame = true; 0630 0631 if (!(m_automaton->playerList()->isEmpty())) 0632 { 0633 m_automaton->playerList()->clear(); 0634 m_automaton->currentPlayer(nullptr); 0635 qCDebug(KSIRK_LOG) << " playerList size = " << m_automaton->playerList()->count(); 0636 } 0637 theWorld()->reset(); 0638 0639 m_automaton->connectToServ(); 0640 } 0641 0642 void KGameWindow::slotShowGoal() 0643 { 0644 qCDebug(KSIRK_LOG); 0645 if (currentPlayer() && !currentPlayer()->isVirtual() 0646 && !currentPlayer()->isAI()) 0647 { 0648 currentPlayer()->goal().show(GameLogic::Goal::GoalDesc|GameLogic::Goal::GoalAdvance); 0649 } 0650 } 0651 0652 void KGameWindow::slotChatMessage() 0653 { 0654 setFocus(); 0655 } 0656 0657 void KGameWindow::slotChatFloatButtonPressed() 0658 { 0659 // change the floating state 0660 m_bottomDock->setFloating(!m_bottomDock->isFloating()); 0661 } 0662 0663 void KGameWindow::slotChatFloatChanged(bool /*value*/) 0664 { 0665 // change the float button image 0666 if (!m_bottomDock->isFloating()) 0667 { 0668 m_floatChatButton->setIcon(m_upChatFloatPix); 0669 } 0670 else 0671 { 0672 m_floatChatButton->setIcon(m_downChatFloatPix); 0673 } 0674 } 0675 0676 void KGameWindow::slotChatReduceButton() 0677 { 0678 qCDebug(KSIRK_LOG); 0679 0680 // change the reduce button image, hide or show the chat and the short last message 0681 if (!m_chatIsReduced) 0682 { 0683 reduceChat(); 0684 } 0685 else 0686 { 0687 unreduceChat(); 0688 } 0689 } 0690 0691 void KGameWindow::slotMovingFightersArrived(AnimSpritesGroup* sprites) 0692 { 0693 Q_UNUSED(sprites) 0694 qCDebug(KSIRK_LOG); 0695 m_automaton->movingFigthersArrived(); 0696 } 0697 0698 void KGameWindow::slotMovingArmiesArrived(AnimSpritesGroup* sprites) 0699 { 0700 qCDebug(KSIRK_LOG); 0701 AnimSpritesGroup::iterator it, it_end; 0702 it = sprites->begin(); it_end = sprites->end(); 0703 for (; it != it_end; it++) 0704 { 0705 (*it)->hide(); 0706 (*it)->deleteLater(); 0707 } 0708 sprites->clear(); 0709 int index = m_animSpritesGroups.indexOf(sprites); 0710 if (index != -1) 0711 { 0712 m_animSpritesGroups.removeAt(index); 0713 } 0714 sprites->deleteLater(); 0715 KMessageParts messageParts; 0716 broadcastChangeItem(messageParts, ID_STATUS_MSG2, false); 0717 } 0718 0719 void KGameWindow::slotBring(AnimSprite* /*sprite*/) 0720 { 0721 m_automaton->game()->stopExplosion(); 0722 } 0723 0724 void KGameWindow::slotMovingArmyArrived(AnimSprite* sprite) 0725 { 0726 qCDebug(KSIRK_LOG); 0727 sprite->setStatic(); 0728 sprite->hide(); 0729 m_automaton->movingArmyArrived(sprite->getDestination(), 0730 ((ArmySprite*)sprite)->nbArmies()); 0731 } 0732 0733 void KGameWindow::slotFiringFinished(AnimSpritesGroup* sprites) 0734 { 0735 Q_UNUSED(sprites) 0736 qCDebug(KSIRK_LOG); 0737 m_automaton->firingFinished(); 0738 } 0739 0740 void KGameWindow::slotExplosionFinished(AnimSpritesGroup* sprites) 0741 { 0742 qCDebug(KSIRK_LOG); 0743 while (!sprites->empty()) 0744 { 0745 AnimSprite* sprite = sprites->front(); 0746 sprites->pop_front(); 0747 sprite->setStatic(); 0748 sprite->deleteLater(); 0749 } 0750 0751 if (backGnd()->bgIsArena()) 0752 { 0753 m_automaton->game()->initCombatBringBackForArena(m_automaton->game()->firstCountry(), m_automaton->game()->secondCountry()); 0754 } 0755 0756 m_automaton->explosionFinished(); 0757 qCDebug(KSIRK_LOG)<<"DONE"; 0758 } 0759 0760 void KGameWindow::slotZoomIn() 0761 { 0762 qCDebug(KSIRK_LOG); 0763 m_theWorld->applyZoomFactorFast(1.1); //Call to the fast method (benj) 0764 m_frame->setMaximumSize(m_theWorld->width(),m_theWorld->height()); 0765 m_scene_world->setSceneRect ( QRectF() ); 0766 m_frame->updateGeometry(); 0767 m_backGnd_world->setPixmap(m_theWorld->map()); 0768 0769 } 0770 0771 void KGameWindow::slotZoomOut() 0772 { 0773 qCDebug(KSIRK_LOG); 0774 m_theWorld->applyZoomFactorFast(1.0/1.1); //call to the fast method 0775 m_frame->setMaximumSize(m_theWorld->width(),m_theWorld->height()); 0776 m_scene_world->setSceneRect ( QRectF() ); 0777 m_frame->updateGeometry(); 0778 m_backGnd_world->setPixmap(m_theWorld->map()); 0779 } 0780 0781 void KGameWindow::slotRemoveMessage() 0782 { 0783 qCDebug(KSIRK_LOG); 0784 if (m_message != nullptr) 0785 { 0786 qCDebug(KSIRK_LOG) << "hiding and deleting"; 0787 m_message->hide(); 0788 delete m_message; 0789 m_message = nullptr; 0790 } 0791 } 0792 0793 void KGameWindow::slotContextualHelp() 0794 { 0795 qCDebug(KSIRK_LOG); 0796 if (currentPlayer() == nullptr || currentPlayer()->isAI()) 0797 { 0798 return; 0799 } 0800 switch (m_automaton->state()) 0801 { 0802 case GameLogic::GameAutomaton::WAIT: 0803 showMessage(i18n("Attack by drag & drop between countries<br>Move armies the same way (last action of a turn)."), 5); 0804 break; 0805 case GameLogic::GameAutomaton::NEWARMIES: 0806 case GameLogic::GameAutomaton::INTERLUDE: 0807 showMessage(i18n("Now, place your armies in your countries<br>by clicking in the target countries.")); 0808 break; 0809 default:; 0810 } 0811 } 0812 0813 void KGameWindow::slotDisableHelp(const QString & link) 0814 { 0815 qCDebug(KSIRK_LOG) << link; 0816 KsirkSettings::setHelpEnabled(false); 0817 } 0818 0819 void KGameWindow::slotArmiesNumberChanged(int checked) 0820 { 0821 qCDebug(KSIRK_LOG) << checked; 0822 KsirkSettings::setShowArmiesNumbers(checked); 0823 0824 foreach (Country* country, m_theWorld->getCountries()) 0825 { 0826 country->createArmiesSprites(); 0827 } 0828 } 0829 0830 void KGameWindow::slotDefAuto() 0831 { 0832 QPoint point; 0833 qCDebug(KSIRK_LOG)<<"Recept signal defense auto"; 0834 m_automaton->setDefenseAuto(true); 0835 if (this->firstCountry()->owner()->getNbAttack() == 1) 0836 m_automaton->gameEvent("actionDefense1", point); 0837 else 0838 m_automaton->gameEvent("actionDefense2", point); 0839 m_defenseDialog->close(); 0840 } 0841 0842 void KGameWindow::slotWindowDef1() 0843 { 0844 QPoint point; 0845 qCDebug(KSIRK_LOG)<<"Recept signal defense with one army"; 0846 m_automaton->gameEvent("actionDefense1", point); 0847 m_defenseDialog->close(); 0848 } 0849 0850 void KGameWindow::slotWindowDef2() 0851 { 0852 QPoint point; 0853 qCDebug(KSIRK_LOG)<<"Recept signal defense with two army"; 0854 m_automaton->gameEvent("actionDefense2", point); 0855 m_defenseDialog->close(); 0856 } 0857 0858 void KGameWindow::slotNewGameNext() 0859 { 0860 qCDebug(KSIRK_LOG); 0861 m_automaton->newGameNext(); 0862 m_reinitializingGame = false; 0863 0864 if (m_automaton->networkGameType()==GameAutomaton::Jabber && m_jabberClient && m_jabberClient->isConnected()) 0865 { 0866 sendGameInfoToJabber(); 0867 } 0868 } 0869 0870 // void KGameWindow::slotNewGameOK(unsigned int nbPlayers, const QString& skin, unsigned int nbNetworkPlayers, bool useGoals) 0871 // { 0872 // qCDebug(KSIRK_LOG) << nbPlayers << skin << nbNetworkPlayers << useGoals; 0873 // m_automaton->setGameStatus(KGame::End); 0874 // m_reinitializingGame = true; 0875 // m_automaton->removeAllPlayers(); 0876 // 0877 // showMap(); 0878 // m_newPlayersNumber = nbPlayers; 0879 // m_automaton->setUseGoals(useGoals); 0880 // m_automaton->state(GameLogic::GameAutomaton::INIT); 0881 // m_automaton->savedState(GameLogic::GameAutomaton::INVALID); 0882 // m_automaton->setNetworkPlayersNumber(m_automaton->networkGameType()==GameAutomaton::None?0:nbNetworkPlayers); 0883 // m_automaton->finishSetupPlayersNumberAndSkin(skin, nbPlayers); 0884 // m_reinitializingGame = false; 0885 // 0886 // if (m_automaton->networkGameType()==GameAutomaton::Jabber && m_jabberClient && m_jabberClient->isConnected()) 0887 // { 0888 // sendGameInfoToJabber(); 0889 // } 0890 // } 0891 0892 void KGameWindow::slotNewGameKO() 0893 { 0894 qCDebug(KSIRK_LOG) << m_stateBeforeNewGame << m_stackWidgetBeforeNewGame; 0895 m_automaton->state(m_stateBeforeNewGame); 0896 m_centralWidget->setCurrentIndex(m_stackWidgetBeforeNewGame); 0897 m_automaton->setGameStatus(KGame::Run); 0898 } 0899 0900 void KGameWindow::slotConnected() 0901 { 0902 qCDebug(KSIRK_LOG) << "Connected to Jabber server."; 0903 0904 qCDebug(KSIRK_LOG) << "Requesting roster..."; 0905 m_jabberClient->requestRoster (); 0906 } 0907 0908 void KGameWindow::slotRosterRequestFinished ( bool success ) 0909 { 0910 qCDebug(KSIRK_LOG) << success; 0911 0912 /* Since we are online now, set initial presence. Don't do this 0913 * before the roster request or we will receive presence 0914 * information before we have updated our roster with actual 0915 * contacts from the server! (Iris won't forward presence 0916 * information in that case either). */ 0917 qCDebug(KSIRK_LOG) << "Setting initial presence..."; 0918 setPresence ( m_initialPresence ); 0919 } 0920 0921 void KGameWindow::slotCSDisconnected () 0922 { 0923 qCDebug(KSIRK_LOG) << "Disconnected from Jabber server."; 0924 0925 /* 0926 * We should delete the JabberClient instance here, 0927 * but timers etc prevent us from doing so. Iris does 0928 * not like to be deleted from a slot. 0929 */ 0930 0931 /* It seems that we don't get offline notifications when going offline 0932 * with the protocol, so clear all resources manually. */ 0933 // resourcePool()->clear(); 0934 0935 } 0936 0937 void KGameWindow::slotReceivedMessage (const XMPP::Message & message) 0938 { 0939 qCDebug(KSIRK_LOG) << "New " << message.type() << " message from " << message.from().full () << ": " << message.body(); 0940 0941 QString body = message.body(); 0942 QString nick = message.from().full(); 0943 0944 if ( message.type() == "groupchat" ) 0945 { 0946 qCDebug(KSIRK_LOG) << "my jid:" << m_groupchatRoom+'@'+m_groupchatHost+'/'+m_groupchatNick; 0947 XMPP::Jid jid ( message.from().domain() ); 0948 if (body.startsWith(QLatin1String("I'm starting a game with skin")) 0949 && m_presents.contains(message.from().full ()) 0950 && message.from().full() != m_groupchatRoom+'@'+m_groupchatHost+'/'+m_groupchatNick) 0951 { 0952 qCDebug(KSIRK_LOG) << "start game message"; 0953 QRegExp rxlen("I'm starting a game with skin '([^']*)' and '(\\d+)' players"); 0954 // int pos = rxlen.indexIn(body); 0955 QString skin = rxlen.cap(1); // "189" 0956 int nbPlayers = rxlen.cap(2).toInt(); // "cm" 0957 qCDebug(KSIRK_LOG) << "emiting newJabberGame" << nick << nbPlayers << skin; 0958 emit newJabberGame(nick, nbPlayers, skin); 0959 } 0960 else if (body.startsWith(QLatin1String("Who propose online KsirK games here?"))) 0961 { 0962 qCDebug(KSIRK_LOG) << "online games question" << m_automaton->stateName(); 0963 if (m_automaton->startingGame()) 0964 { 0965 sendGameInfoToJabber(); 0966 } 0967 } 0968 } 0969 else if ( message.type() == "ksirkgame" ) 0970 { 0971 XMPP::Jid jid ( message.from() ); 0972 if (body == "connect") 0973 { 0974 qCDebug(KSIRK_LOG) << "received connect from" << jid.full(); 0975 KMessageJabber* messageIO = new KMessageJabber(jid.full(), m_jabberClient, this); 0976 if (m_automaton->messageServer()) 0977 { 0978 m_automaton->messageServer()->addClient(messageIO); 0979 } 0980 } 0981 else 0982 { 0983 qCDebug(KSIRK_LOG) << "non connect ksirkgame message"; 0984 } 0985 } 0986 } 0987 void KGameWindow::slotHandleTLSWarning (QCA::TLS::IdentityResult identityResult, QCA::Validity validityResult ) 0988 { 0989 qCDebug(KSIRK_LOG) << "Handling TLS warning..." << identityResult << validityResult; 0990 } 0991 0992 void KGameWindow::slotClientError ( JabberClient::ErrorCode errorCode ) 0993 { 0994 qCDebug(KSIRK_LOG) << "Handling client error..."; 0995 0996 switch ( errorCode ) 0997 { 0998 case JabberClient::NoTLS: 0999 default: 1000 #if 0 //QT5 1001 KMessageBox::queuedMessageBox ( 0, KMessageBox::Error, 1002 i18n ("An encrypted connection with the Jabber server could not be established."), 1003 i18n ("Jabber Connection Error")); 1004 // disconnect ( 0/*Kopete::Account::Manual*/ ); 1005 #endif 1006 break; 1007 } 1008 } 1009 1010 void KGameWindow::slotCSError ( int error ) 1011 { 1012 qCDebug(KSIRK_LOG) << "Error in stream signalled."; 1013 1014 if ( ( error == XMPP::ClientStream::ErrAuth ) 1015 && ( m_jabberClient->clientStream()->errorCondition () == XMPP::ClientStream::NotAuthorized ) ) 1016 { 1017 qCDebug(KSIRK_LOG) << "Incorrect password, retrying."; 1018 // disconnect(/*Kopete::Account::BadPassword*/0); 1019 } 1020 else 1021 { 1022 // int errorClass = 0; 1023 1024 qCDebug(KSIRK_LOG) << "Disconnecting."; 1025 1026 // display message to user 1027 // if(!m_removing) //when removing the account, connection errors are normal. 1028 // handleStreamError (error, m_jabberClient->clientStream()->errorCondition (), m_jabberClient->clientConnector()->errorCode (), server (), errorClass, m_jabberClient->clientStream()->errorText()); 1029 // 1030 // disconnect ( errorClass ); 1031 1032 /* slotCSDisconnected will not be called*/ 1033 // resourcePool()->clear(); 1034 } 1035 1036 } 1037 1038 void KGameWindow::slotClientDebugMessage ( const QString &msg ) 1039 { 1040 qCDebug(KSIRK_LOG) << msg; 1041 } 1042 1043 void KGameWindow::slotGroupChatJoined (const XMPP::Jid & jid) 1044 { 1045 qCDebug(KSIRK_LOG) << "Joined groupchat " << jid.full (); 1046 1047 /* <message type="chat" to="kleag@localhost" id="aabca" > 1048 <body>hello</body> 1049 </message>*/ 1050 XMPP::Message message(QString(m_groupchatRoom+'@'+m_groupchatHost)); 1051 message.setType("groupchat"); 1052 message.setId(QUuid::createUuid().toString().remove('{').remove('}').remove('-')); 1053 message.setBody("Hello, I'm a KsirK Game"); 1054 m_jabberClient->sendMessage(message); 1055 1056 askForJabberGames(); 1057 } 1058 1059 void KGameWindow::slotGroupChatLeft (const XMPP::Jid & jid) 1060 { 1061 qCDebug(KSIRK_LOG) << "Left groupchat " << jid.full (); 1062 } 1063 1064 void KGameWindow::slotGroupChatPresence (const XMPP::Jid & jid, const XMPP::Status & status) 1065 { 1066 qCDebug(KSIRK_LOG) << "Received groupchat presence for room " << jid.full() << status.isAvailable(); 1067 1068 if (status.isAvailable()) 1069 { 1070 XMPP::Message message(jid); 1071 message.setType("ksirkgame"); 1072 message.setId(QUuid::createUuid().toString().remove('{').remove('}').remove('-')); 1073 message.setBody(QString("Hello, ")+jid.full()); 1074 m_jabberClient->sendMessage(message); 1075 m_presents.insert(jid.full()); 1076 } 1077 else 1078 { 1079 m_presents.remove(jid.full()); 1080 } 1081 } 1082 1083 void KGameWindow::slotGroupChatError (const XMPP::Jid &jid, int error, const QString &reason) 1084 { 1085 qCDebug(KSIRK_LOG) << "Group chat error - room " << jid.full () << " had error " << error << " (" << reason << ")"; 1086 1087 switch (error) 1088 { 1089 case JabberClient::InvalidPasswordForMUC: 1090 { 1091 KPasswordDialog dlg(nullptr); 1092 dlg.setPrompt(i18n("A password is required to join the room %1.", jid.node())); 1093 if (dlg.exec() == KPasswordDialog::Accepted) 1094 m_jabberClient->joinGroupChat(jid.domain(), jid.node(), jid.resource(), dlg.password()); 1095 } 1096 break; 1097 1098 case JabberClient::NicknameConflict: 1099 { 1100 bool ok; 1101 QString nickname = QInputDialog::getText(this, i18n("Error trying to join %1: nickname %2 is already in use", jid.node(), jid.resource()), i18n("Provide your nickname"), QLineEdit::Normal, QString(), &ok); 1102 if (ok) 1103 { 1104 m_jabberClient->joinGroupChat(jid.domain(), jid.node(), nickname); 1105 } 1106 } 1107 break; 1108 1109 case JabberClient::BannedFromThisMUC: 1110 //QT5 KMessageBox::queuedMessageBox ( 0, KMessageBox::Error, i18n ("You cannot join the room %1 because you have been banned", jid.node()), i18n ("Jabber Group Chat") ); 1111 break; 1112 1113 case JabberClient::MaxUsersReachedForThisMuc: 1114 //QT5 KMessageBox::queuedMessageBox ( 0, KMessageBox::Error, i18n ("You cannot join the room %1 because the maximum number of users has been reached", jid.node()), i18n ("Jabber Group Chat") ); 1115 break; 1116 1117 default: 1118 { 1119 QString detailedReason = reason.isEmpty () ? i18n ( "No reason given by the server" ) : reason; 1120 1121 //QT5 KMessageBox::queuedMessageBox ( 0, KMessageBox::Error, i18n ("There was an error processing your request for groupchat %1. (Reason: %2, Code %3)", jid.full (), detailedReason, error ), i18n ("Jabber Group Chat") ); 1122 } 1123 } 1124 } 1125 1126 void KGameWindow::slotJabberGameCanceled(int previousIndex) 1127 { 1128 qCDebug(KSIRK_LOG) << previousIndex; 1129 m_centralWidget->setCurrentIndex(previousIndex); 1130 } 1131 1132 void KGameWindow::slotExit() 1133 { 1134 // hide(); 1135 // delete m_automaton; 1136 close(); 1137 } 1138 1139 void KGameWindow::slotNewPlayerNext() 1140 { 1141 qCDebug(KSIRK_LOG) << m_newGameSetup->nbLocalPlayers() << m_newGameSetup->nbPlayers() << m_newGameSetup->nbNetworkPlayers(); 1142 if (m_automaton->isAdmin() && m_newGameSetup->nbLocalPlayers() >= m_newGameSetup->nbPlayers()-m_newGameSetup->nbNetworkPlayers()) 1143 { 1144 m_newGameSummaryWidget->show(this); 1145 m_centralWidget->setCurrentIndex(NEWGAMESUMMARY_INDEX); 1146 } 1147 else if (!m_automaton->isAdmin()) 1148 { 1149 NewPlayerData* pd = m_newGameSetup->players().back(); 1150 addPlayer(pd->name(), 0, 0, pd->nation(), pd->computer()); 1151 } 1152 } 1153 1154 void KGameWindow::slotNewPlayerPrevious() 1155 { 1156 qCDebug(KSIRK_LOG); 1157 if (m_newGameSetup->players().empty()) 1158 { 1159 m_centralWidget->setCurrentIndex(NEWGAME_INDEX); 1160 } 1161 else 1162 { 1163 NewPlayerData* player = m_newGameSetup->players().back(); 1164 m_newGameSetup->players().pop_back(); 1165 m_newPlayerWidget->init(player); 1166 delete player; 1167 m_centralWidget->setCurrentIndex(NEWPLAYER_INDEX); 1168 } 1169 } 1170 1171 void KGameWindow::slotNewPlayerCancel() 1172 { 1173 qCDebug(KSIRK_LOG); 1174 /// @TODO other uninits to do 1175 qDeleteAll(m_newGameSetup->players()); 1176 m_newGameSetup->players().clear(); 1177 m_centralWidget->setCurrentIndex(m_stackWidgetBeforeNewGame); 1178 } 1179 1180 void KGameWindow::slotStartNewGame() 1181 { 1182 qCDebug(KSIRK_LOG) << m_newGameSetup->nbPlayers() << m_newGameSetup->nbPlayers() << m_newGameSetup->players().size(); 1183 m_automaton->setGameStatus(KGame::End); 1184 m_reinitializingGame = true; 1185 1186 // delete remainings animations from previous game 1187 m_animFighters->clear(); 1188 foreach(AnimSpritesGroup* sprites, m_animSpritesGroups) 1189 { 1190 sprites->clear(); 1191 delete sprites; 1192 } 1193 m_animSpritesGroups.clear(); 1194 1195 // for network games, remote players are already created, should not remove them 1196 // TODO the players will not be in the orderd showed in the interface. 1197 if (!(m_automaton->playerList()->isEmpty()) && m_automaton->networkGameType() == GameAutomaton::None) 1198 { 1199 qCDebug(KSIRK_LOG) << "There was " << m_automaton->playerList()->count() << "players"; 1200 m_automaton->playerList()->clear(); 1201 m_automaton->currentPlayer(nullptr); 1202 qCDebug(KSIRK_LOG) << " playerList size = " << m_automaton->playerList()->count(); 1203 } 1204 theWorld()->reset(); 1205 1206 m_automaton->finishSetupPlayersNumberAndSkin(); 1207 m_reinitializingGame = false; 1208 1209 unsigned int nbAvailArmies = (unsigned int)(m_theWorld->getNbCountries() * 2.5 / m_newGameSetup->players().size()); 1210 foreach (const NewPlayerData* player, m_newGameSetup->players()) 1211 { 1212 if (!player->network()) 1213 { 1214 // this has to be done locally 1215 addPlayer(player->name(), nbAvailArmies, 0, player->nation(), player->computer()); 1216 } 1217 } 1218 1219 if (m_newGameSetup->players().size() == m_newGameSetup->nbPlayers()) 1220 { 1221 showMap(); 1222 m_frame->setFocus(); 1223 m_newGameSummaryWidget->finishButton->setEnabled(true); 1224 } 1225 else 1226 { 1227 m_newGameSummaryWidget->finishButton->setDisabled(true); 1228 m_newGameSummaryWidget->previousButton->setDisabled(true); 1229 } 1230 } 1231 1232 void KGameWindow::slotTcpConnectCancel() 1233 { 1234 showMainMenu(); 1235 } 1236 1237 void KGameWindow::slotTcpConnectPrevious() 1238 { 1239 showMainMenu(); 1240 } 1241 1242 1243 } // closing namespace Ksirk