76 CustomizePalettes(); |
76 CustomizePalettes(); |
77 |
77 |
78 ui.pageOptions->CBResolution->addItems(sdli.getResolutions()); |
78 ui.pageOptions->CBResolution->addItems(sdli.getResolutions()); |
79 |
79 |
80 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
80 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
81 |
81 |
82 namegen = new HWNamegen(); |
82 namegen = new HWNamegen(); |
83 |
83 |
84 #ifdef __APPLE__ |
84 #ifdef __APPLE__ |
85 //autoupdate |
85 //autoupdate |
86 AutoUpdater* updater; |
86 AutoUpdater* updater; |
87 CocoaInitializer initializer; |
87 CocoaInitializer initializer; |
88 updater = new SparkleAutoUpdater("http://files.getdropbox.com/u/24468/appcast.xml"); //this has to change before release!!! |
88 updater = new SparkleAutoUpdater("http://files.getdropbox.com/u/24468/appcast.xml"); //this has to change before release!!! |
89 if(updater && config->isAutoUpdateEnabled()) |
89 if(updater && config->isAutoUpdateEnabled()) |
90 updater->checkForUpdates(); |
90 updater->checkForUpdates(); |
91 #endif |
91 #endif |
92 |
92 |
93 UpdateTeamsLists(); |
93 UpdateTeamsLists(); |
94 UpdateWeapons(); |
94 UpdateWeapons(); |
95 |
95 |
96 connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool))); |
96 connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool))); |
97 onFrontendFullscreen(config->isFrontendFullscreen()); |
97 onFrontendFullscreen(config->isFrontendFullscreen()); |
133 |
133 |
134 connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
134 connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
135 connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect())); |
135 connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect())); |
136 connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer())); |
136 connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer())); |
137 connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16))); |
137 connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16))); |
138 |
138 |
139 connect(ui.pageNetServer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
139 connect(ui.pageNetServer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
140 connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
140 connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
141 |
141 |
142 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
142 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
143 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
143 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
234 for(QVector<QComboBox*>::iterator it = combos.begin(); it != combos.end(); ++it) { |
234 for(QVector<QComboBox*>::iterator it = combos.begin(); it != combos.end(); ++it) { |
235 (*it)->clear(); |
235 (*it)->clear(); |
236 |
236 |
237 for(int i = 0; i < names.size(); ++i) |
237 for(int i = 0; i < names.size(); ++i) |
238 (*it)->addItem(names[i], ui.pageSelectWeapon->pWeapons->getWeaponsString(names[i])); |
238 (*it)->addItem(names[i], ui.pageSelectWeapon->pWeapons->getWeaponsString(names[i])); |
239 |
239 |
240 int pos = (*it)->findText("Default"); |
240 int pos = (*it)->findText("Default"); |
241 if (pos != -1) { |
241 if (pos != -1) { |
242 (*it)->setCurrentIndex(pos); |
242 (*it)->setCurrentIndex(pos); |
243 } |
243 } |
244 } |
244 } |
355 void HWForm::OnPageShown(quint8 id, quint8 lastid) |
355 void HWForm::OnPageShown(quint8 id, quint8 lastid) |
356 { |
356 { |
357 if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) { |
357 if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) { |
358 QStringList tmNames = config->GetTeamsList(); |
358 QStringList tmNames = config->GetTeamsList(); |
359 TeamSelWidget* curTeamSelWidget; |
359 TeamSelWidget* curTeamSelWidget; |
360 |
360 |
361 if(id == ID_PAGE_MULTIPLAYER) { |
361 if(id == ID_PAGE_MULTIPLAYER) { |
362 curTeamSelWidget = ui.pageMultiplayer->teamsSelect; |
362 curTeamSelWidget = ui.pageMultiplayer->teamsSelect; |
363 } else { |
363 } else { |
364 curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget; |
364 curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget; |
365 } |
365 } |
366 |
366 |
367 QList<HWTeam> teamsList; |
367 QList<HWTeam> teamsList; |
368 for(QStringList::iterator it = tmNames.begin(); it != tmNames.end(); it++) { |
368 for(QStringList::iterator it = tmNames.begin(); it != tmNames.end(); it++) { |
369 HWTeam team(*it); |
369 HWTeam team(*it); |
370 team.LoadFromFile(); |
370 team.LoadFromFile(); |
371 teamsList.push_back(team); |
371 teamsList.push_back(team); |
372 } |
372 } |
373 |
373 |
374 if(lastid == ID_PAGE_SETUP) { // _TEAM |
374 if(lastid == ID_PAGE_SETUP) { // _TEAM |
375 if (editedTeam) { |
375 if (editedTeam) { |
376 curTeamSelWidget->addTeam(*editedTeam); |
376 curTeamSelWidget->addTeam(*editedTeam); |
377 } |
377 } |
378 } else if(lastid != ID_PAGE_GAMESTATS |
378 } else if(lastid != ID_PAGE_GAMESTATS |
400 { |
400 { |
401 quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
401 quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
402 quint8 curid = ui.Pages->currentIndex(); |
402 quint8 curid = ui.Pages->currentIndex(); |
403 ui.Pages->setCurrentIndex(id); |
403 ui.Pages->setCurrentIndex(id); |
404 OnPageShown(id, curid); |
404 OnPageShown(id, curid); |
405 |
405 |
406 if (id == ID_PAGE_CONNECTING) |
406 if (id == ID_PAGE_CONNECTING) |
407 GoBack(); |
407 GoBack(); |
408 if (id == ID_PAGE_NETSERVER) |
408 if (id == ID_PAGE_NETSERVER) |
409 GoBack(); |
409 GoBack(); |
410 if ((!hwnet) && (id == ID_PAGE_ROOMSLIST)) |
410 if ((!hwnet) && (id == ID_PAGE_ROOMSLIST)) |
411 GoBack(); |
411 GoBack(); |
412 |
412 |
413 if ((!hwnet) || (!hwnet->isInRoom())) |
413 if ((!hwnet) || (!hwnet->isInRoom())) |
414 if (id == ID_PAGE_NETGAME || id == ID_PAGE_NETGAME) |
414 if (id == ID_PAGE_NETGAME || id == ID_PAGE_NETGAME) |
415 GoBack(); |
415 GoBack(); |
416 |
416 |
417 if (curid == ID_PAGE_ROOMSLIST) NetDisconnect(); |
417 if (curid == ID_PAGE_ROOMSLIST) NetDisconnect(); |
441 |
441 |
442 void HWForm::IntermediateSetup() |
442 void HWForm::IntermediateSetup() |
443 { |
443 { |
444 quint8 id=ui.Pages->currentIndex(); |
444 quint8 id=ui.Pages->currentIndex(); |
445 TeamSelWidget* curTeamSelWidget; |
445 TeamSelWidget* curTeamSelWidget; |
446 |
446 |
447 if(id == ID_PAGE_MULTIPLAYER) { |
447 if(id == ID_PAGE_MULTIPLAYER) { |
448 curTeamSelWidget = ui.pageMultiplayer->teamsSelect; |
448 curTeamSelWidget = ui.pageMultiplayer->teamsSelect; |
449 } else { |
449 } else { |
450 curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget; |
450 curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget; |
451 } |
451 } |
452 |
452 |
453 QList<HWTeam> teams = curTeamSelWidget->getDontPlayingTeams(); |
453 QList<HWTeam> teams = curTeamSelWidget->getDontPlayingTeams(); |
454 QStringList tmnames; |
454 QStringList tmnames; |
455 for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) { |
455 for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) { |
456 tmnames += it->TeamName; |
456 tmnames += it->TeamName; |
457 } |
457 } |
542 if(hwnet) { |
542 if(hwnet) { |
543 hwnet->Disconnect(); |
543 hwnet->Disconnect(); |
544 delete hwnet; |
544 delete hwnet; |
545 hwnet=0; |
545 hwnet=0; |
546 } |
546 } |
547 |
547 |
548 ui.pageRoomsList->chatWidget->clear(); |
548 ui.pageRoomsList->chatWidget->clear(); |
549 |
549 |
550 hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
550 hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
551 |
551 |
552 GoToPage(ID_PAGE_CONNECTING); |
552 GoToPage(ID_PAGE_CONNECTING); |
553 |
553 |
554 connect(hwnet, SIGNAL(showMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
554 connect(hwnet, SIGNAL(showMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
565 ui.pageRoomsList, SLOT(setRoomsList(const QStringList&))); |
565 ui.pageRoomsList, SLOT(setRoomsList(const QStringList&))); |
566 connect(hwnet, SIGNAL(adminAccess(bool)), |
566 connect(hwnet, SIGNAL(adminAccess(bool)), |
567 ui.pageRoomsList, SLOT(setAdmin(bool))); |
567 ui.pageRoomsList, SLOT(setAdmin(bool))); |
568 connect(hwnet, SIGNAL(adminAccess(bool)), |
568 connect(hwnet, SIGNAL(adminAccess(bool)), |
569 ui.pageRoomsList->chatWidget, SLOT(adminAccess(bool))); |
569 ui.pageRoomsList->chatWidget, SLOT(adminAccess(bool))); |
570 |
570 |
571 connect(hwnet, SIGNAL(serverMessage(const QString&)), |
571 connect(hwnet, SIGNAL(serverMessage(const QString&)), |
572 ui.pageRoomsList->chatWidget, SLOT(onServerMessage(const QString&))); |
572 ui.pageRoomsList->chatWidget, SLOT(onServerMessage(const QString&))); |
573 |
573 |
574 connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)), |
574 connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)), |
575 hwnet, SLOT(CreateRoom(const QString&))); |
575 hwnet, SLOT(CreateRoom(const QString&))); |
651 connect(ui.pageAdmin, SIGNAL(setServerMessage(const QString&)), hwnet, SLOT(newServerMessage(const QString &))); |
651 connect(ui.pageAdmin, SIGNAL(setServerMessage(const QString&)), hwnet, SLOT(newServerMessage(const QString &))); |
652 connect(ui.pageAdmin->pbClearAccountsCache, SIGNAL(clicked()), hwnet, SLOT(clearAccountsCache())); |
652 connect(ui.pageAdmin->pbClearAccountsCache, SIGNAL(clicked()), hwnet, SLOT(clearAccountsCache())); |
653 |
653 |
654 // disconnect |
654 // disconnect |
655 connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection); |
655 connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection); |
656 |
656 |
657 hwnet->Connect(hostName, port, nick); |
657 hwnet->Connect(hostName, port, nick); |
658 } |
658 } |
659 |
659 |
660 void HWForm::NetConnect() |
660 void HWForm::NetConnect() |
661 { |
661 { |
726 if (hwnet) { |
726 if (hwnet) { |
727 hwnet->deleteLater(); |
727 hwnet->deleteLater(); |
728 hwnet = 0; |
728 hwnet = 0; |
729 QMessageBox::warning(this, QMessageBox::tr("Network"), |
729 QMessageBox::warning(this, QMessageBox::tr("Network"), |
730 QMessageBox::tr("Connection to server is lost")); |
730 QMessageBox::tr("Connection to server is lost")); |
731 |
731 |
732 } |
732 } |
733 if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack(); |
733 if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack(); |
734 } |
734 } |
735 |
735 |
736 void HWForm::NetConnected() |
736 void HWForm::NetConnected() |
764 void HWForm::GameStateChanged(GameState gameState) |
764 void HWForm::GameStateChanged(GameState gameState) |
765 { |
765 { |
766 switch(gameState) { |
766 switch(gameState) { |
767 case gsStarted: { |
767 case gsStarted: { |
768 Music(false); |
768 Music(false); |
769 if (wBackground) wBackground->stopAnimation(); |
769 if (wBackground) wBackground->stopAnimation(); |
770 GoToPage(ID_PAGE_INGAME); |
770 GoToPage(ID_PAGE_INGAME); |
771 ui.pageGameStats->clear(); |
771 ui.pageGameStats->clear(); |
772 if (pRegisterServer) |
772 if (pRegisterServer) |
773 { |
773 { |
774 pRegisterServer->unregister(); |
774 pRegisterServer->unregister(); |
777 break; |
777 break; |
778 } |
778 } |
779 case gsFinished: { |
779 case gsFinished: { |
780 GoBack(); |
780 GoBack(); |
781 Music(ui.pageOptions->CBEnableMusic->isChecked()); |
781 Music(ui.pageOptions->CBEnableMusic->isChecked()); |
782 if (wBackground) wBackground->startAnimation(); |
782 if (wBackground) wBackground->startAnimation(); |
783 GoToPage(ID_PAGE_GAMESTATS); |
783 GoToPage(ID_PAGE_GAMESTATS); |
784 if (hwnet) hwnet->gameFinished(); |
784 if (hwnet) hwnet->gameFinished(); |
785 break; |
785 break; |
786 } |
786 } |
787 default: { |
787 default: { |
788 quint8 id = ui.Pages->currentIndex(); |
788 quint8 id = ui.Pages->currentIndex(); |
789 if (id == ID_PAGE_INGAME) { |
789 if (id == ID_PAGE_INGAME) { |
790 GoBack(); |
790 GoBack(); |
791 Music(ui.pageOptions->CBEnableMusic->isChecked()); |
791 Music(ui.pageOptions->CBEnableMusic->isChecked()); |
792 if (wBackground) wBackground->startAnimation(); |
792 if (wBackground) wBackground->startAnimation(); |
793 if (hwnet) hwnet->gameFinished(); |
793 if (hwnet) hwnet->gameFinished(); |
794 } |
794 } |
795 }; |
795 }; |
796 } |
796 } |
797 } |
797 } |
897 ui.pageNetGame->restrictJoins->setChecked(false); |
897 ui.pageNetGame->restrictJoins->setChecked(false); |
898 ui.pageNetGame->restrictTeamAdds->setChecked(false); |
898 ui.pageNetGame->restrictTeamAdds->setChecked(false); |
899 ui.pageNetGame->pGameCFG->GameSchemes->setModel(ammoSchemeModel); |
899 ui.pageNetGame->pGameCFG->GameSchemes->setModel(ammoSchemeModel); |
900 ui.pageNetGame->pGameCFG->setEnabled(true); |
900 ui.pageNetGame->pGameCFG->setEnabled(true); |
901 ui.pageNetGame->pNetTeamsWidget->setInteractivity(true); |
901 ui.pageNetGame->pNetTeamsWidget->setInteractivity(true); |
902 |
902 |
903 if (hwnet) |
903 if (hwnet) |
904 { |
904 { |
905 // disconnect connections first to ensure their inexistance and not to connect twice |
905 // disconnect connections first to ensure their inexistance and not to connect twice |
906 ui.pageNetGame->BtnStart->disconnect(hwnet); |
906 ui.pageNetGame->BtnStart->disconnect(hwnet); |
907 ui.pageNetGame->restrictJoins->disconnect(hwnet); |
907 ui.pageNetGame->restrictJoins->disconnect(hwnet); |
919 |
919 |
920 void HWForm::NetGameSlave() |
920 void HWForm::NetGameSlave() |
921 { |
921 { |
922 ui.pageNetGame->pGameCFG->setEnabled(false); |
922 ui.pageNetGame->pGameCFG->setEnabled(false); |
923 ui.pageNetGame->pNetTeamsWidget->setInteractivity(false); |
923 ui.pageNetGame->pNetTeamsWidget->setInteractivity(false); |
924 |
924 |
925 if (hwnet) |
925 if (hwnet) |
926 { |
926 { |
927 NetAmmoSchemeModel * netAmmo = new NetAmmoSchemeModel(hwnet); |
927 NetAmmoSchemeModel * netAmmo = new NetAmmoSchemeModel(hwnet); |
928 connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)), netAmmo, SLOT(setNetSchemeConfig(QStringList &))); |
928 connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)), netAmmo, SLOT(setNetSchemeConfig(QStringList &))); |
929 ui.pageNetGame->pGameCFG->GameSchemes->setModel(netAmmo); |
929 ui.pageNetGame->pGameCFG->GameSchemes->setModel(netAmmo); |