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