QTfrontend/hwform.cpp
branchhedgeroid
changeset 6224 42b256eca362
parent 6223 cc3eb9b7230f
child 6225 505643d4c23d
equal deleted inserted replaced
6055:88cfcd9161d3 6224:42b256eca362
    42 #include <QInputDialog>
    42 #include <QInputDialog>
    43 
    43 
    44 #include "hwform.h"
    44 #include "hwform.h"
    45 #include "game.h"
    45 #include "game.h"
    46 #include "team.h"
    46 #include "team.h"
    47 #include "namegen.h"
       
    48 #include "teamselect.h"
    47 #include "teamselect.h"
    49 #include "selectWeapon.h"
    48 #include "selectWeapon.h"
    50 #include "gameuiconfig.h"
    49 #include "gameuiconfig.h"
    51 #include "pageinfo.h"
    50 #include "pageinfo.h"
    52 #include "pagetraining.h"
    51 #include "pagetraining.h"
    79 #include "ammoSchemeModel.h"
    78 #include "ammoSchemeModel.h"
    80 #include "bgwidget.h"
    79 #include "bgwidget.h"
    81 #include "xfire.h"
    80 #include "xfire.h"
    82 #include "drawmapwidget.h"
    81 #include "drawmapwidget.h"
    83 
    82 
       
    83 #include "HWDataManager.h"
       
    84 
    84 #ifdef __APPLE__
    85 #ifdef __APPLE__
    85 #include "M3Panel.h"
    86 #include "M3Panel.h"
    86 #ifdef SPARKLE_ENABLED
    87 #ifdef SPARKLE_ENABLED
    87 #define SPARKLE_APPCAST_URL "http://www.hedgewars.org/download/appcast.xml"
    88 #define SPARKLE_APPCAST_URL "http://www.hedgewars.org/download/appcast.xml"
    88 #include "SparkleAutoUpdater.h"
    89 #include "SparkleAutoUpdater.h"
    93 // and this one flag does not warrant a static class
    94 // and this one flag does not warrant a static class
    94 bool frontendEffects = true;
    95 bool frontendEffects = true;
    95 QString playerHash;
    96 QString playerHash;
    96 
    97 
    97 HWForm::HWForm(QWidget *parent, QString styleSheet)
    98 HWForm::HWForm(QWidget *parent, QString styleSheet)
    98   : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0)
    99   : QMainWindow(parent)
    99 {
   100   , game(0)
       
   101   , pnetserver(0)
       
   102   , pRegisterServer(0)
       
   103   , editedTeam(0)
       
   104   , hwnet(0)
       
   105 {
       
   106     // set music track
       
   107     SDLInteraction::instance().setMusicTrack(
       
   108         HWDataManager::instance().findFileForRead("Music/main_theme.ogg")
       
   109     );
       
   110 
   100 #ifdef USE_XFIRE
   111 #ifdef USE_XFIRE
   101     xfire_init();
   112     xfire_init();
   102 #endif
   113 #endif
   103     game = NULL;
       
   104     gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
   114     gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
   105     frontendEffects = gameSettings->value("frontend/effects", true).toBool();
   115     frontendEffects = gameSettings->value("frontend/effects", true).toBool();
   106     playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toLatin1(), QCryptographicHash::Md5).toHex());
   116     playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toLatin1(), QCryptographicHash::Md5).toHex());
   107 
   117 
   108     this->setStyleSheet(styleSheet);
   118     this->setStyleSheet(styleSheet);
   109     ui.setupUi(this);
   119     ui.setupUi(this);
   110     setMinimumSize(760, 580);
   120     setMinimumSize(760, 580);
   111     //setFocusPolicy(Qt::StrongFocus);
   121     //setFocusPolicy(Qt::StrongFocus);
   112     CustomizePalettes();
   122     CustomizePalettes();
   113 
   123 
   114     ui.pageOptions->CBResolution->addItems(sdli.getResolutions());
   124     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   115 
   125 
   116     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
   126     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
   117 
   127 
   118     namegen = new HWNamegen();
       
   119 
   128 
   120 #ifdef __APPLE__
   129 #ifdef __APPLE__
   121     panel = new M3Panel;
   130     panel = new M3Panel;
   122 
   131 
   123 #ifdef SPARKLE_ENABLED
   132 #ifdef SPARKLE_ENABLED
   165     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   174     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   166 
   175 
   167     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   176     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   168     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   177     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   169 
   178 
   170     connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   179     //connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   171     connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   180     //connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   172 
   181 
   173     connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
   182     connect(ui.pageEditTeam, SIGNAL(teamEdited()), this, SLOT(AfterTeamEdit()));
   174     connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
       
   175 
       
   176     connect(ui.pageEditTeam->signalMapper2, SIGNAL(mapped(const int &)), this, SLOT(RandomName(const int &)));
       
   177     connect(ui.pageEditTeam->randTeamButton, SIGNAL(clicked()), this, SLOT(RandomNames()));
       
   178 
   183 
   179     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
   184     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
   180     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
   185     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
   181         ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool)));
   186         ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool)));
   182     connect(ui.pageMultiplayer, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   187     connect(ui.pageMultiplayer, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   187 
   192 
   188 
   193 
   189     connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo()));
   194     connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo()));
   190     connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo()));
   195     connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo()));
   191 
   196 
   192     connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam()));
   197     connect(ui.pageOptions, SIGNAL(newTeamRequested()), this, SLOT(NewTeam()));
   193     connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam()));
   198     connect(ui.pageOptions, SIGNAL(editTeamRequested(const QString&)), this, SLOT(EditTeam(const QString&)));
   194     connect(ui.pageOptions->BtnDeleteTeam, SIGNAL(clicked()), this, SLOT(DeleteTeam()));
   199     connect(ui.pageOptions, SIGNAL(deleteTeamRequested(const QString&)), this, SLOT(DeleteTeam(const QString&)));
   195     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
   200     connect(ui.pageOptions->btnSave, SIGNAL(clicked()), config, SLOT(SaveOptions()));
   196     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack()));
   201     connect(ui.pageOptions->btnSave, SIGNAL(clicked()), this, SLOT(GoBack()));
   197     connect(ui.pageOptions->BtnAssociateFiles, SIGNAL(clicked()), this, SLOT(AssociateFiles()));
   202     connect(ui.pageOptions->BtnAssociateFiles, SIGNAL(clicked()), this, SLOT(AssociateFiles()));
   198 
   203 
   199     connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon()));
   204     connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon()));
   200     connect(ui.pageOptions->WeaponNew, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon()));
   205     connect(ui.pageOptions->WeaponNew, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon()));
   201     connect(ui.pageOptions->WeaponDelete, SIGNAL(clicked()), this, SLOT(DeleteWeaponSet()));
   206     connect(ui.pageOptions->WeaponDelete, SIGNAL(clicked()), this, SLOT(DeleteWeaponSet()));
   238     pageSwitchMapper->setMapping(ui.pageSinglePlayer->BtnMultiplayer, ID_PAGE_MULTIPLAYER);
   243     pageSwitchMapper->setMapping(ui.pageSinglePlayer->BtnMultiplayer, ID_PAGE_MULTIPLAYER);
   239 
   244 
   240     connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves()));
   245     connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves()));
   241     connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
   246     connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
   242 
   247 
   243     connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining()));
   248     connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&)));
   244 
   249 
   245     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   250     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   246     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   251     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   247 
   252 
   248 
   253 
   279 }
   284 }
   280 
   285 
   281 #ifdef USE_XFIRE
   286 #ifdef USE_XFIRE
   282 void HWForm::updateXfire(void)
   287 void HWForm::updateXfire(void)
   283 {
   288 {
   284     if(hwnet)
   289     if(hwnet && (hwnet->clientState() != HWNewNet::Disconnected))
   285     {
   290     {
   286         xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii());
   291         xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii());
   287         switch(hwnet->getClientState())
   292         switch(hwnet->clientState())
   288         {
   293         {
   289             case 1: // Connecting
   294             case HWNewNet::Connecting: // Connecting
       
   295             case HWNewNet::Connected:
   290             xfire_setvalue(XFIRE_STATUS, "Connecting");
   296             xfire_setvalue(XFIRE_STATUS, "Connecting");
   291             xfire_setvalue(XFIRE_NICKNAME, "-");
   297             xfire_setvalue(XFIRE_NICKNAME, "-");
   292             xfire_setvalue(XFIRE_ROOM, "-");
   298             xfire_setvalue(XFIRE_ROOM, "-");
   293             case 2: // In lobby
   299             case HWNewNet::InLobby: // In lobby
   294             xfire_setvalue(XFIRE_STATUS, "Online");
   300             xfire_setvalue(XFIRE_STATUS, "Online");
   295             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   301             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   296             xfire_setvalue(XFIRE_ROOM, "In game lobby");
   302             xfire_setvalue(XFIRE_ROOM, "In game lobby");
   297             break;
   303             break;
   298             case 3: // In room
   304             case HWNewNet::InRoom: // In room
   299             xfire_setvalue(XFIRE_STATUS, "Online");
   305             xfire_setvalue(XFIRE_STATUS, "Online");
   300             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   306             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   301             xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii());
   307             xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii());
   302             break;
   308             break;
   303             case 5: // In game
   309             case HWNewNet::InGame: // In game
   304             xfire_setvalue(XFIRE_STATUS, "Online");
   310             xfire_setvalue(XFIRE_STATUS, "Online");
   305             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   311             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   306             xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii());
   312             xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii());
   307             break;
   313             break;
   308             default:
   314             default:
   454 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   460 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   455 {
   461 {
   456 #ifdef USE_XFIRE
   462 #ifdef USE_XFIRE
   457     updateXfire();
   463     updateXfire();
   458 #endif
   464 #endif
       
   465     if (id == ID_PAGE_DATADOWNLOAD)
       
   466     {
       
   467         ui.pageDataDownload->fetchList();
       
   468     }
   459     if (id == ID_PAGE_DRAWMAP) {
   469     if (id == ID_PAGE_DRAWMAP) {
   460         DrawMapScene * scene;
   470         DrawMapScene * scene;
   461         if(lastid == ID_PAGE_MULTIPLAYER)
   471         if(lastid == ID_PAGE_MULTIPLAYER)
   462             scene = ui.pageMultiplayer->gameCFG->pMapContainer->getDrawMapScene();
   472             scene = ui.pageMultiplayer->gameCFG->pMapContainer->getDrawMapScene();
   463         else
   473         else
   471             ui.pageMultiplayer->gameCFG->pMapContainer->mapDrawingFinished();
   481             ui.pageMultiplayer->gameCFG->pMapContainer->mapDrawingFinished();
   472         else
   482         else
   473             ui.pageNetGame->pGameCFG->pMapContainer->mapDrawingFinished();
   483             ui.pageNetGame->pGameCFG->pMapContainer->mapDrawingFinished();
   474     }
   484     }
   475 
   485 
       
   486     if (id == ID_PAGE_ROOMSLIST) {
       
   487         if (hwnet && game && game->gameState == gsStarted) { // abnormal exit - kick or room destruction - send kills.
       
   488             game->netSuspend = true;
       
   489             ui.pageRoomsList->displayWarning(tr("Game aborted"));
       
   490             game->abort();
       
   491         }
       
   492     }
       
   493 
   476     if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) {
   494     if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) {
   477         QStringList tmNames = config->GetTeamsList();
   495         QStringList tmNames = config->GetTeamsList();
   478         TeamSelWidget* curTeamSelWidget;
   496         TeamSelWidget* curTeamSelWidget;
   479         ui.pageOptions->BtnNewTeam->setVisible(false);
   497         ui.pageOptions->setTeamOptionsEnabled(false);
   480         ui.pageOptions->BtnEditTeam->setVisible(false);
       
   481         ui.pageOptions->BtnDeleteTeam->setVisible(false);
       
   482         ui.pageOptions->CBTeamName->setVisible(false);
       
   483         ui.pageOptions->LblNoEditTeam->setVisible(true);
       
   484 
   498 
   485         if (id == ID_PAGE_MULTIPLAYER) {
   499         if (id == ID_PAGE_MULTIPLAYER) {
   486             curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   500             curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   487         } else {
   501         } else {
   488             curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   502             curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   509         if (id == ID_PAGE_GAMESTATS) {
   523         if (id == ID_PAGE_GAMESTATS) {
   510             ui.pageGameStats->renderStats();
   524             ui.pageGameStats->renderStats();
   511         }
   525         }
   512 
   526 
   513     if (id == ID_PAGE_MAIN) {
   527     if (id == ID_PAGE_MAIN) {
   514         ui.pageOptions->BtnNewTeam->setVisible(true);
   528         ui.pageOptions->setTeamOptionsEnabled(true);
   515         ui.pageOptions->BtnEditTeam->setVisible(true);
       
   516         ui.pageOptions->BtnDeleteTeam->setVisible(true);
       
   517         ui.pageOptions->CBTeamName->setVisible(true);
       
   518         ui.pageOptions->LblNoEditTeam->setVisible(false);
       
   519     }
   529     }
   520 
   530 
   521     // load and save ignore/friends lists
   531     // load and save ignore/friends lists
   522     if (lastid == ID_PAGE_NETGAME) // leaving a room
   532     if (lastid == ID_PAGE_NETGAME) // leaving a room
   523         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   533         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   525         ui.pageRoomsList->chatWidget->saveLists(ui.pageOptions->editNetNick->text());
   535         ui.pageRoomsList->chatWidget->saveLists(ui.pageOptions->editNetNick->text());
   526 
   536 
   527     if (id == ID_PAGE_NETGAME) // joining a room
   537     if (id == ID_PAGE_NETGAME) // joining a room
   528         ui.pageNetGame->pChatWidget->loadLists(ui.pageOptions->editNetNick->text());
   538         ui.pageNetGame->pChatWidget->loadLists(ui.pageOptions->editNetNick->text());
   529 // joining the lobby 
   539 // joining the lobby 
   530     else if (id == ID_PAGE_ROOMSLIST) {
   540     else if (id == ID_PAGE_ROOMSLIST)
   531         if (hwnet && game && game->gameState == gsStarted) { // abnormal exit - kick or room destruction - send kills.
       
   532             game->netSuspend = true;
       
   533             game->KillAllTeams();
       
   534         }
       
   535         ui.pageRoomsList->chatWidget->loadLists(ui.pageOptions->editNetNick->text());
   541         ui.pageRoomsList->chatWidget->loadLists(ui.pageOptions->editNetNick->text());
   536     }
   542 
   537 }
   543 }
   538 
   544 
   539 void HWForm::GoToPage(int id)
   545 void HWForm::GoToPage(int id)
   540 {
   546 {
   541     int lastid = ui.Pages->currentIndex();
   547     int lastid = ui.Pages->currentIndex();
   544     ui.Pages->setCurrentIndex(id);
   550     ui.Pages->setCurrentIndex(id);
   545 }
   551 }
   546 
   552 
   547 void HWForm::GoBack()
   553 void HWForm::GoBack()
   548 {
   554 {
       
   555     int curid = ui.Pages->currentIndex();
       
   556     if (curid == ID_PAGE_MAIN)
       
   557         exit();
       
   558 
   549     int id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
   559     int id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
   550     int curid = ui.Pages->currentIndex();
       
   551     ui.Pages->setCurrentIndex(id);
   560     ui.Pages->setCurrentIndex(id);
   552     OnPageShown(id, curid);
   561     OnPageShown(id, curid);
   553 
   562 
   554     if (id == ID_PAGE_CONNECTING)
   563     if (id == ID_PAGE_CONNECTING)
   555         GoBack();
   564         GoBack();
   561     if ((!hwnet) || (!hwnet->isInRoom()))
   570     if ((!hwnet) || (!hwnet->isInRoom()))
   562         if (id == ID_PAGE_NETGAME || id == ID_PAGE_NETGAME)
   571         if (id == ID_PAGE_NETGAME || id == ID_PAGE_NETGAME)
   563             GoBack();
   572             GoBack();
   564 
   573 
   565     if (curid == ID_PAGE_ROOMSLIST || curid == ID_PAGE_CONNECTING) NetDisconnect();
   574     if (curid == ID_PAGE_ROOMSLIST || curid == ID_PAGE_CONNECTING) NetDisconnect();
   566     if (curid == ID_PAGE_NETGAME && hwnet) hwnet->partRoom();
   575     if (curid == ID_PAGE_NETGAME && hwnet && hwnet->isInRoom()) hwnet->partRoom();
   567     // need to work on this, can cause invalid state for admin quit trying to prevent bad state message on kick
   576     // need to work on this, can cause invalid state for admin quit trying to prevent bad state message on kick
   568     //if (curid == ID_PAGE_NETGAME && (!game || game->gameState != gsStarted)) hwnet->partRoom();
   577     //if (curid == ID_PAGE_NETGAME && (!game || game->gameState != gsStarted)) hwnet->partRoom();
   569 
   578 
   570     if (curid == ID_PAGE_SCHEME)
   579     if (curid == ID_PAGE_SCHEME)
   571         ammoSchemeModel->Save();
   580         ammoSchemeModel->Save();
   580 void HWForm::btnExitPressed()
   589 void HWForm::btnExitPressed()
   581 {
   590 {
   582     eggTimer.start();
   591     eggTimer.start();
   583 }
   592 }
   584 
   593 
   585 void HWForm::btnExitClicked()
   594 void HWForm::exit()
   586 {
   595 {
   587     if (eggTimer.elapsed() < 3000){
   596 //   if (eggTimer.elapsed() < 3000){
   588 #ifdef __APPLE__
   597 #ifdef __APPLE__
   589         panel->showInstallController();
   598         panel->showInstallController();
   590 #endif
   599 #endif
   591         close();
   600         close();
   592     }
   601 // TODO reactivate egg
       
   602 /*    }
   593     else
   603     else
   594     {
   604     {
   595         QPushButton * btn = findChild<QPushButton *>("imageButt");
   605         QPushButton * btn = findChild<QPushButton *>("imageButt");
   596         if (btn)
   606         if (btn)
   597         {
   607         {
   598             btn->setIcon(QIcon(":/res/bonus.png"));
   608             btn->setIcon(QIcon(":/res/bonus.png"));
   599         }
   609         }
   600     }
   610     } */
   601 }
   611 }
   602 
   612 
   603 void HWForm::IntermediateSetup()
   613 void HWForm::IntermediateSetup()
   604 {
   614 {
   605     quint8 id=ui.Pages->currentIndex();
   615     quint8 id=ui.Pages->currentIndex();
   622     GoToPage(ID_PAGE_SETUP);
   632     GoToPage(ID_PAGE_SETUP);
   623 }
   633 }
   624 
   634 
   625 void HWForm::NewTeam()
   635 void HWForm::NewTeam()
   626 {
   636 {
   627     editedTeam = new HWTeam(QLineEdit::tr("unnamed"));
   637     ui.pageEditTeam->createTeam(QLineEdit::tr("unnamed"), playerHash);
   628     editedTeam->SetToPage(this);
   638     UpdateTeamsLists();
   629     GoToPage(ID_PAGE_SETUP_TEAM);
   639     GoToPage(ID_PAGE_SETUP_TEAM);
   630 }
   640 }
   631 
   641 
   632 void HWForm::EditTeam()
   642 void HWForm::EditTeam(const QString & teamName)
   633 {
   643 {
   634     editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
   644     ui.pageEditTeam->editTeam(teamName, playerHash);
   635     editedTeam->loadFromFile();
       
   636     editedTeam->SetToPage(this);
       
   637     GoToPage(ID_PAGE_SETUP_TEAM);
   645     GoToPage(ID_PAGE_SETUP_TEAM);
   638 }
   646 }
   639 
   647 
   640 void HWForm::DeleteTeam()
   648 void HWForm::AfterTeamEdit()
   641 {
   649 {
   642     QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel);
       
   643 
       
   644     if (reallyDelete.exec() == QMessageBox::Ok) {
       
   645         editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
       
   646         editedTeam->deleteFile();
       
   647 
       
   648         // Remove from lists
       
   649         ui.pageOptions->CBTeamName->removeItem(ui.pageOptions->CBTeamName->currentIndex());
       
   650     }
       
   651 }
       
   652 
       
   653 void HWForm::RandomNames()
       
   654 {
       
   655     editedTeam->GetFromPage(this);
       
   656     namegen->teamRandomNames(*editedTeam, true);
       
   657     editedTeam->SetToPage(this);
       
   658 }
       
   659 
       
   660 void HWForm::RandomName(const int &i)
       
   661 {
       
   662     editedTeam->GetFromPage(this);
       
   663     namegen->teamRandomName(*editedTeam,i);
       
   664     editedTeam->SetToPage(this);
       
   665 }
       
   666 
       
   667 void HWForm::TeamSave()
       
   668 {
       
   669     editedTeam->GetFromPage(this);
       
   670     editedTeam->saveToFile();
       
   671     delete editedTeam;
       
   672     editedTeam=0;
       
   673     UpdateTeamsLists();
   650     UpdateTeamsLists();
   674     GoBack();
   651     GoBack();
   675 }
   652 }
   676 
   653 
   677 void HWForm::TeamDiscard()
   654 
   678 {
   655 void HWForm::DeleteTeam(const QString & teamName)
   679     delete editedTeam;
   656 {
   680     editedTeam=0;
   657     ui.pageEditTeam->deleteTeam(teamName);
   681     GoBack();
   658     QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel);
       
   659 
       
   660     UpdateTeamsLists();
   682 }
   661 }
   683 
   662 
   684 void HWForm::DeleteScheme()
   663 void HWForm::DeleteScheme()
   685 {
   664 {
   686     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   665     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   796     {
   775     {
   797         case ID_PAGE_INGAME:
   776         case ID_PAGE_INGAME:
   798             ShowErrorMessage(errmsg);
   777             ShowErrorMessage(errmsg);
   799             // no break
   778             // no break
   800         case ID_PAGE_NETGAME:
   779         case ID_PAGE_NETGAME:
   801             ui.pageNetGame->pChatWidget->addLine("Error",errmsg);
   780             ui.pageNetGame->displayError(errmsg);
   802             break;
   781             break;
   803         default:
   782         default:
   804         ui.pageRoomsList->chatWidget->addLine("Error",errmsg);
   783         ui.pageRoomsList->displayError(errmsg);
   805     }
   784     }
   806 }
   785 }
   807 
   786 
   808 void HWForm::NetWarning(const QString & wrnmsg)
   787 void HWForm::NetWarning(const QString & wrnmsg)
   809 {
   788 {
   810     if (ui.Pages->currentIndex() == ID_PAGE_NETGAME || ui.Pages->currentIndex() == ID_PAGE_INGAME)
   789     if (ui.Pages->currentIndex() == ID_PAGE_NETGAME || ui.Pages->currentIndex() == ID_PAGE_INGAME)
   811         ui.pageNetGame->pChatWidget->addLine("Warning",wrnmsg);
   790         ui.pageNetGame->displayWarning(wrnmsg);
   812     else
   791     else
   813         ui.pageRoomsList->chatWidget->addLine("Warning",wrnmsg);
   792         ui.pageRoomsList->displayWarning(wrnmsg);
   814 }
   793 }
   815 
   794 
   816 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick)
   795 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick)
   817 {
   796 {
   818     if(hwnet) {
   797     if(hwnet) {
   826     hwnet = new HWNewNet();
   805     hwnet = new HWNewNet();
   827 
   806 
   828     GoToPage(ID_PAGE_CONNECTING);
   807     GoToPage(ID_PAGE_CONNECTING);
   829 
   808 
   830     connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame()));
   809     connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame()));
   831     connect(hwnet, SIGNAL(Connected()), this, SLOT(NetConnected()));
   810     connect(hwnet, SIGNAL(connected()), this, SLOT(NetConnected()));
   832     connect(hwnet, SIGNAL(Error(const QString&)), this, SLOT(NetError(const QString&)));
   811     connect(hwnet, SIGNAL(Error(const QString&)), this, SLOT(NetError(const QString&)));
   833     connect(hwnet, SIGNAL(Warning(const QString&)), this, SLOT(NetWarning(const QString&)));
   812     connect(hwnet, SIGNAL(Warning(const QString&)), this, SLOT(NetWarning(const QString&)));
   834     connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
   813     connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
   835     connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&)));
   814     connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&)));
   836     connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)));
   815     connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)));
   942     connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int)));
   921     connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int)));
   943     connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars()));
   922     connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars()));
   944     connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache()));
   923     connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache()));
   945 
   924 
   946 // disconnect
   925 // disconnect
   947     connect(hwnet, SIGNAL(Disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection);
   926     connect(hwnet, SIGNAL(disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection);
   948 
   927 
   949 // config stuff
   928 // config stuff
   950     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
   929     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
   951     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
   930     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
   952     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
   931     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1164     }
  1143     }
  1165     demofile.write(demo);
  1144     demofile.write(demo);
  1166     demofile.close();
  1145     demofile.close();
  1167 }
  1146 }
  1168 
  1147 
  1169 void HWForm::StartTraining()
  1148 void HWForm::startTraining(const QString & scriptName)
  1170 {
  1149 {
  1171     CreateGame(0, 0, 0);
  1150     CreateGame(0, 0, 0);
  1172 
  1151 
  1173     game->StartTraining(ui.pageTraining->CBSelect->itemData(ui.pageTraining->CBSelect->currentIndex()).toString());
  1152     game->StartTraining(scriptName);
  1174 }
  1153 }
  1175 
  1154 
  1176 void HWForm::StartCampaign()
  1155 void HWForm::StartCampaign()
  1177 {
  1156 {
  1178     CreateGame(0, 0, 0);
  1157     CreateGame(0, 0, 0);
  1185     QString ammo;
  1164     QString ammo;
  1186     ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData(
  1165     ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData(
  1187             ui.pageNetGame->pGameCFG->WeaponsName->currentIndex()
  1166             ui.pageNetGame->pGameCFG->WeaponsName->currentIndex()
  1188             ).toString();
  1167             ).toString();
  1189 
  1168 
  1190     CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
  1169 	CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
  1191 
  1170 
  1192     connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));
  1171     connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));
  1193     connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &)));
  1172     connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &)));
  1194     connect(game, SIGNAL(SendTeamMessage(const QString &)), hwnet, SLOT(SendTeamMessage(const QString &)));
  1173     connect(game, SIGNAL(SendTeamMessage(const QString &)), hwnet, SLOT(SendTeamMessage(const QString &)));
  1195     connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)));
  1174     connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)));
  1208 }
  1187 }
  1209 
  1188 
  1210 void HWForm::Music(bool checked)
  1189 void HWForm::Music(bool checked)
  1211 {
  1190 {
  1212     if (checked)
  1191     if (checked)
  1213         sdli.StartMusic();
  1192         SDLInteraction::instance().startMusic();
  1214     else
  1193     else
  1215         sdli.StopMusic();
  1194         SDLInteraction::instance().stopMusic();
  1216 }
  1195 }
  1217 
  1196 
  1218 void HWForm::NetGameChangeStatus(bool isMaster)
  1197 void HWForm::NetGameChangeStatus(bool isMaster)
  1219 {
  1198 {
  1220     ui.pageNetGame->pGameCFG->setEnabled(isMaster);
  1199     ui.pageNetGame->pGameCFG->setEnabled(isMaster);
  1238     if (hwnet)
  1217     if (hwnet)
  1239     {
  1218     {
  1240         // disconnect connections first to ensure their inexistance and not to connect twice
  1219         // disconnect connections first to ensure their inexistance and not to connect twice
  1241         ui.pageNetGame->BtnStart->disconnect(hwnet);
  1220         ui.pageNetGame->BtnStart->disconnect(hwnet);
  1242         ui.pageNetGame->BtnUpdate->disconnect(hwnet);
  1221         ui.pageNetGame->BtnUpdate->disconnect(hwnet);
  1243         ui.pageNetGame->leRoomName->setText(hwnet->getRoom());
  1222         ui.pageNetGame->setRoomName(hwnet->getRoom());
  1244         ui.pageNetGame->restrictJoins->disconnect(hwnet);
  1223         ui.pageNetGame->restrictJoins->disconnect(hwnet);
  1245         ui.pageNetGame->restrictTeamAdds->disconnect(hwnet);
  1224         ui.pageNetGame->restrictTeamAdds->disconnect(hwnet);
  1246         connect(ui.pageNetGame->BtnStart, SIGNAL(clicked()), hwnet, SLOT(startGame()));
  1225         connect(ui.pageNetGame->BtnStart, SIGNAL(clicked()), hwnet, SLOT(startGame()));
  1247         connect(ui.pageNetGame, SIGNAL(askForUpdateRoomName(const QString &)),
  1226         connect(ui.pageNetGame, SIGNAL(askForUpdateRoomName(const QString &)),
  1248             hwnet, SLOT(updateRoomName(const QString &)));
  1227             hwnet, SLOT(updateRoomName(const QString &)));
  1284 {
  1263 {
  1285     if (ui.Pages->currentIndex() == ID_PAGE_NETGAME || ui.Pages->currentIndex() == ID_PAGE_INGAME)
  1264     if (ui.Pages->currentIndex() == ID_PAGE_NETGAME || ui.Pages->currentIndex() == ID_PAGE_INGAME)
  1286     {
  1265     {
  1287         GoBack();
  1266         GoBack();
  1288         if (!reason.isEmpty())
  1267         if (!reason.isEmpty())
  1289             ui.pageRoomsList->chatWidget->addLine("Notice",reason);
  1268             ui.pageRoomsList->displayNotice(reason);
  1290     }
  1269     }
  1291     else
  1270     else
  1292         qWarning("Left room while not in room");
  1271         qWarning("Left room while not in room");
  1293 }
  1272 }
  1294 
  1273 
  1307     Q_UNUSED(index);
  1286     Q_UNUSED(index);
  1308 
  1287 
  1309     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1288     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1310     ui.pageCampaign->CBSelect->clear();
  1289     ui.pageCampaign->CBSelect->clear();
  1311 
  1290 
  1312     QDir tmpdir;
  1291     QStringList entries = HWDataManager::instance().entryList(
  1313     tmpdir.cd(cfgdir->absolutePath());
  1292                                                         "Missions/Campaign",
  1314     tmpdir.cd("Data/Missions/Campaign");
  1293                                                         QDir::Files,
  1315     tmpdir.setFilter(QDir::Files);
  1294                                                         QStringList("*#*.lua")
  1316     QStringList userentries = tmpdir.entryList(QStringList("*#*.lua"));
  1295                                                     );
  1317     //entries.sort();
  1296     
  1318     unsigned int n = userentries.count();
  1297     unsigned int n = entries.count();
  1319     for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++)
       
  1320         ui.pageCampaign->CBSelect->addItem(QString(userentries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(userentries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
       
  1321 
       
  1322     tmpdir.cd(datadir->absolutePath());
       
  1323     tmpdir.cd("Missions/Campaign");
       
  1324     tmpdir.setFilter(QDir::Files);
       
  1325     QStringList entries = tmpdir.entryList(QStringList("*#*.lua"));
       
  1326     //entries.sort();
       
  1327     n = entries.count();
       
  1328     for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++) {
  1298     for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++) {
  1329         if (userentries.contains(entries[i])) continue; 
       
  1330         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
  1299         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
  1331     }
  1300     }
  1332 }
  1301 }
  1333 
  1302 
  1334 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1303 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]