QTfrontend/hwform.cpp
changeset 7615 b39beffcf05e
parent 7565 00568d3054d0
child 7617 0ac281e1b58b
equal deleted inserted replaced
7614:3ae60c8a15f2 7615:b39beffcf05e
    74 #include "pagedrawmap.h"
    74 #include "pagedrawmap.h"
    75 #include "pagenettype.h"
    75 #include "pagenettype.h"
    76 #include "pagegamestats.h"
    76 #include "pagegamestats.h"
    77 #include "pageplayrecord.h"
    77 #include "pageplayrecord.h"
    78 #include "pagedata.h"
    78 #include "pagedata.h"
       
    79 #include "pagevideos.h"
    79 #include "hwconsts.h"
    80 #include "hwconsts.h"
    80 #include "newnetclient.h"
    81 #include "newnetclient.h"
    81 #include "gamecfgwidget.h"
    82 #include "gamecfgwidget.h"
    82 #include "netserverslist.h"
    83 #include "netserverslist.h"
    83 #include "netudpserver.h"
    84 #include "netudpserver.h"
    88 #include "bgwidget.h"
    89 #include "bgwidget.h"
    89 #include "xfire.h"
    90 #include "xfire.h"
    90 #include "drawmapwidget.h"
    91 #include "drawmapwidget.h"
    91 #include "mouseoverfilter.h"
    92 #include "mouseoverfilter.h"
    92 #include "roomslistmodel.h"
    93 #include "roomslistmodel.h"
       
    94 #include "recorder.h"
    93 
    95 
    94 #include "DataManager.h"
    96 #include "DataManager.h"
    95 
    97 
    96 #ifdef __APPLE__
    98 #ifdef __APPLE__
    97 #include "M3Panel.h"
    99 #include "M3Panel.h"
   137     CustomizePalettes();
   139     CustomizePalettes();
   138 
   140 
   139     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   141     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   140 
   142 
   141     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
   143     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
       
   144 
       
   145     ui.pageVideos->init(config);
   142 
   146 
   143 #ifdef __APPLE__
   147 #ifdef __APPLE__
   144     panel = new M3Panel;
   148     panel = new M3Panel;
   145 
   149 
   146 #ifdef SPARKLE_ENABLED
   150 #ifdef SPARKLE_ENABLED
   196     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   200     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   197 
   201 
   198     connect(ui.pageNetGame, SIGNAL(DLCClicked()), pageSwitchMapper, SLOT(map()));
   202     connect(ui.pageNetGame, SIGNAL(DLCClicked()), pageSwitchMapper, SLOT(map()));
   199     pageSwitchMapper->setMapping(ui.pageNetGame, ID_PAGE_DATADOWNLOAD);
   203     pageSwitchMapper->setMapping(ui.pageNetGame, ID_PAGE_DATADOWNLOAD);
   200 
   204 
       
   205     connect(ui.pageMain->BtnVideos, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
       
   206     pageSwitchMapper->setMapping(ui.pageMain->BtnVideos, ID_PAGE_VIDEOS);
       
   207 
   201     //connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   208     //connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   202     //connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   209     //connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   203 
   210 
   204     connect(ui.pageFeedback->BtnSend, SIGNAL(clicked()), this, SLOT(SendFeedback()));
   211     connect(ui.pageFeedback->BtnSend, SIGNAL(clicked()), this, SLOT(SendFeedback()));
   205 
   212 
   286     connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet()));
   293     connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet()));
   287     connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   294     connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   288 
   295 
   289     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
   296     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
   290 
   297 
       
   298     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   291 
   299 
   292     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
   300     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
   293     ui.pageScheme->setModel(ammoSchemeModel);
   301     ui.pageScheme->setModel(ammoSchemeModel);
   294     ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel);
   302     ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel);
   295     ui.pageOptions->SchemesName->setModel(ammoSchemeModel);
   303     ui.pageOptions->SchemesName->setModel(ammoSchemeModel);
   510 {
   518 {
   511     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   519     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   512     GoToPage(ID_PAGE_SCHEME);
   520     GoToPage(ID_PAGE_SCHEME);
   513 }
   521 }
   514 
   522 
       
   523 void HWForm::GoToVideos()
       
   524 {
       
   525     GoToPage(ID_PAGE_VIDEOS);
       
   526 }
       
   527 
   515 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   528 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   516 {
   529 {
   517 #ifdef USE_XFIRE
   530 #ifdef USE_XFIRE
   518     updateXfire();
   531     updateXfire();
   519 #endif
   532 #endif
   599     }
   612     }
   600 
   613 
   601     if (id == ID_PAGE_SETUP)
   614     if (id == ID_PAGE_SETUP)
   602     {
   615     {
   603         config->reloadValues();
   616         config->reloadValues();
       
   617     }
       
   618 
       
   619     if (id == ID_PAGE_VIDEOS )
       
   620     {
       
   621         config->reloadVideosValues();
   604     }
   622     }
   605 
   623 
   606     // load and save ignore/friends lists
   624     // load and save ignore/friends lists
   607     if (lastid == ID_PAGE_NETGAME) // leaving a room
   625     if (lastid == ID_PAGE_NETGAME) // leaving a room
   608         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   626         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   702 {
   720 {
   703     bool stopAnim = false;
   721     bool stopAnim = false;
   704     int curid = ui.Pages->currentIndex();
   722     int curid = ui.Pages->currentIndex();
   705     if (curid == ID_PAGE_MAIN)
   723     if (curid == ID_PAGE_MAIN)
   706     {
   724     {
       
   725         if (!ui.pageVideos->tryQuit(this))
       
   726             return;
   707         stopAnim = true;
   727         stopAnim = true;
   708         exit();
   728         exit();
   709     }
   729     }
   710 
   730 
   711     int id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
   731     int id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
  1355 {
  1375 {
  1356     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
  1376     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
  1357     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
  1377     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
  1358     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
  1378     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
  1359     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
  1379     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
  1360     connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
  1380     connect(game, SIGNAL(HaveRecord(RecordType, const QByteArray &)), this, SLOT(GetRecord(RecordType, const QByteArray &)));
  1361     m_lastDemo = QByteArray();
  1381     m_lastDemo = QByteArray();
  1362 }
  1382 }
  1363 
  1383 
  1364 void HWForm::ShowErrorMessage(const QString & msg)
  1384 void HWForm::ShowErrorMessage(const QString & msg)
  1365 {
  1385 {
  1366     QMessageBox::warning(this,
  1386     QMessageBox::warning(this,
  1367                          "Hedgewars",
  1387                          "Hedgewars",
  1368                          msg);
  1388                          msg);
  1369 }
  1389 }
  1370 
  1390 
  1371 void HWForm::GetRecord(bool isDemo, const QByteArray & record)
  1391 void HWForm::GetRecord(RecordType type, const QByteArray & record)
  1372 {
  1392 {
  1373     QString filename;
  1393     if (type != rtNeither)
  1374     QByteArray demo = record;
  1394     {
  1375     QString recordFileName =
  1395         QString filename;
  1376         config->appendDateTimeToRecordName() ?
  1396         QByteArray demo = record;
  1377         QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") :
  1397         QString recordFileName =
  1378         "LastRound";
  1398             config->appendDateTimeToRecordName() ?
  1379 
  1399             QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") :
  1380     QStringList versionParts = cVersionString->split('-');
  1400             "LastRound";
  1381     if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) )
  1401 
  1382         recordFileName = recordFileName + "_" + versionParts[1].replace(':','-');
  1402         QStringList versionParts = cVersionString->split('-');
  1383 
  1403         if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) )
  1384     if (isDemo)
  1404             recordFileName = recordFileName + "_" + versionParts[1].replace(':','-');
  1385     {
  1405 
  1386         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
  1406         if (type == rtDemo)
  1387         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
  1407         {
  1388         demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
  1408             demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
  1389         filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
  1409             demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
  1390         m_lastDemo = demo;
  1410             demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
  1391     }
  1411             filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
  1392     else
  1412             m_lastDemo = demo;
  1393     {
  1413         }
  1394         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
  1414         else
  1395         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
  1415         {
  1396         filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1416             demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
  1397     }
  1417             demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
  1398 
  1418             filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1399 
  1419         }
  1400     QFile demofile(filename);
  1420 
  1401     if (!demofile.open(QIODevice::WriteOnly))
  1421         QFile demofile(filename);
  1402     {
  1422         if (!demofile.open(QIODevice::WriteOnly))
  1403         ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
  1423             ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
  1404         return ;
  1424         else
  1405     }
  1425         {
  1406     demofile.write(demo);
  1426             demofile.write(demo);
  1407     demofile.close();
  1427             demofile.close();
       
  1428         }
       
  1429     }
       
  1430 
       
  1431     ui.pageVideos->startEncoding(record);
  1408 }
  1432 }
  1409 
  1433 
  1410 void HWForm::startTraining(const QString & scriptName)
  1434 void HWForm::startTraining(const QString & scriptName)
  1411 {
  1435 {
  1412     CreateGame(0, 0, 0);
  1436     CreateGame(0, 0, 0);
  1443 {
  1467 {
  1444 #ifdef USE_XFIRE
  1468 #ifdef USE_XFIRE
  1445     xfire_free();
  1469     xfire_free();
  1446 #endif
  1470 #endif
  1447     config->SaveOptions();
  1471     config->SaveOptions();
       
  1472     config->SaveVideosOptions();
  1448     event->accept();
  1473     event->accept();
  1449 }
  1474 }
  1450 
  1475 
  1451 void HWForm::Music(bool checked)
  1476 void HWForm::Music(bool checked)
  1452 {
  1477 {