QTfrontend/hwform.cpp
changeset 7628 bc7b1d228a2c
parent 7490 c422845b8d1f
parent 7617 0ac281e1b58b
child 7636 10caa79d4a80
equal deleted inserted replaced
7533:7ee319134713 7628:bc7b1d228a2c
    75 #include "pagedrawmap.h"
    75 #include "pagedrawmap.h"
    76 #include "pagenettype.h"
    76 #include "pagenettype.h"
    77 #include "pagegamestats.h"
    77 #include "pagegamestats.h"
    78 #include "pageplayrecord.h"
    78 #include "pageplayrecord.h"
    79 #include "pagedata.h"
    79 #include "pagedata.h"
       
    80 #include "pagevideos.h"
    80 #include "hwconsts.h"
    81 #include "hwconsts.h"
    81 #include "newnetclient.h"
    82 #include "newnetclient.h"
    82 #include "gamecfgwidget.h"
    83 #include "gamecfgwidget.h"
    83 #include "netserverslist.h"
    84 #include "netserverslist.h"
    84 #include "netudpserver.h"
    85 #include "netudpserver.h"
    89 #include "bgwidget.h"
    90 #include "bgwidget.h"
    90 #include "xfire.h"
    91 #include "xfire.h"
    91 #include "drawmapwidget.h"
    92 #include "drawmapwidget.h"
    92 #include "mouseoverfilter.h"
    93 #include "mouseoverfilter.h"
    93 #include "roomslistmodel.h"
    94 #include "roomslistmodel.h"
       
    95 #include "recorder.h"
    94 
    96 
    95 #include "DataManager.h"
    97 #include "DataManager.h"
    96 
    98 
    97 #ifdef __APPLE__
    99 #ifdef __APPLE__
    98 #include "M3Panel.h"
   100 #include "M3Panel.h"
   138     CustomizePalettes();
   140     CustomizePalettes();
   139 
   141 
   140     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   142     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   141 
   143 
   142     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
   144     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
       
   145 
       
   146     ui.pageVideos->init(config);
   143 
   147 
   144 #ifdef __APPLE__
   148 #ifdef __APPLE__
   145     panel = new M3Panel;
   149     panel = new M3Panel;
   146 
   150 
   147 #ifdef SPARKLE_ENABLED
   151 #ifdef SPARKLE_ENABLED
   198     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   202     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   199 
   203 
   200     connect(ui.pageNetGame, SIGNAL(DLCClicked()), pageSwitchMapper, SLOT(map()));
   204     connect(ui.pageNetGame, SIGNAL(DLCClicked()), pageSwitchMapper, SLOT(map()));
   201     pageSwitchMapper->setMapping(ui.pageNetGame, ID_PAGE_DATADOWNLOAD);
   205     pageSwitchMapper->setMapping(ui.pageNetGame, ID_PAGE_DATADOWNLOAD);
   202 
   206 
       
   207 #ifdef VIDEOREC
       
   208     connect(ui.pageMain->BtnVideos, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
       
   209     pageSwitchMapper->setMapping(ui.pageMain->BtnVideos, ID_PAGE_VIDEOS);
       
   210 #endif
       
   211 
   203     //connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   212     //connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   204     //connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   213     //connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   205 
   214 
   206     connect(ui.pageFeedback->BtnSend, SIGNAL(clicked()), this, SLOT(SendFeedback()));
   215     connect(ui.pageFeedback->BtnSend, SIGNAL(clicked()), this, SLOT(SendFeedback()));
   207 
   216 
   208     connect(ui.pageEditTeam, SIGNAL(teamEdited()), this, SLOT(AfterTeamEdit()));
   217     connect(ui.pageEditTeam, SIGNAL(goBack()), this, SLOT(AfterTeamEdit()));
   209 
   218 
   210     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
   219     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
   211     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
   220     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
   212             ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool)));
   221             ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool)));
   213     connect(ui.pageMultiplayer, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   222     connect(ui.pageMultiplayer, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   289     connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet()));
   298     connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet()));
   290     connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   299     connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   291 
   300 
   292     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
   301     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
   293 
   302 
       
   303     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   294 
   304 
   295     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
   305     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
   296     ui.pageScheme->setModel(ammoSchemeModel);
   306     ui.pageScheme->setModel(ammoSchemeModel);
   297     ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel);
   307     ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel);
   298     ui.pageOptions->SchemesName->setModel(ammoSchemeModel);
   308     ui.pageOptions->SchemesName->setModel(ammoSchemeModel);
   513 {
   523 {
   514     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   524     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   515     GoToPage(ID_PAGE_SCHEME);
   525     GoToPage(ID_PAGE_SCHEME);
   516 }
   526 }
   517 
   527 
       
   528 void HWForm::GoToVideos()
       
   529 {
       
   530     GoToPage(ID_PAGE_VIDEOS);
       
   531 }
       
   532 
   518 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   533 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   519 {
   534 {
   520 #ifdef USE_XFIRE
   535 #ifdef USE_XFIRE
   521     updateXfire();
   536     updateXfire();
   522 #endif
   537 #endif
   602     }
   617     }
   603 
   618 
   604     if (id == ID_PAGE_SETUP)
   619     if (id == ID_PAGE_SETUP)
   605     {
   620     {
   606         config->reloadValues();
   621         config->reloadValues();
       
   622     }
       
   623 
       
   624     if (id == ID_PAGE_VIDEOS )
       
   625     {
       
   626         config->reloadVideosValues();
   607     }
   627     }
   608 
   628 
   609     // load and save ignore/friends lists
   629     // load and save ignore/friends lists
   610     if (lastid == ID_PAGE_NETGAME) // leaving a room
   630     if (lastid == ID_PAGE_NETGAME) // leaving a room
   611         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   631         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   705 {
   725 {
   706     bool stopAnim = false;
   726     bool stopAnim = false;
   707     int curid = ui.Pages->currentIndex();
   727     int curid = ui.Pages->currentIndex();
   708     if (curid == ID_PAGE_MAIN)
   728     if (curid == ID_PAGE_MAIN)
   709     {
   729     {
       
   730         if (!ui.pageVideos->tryQuit(this))
       
   731             return;
   710         stopAnim = true;
   732         stopAnim = true;
   711         exit();
   733         exit();
   712     }
   734     }
   713 
   735 
   714     int id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
   736     int id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
   879 }
   901 }
   880 
   902 
   881 void HWForm::AfterTeamEdit()
   903 void HWForm::AfterTeamEdit()
   882 {
   904 {
   883     UpdateTeamsLists();
   905     UpdateTeamsLists();
   884     GoBack();
   906     //GoBack();
   885 }
   907 }
   886 
   908 
   887 
   909 
   888 void HWForm::DeleteTeam(const QString & teamName)
   910 void HWForm::DeleteTeam(const QString & teamName)
   889 {
   911 {
  1359     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
  1381     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
  1360     connect(game, SIGNAL(CampStateChanged(int)), this, SLOT(UpdateCampaignPageProgress(int)));
  1382     connect(game, SIGNAL(CampStateChanged(int)), this, SLOT(UpdateCampaignPageProgress(int)));
  1361     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
  1383     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
  1362     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
  1384     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
  1363     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
  1385     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
  1364     connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
  1386     connect(game, SIGNAL(HaveRecord(RecordType, const QByteArray &)), this, SLOT(GetRecord(RecordType, const QByteArray &)));
  1365     m_lastDemo = QByteArray();
  1387     m_lastDemo = QByteArray();
  1366 }
  1388 }
  1367 
  1389 
  1368 void HWForm::ShowErrorMessage(const QString & msg)
  1390 void HWForm::ShowErrorMessage(const QString & msg)
  1369 {
  1391 {
  1370     QMessageBox::warning(this,
  1392     QMessageBox::warning(this,
  1371                          "Hedgewars",
  1393                          "Hedgewars",
  1372                          msg);
  1394                          msg);
  1373 }
  1395 }
  1374 
  1396 
  1375 void HWForm::GetRecord(bool isDemo, const QByteArray & record)
  1397 void HWForm::GetRecord(RecordType type, const QByteArray & record)
  1376 {
  1398 {
  1377     QString filename;
  1399     if (type != rtNeither)
  1378     QByteArray demo = record;
  1400     {
  1379     QString recordFileName =
  1401         QString filename;
  1380         config->appendDateTimeToRecordName() ?
  1402         QByteArray demo = record;
  1381         QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") :
  1403         QString recordFileName =
  1382         "LastRound";
  1404             config->appendDateTimeToRecordName() ?
  1383 
  1405             QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") :
  1384     QStringList versionParts = cVersionString->split('-');
  1406             "LastRound";
  1385     if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) )
  1407 
  1386         recordFileName = recordFileName + "_" + versionParts[1].replace(':','-');
  1408         QStringList versionParts = cVersionString->split('-');
  1387 
  1409         if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) )
  1388     if (isDemo)
  1410             recordFileName = recordFileName + "_" + versionParts[1].replace(':','-');
  1389     {
  1411 
  1390         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
  1412         if (type == rtDemo)
  1391         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
  1413         {
  1392         demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
  1414             demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
  1393         filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
  1415             demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
  1394         m_lastDemo = demo;
  1416             demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
  1395     }
  1417             filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
  1396     else
  1418             m_lastDemo = demo;
  1397     {
  1419         }
  1398         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
  1420         else
  1399         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
  1421         {
  1400         filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1422             demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
  1401     }
  1423             demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
  1402 
  1424             filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1403 
  1425         }
  1404     QFile demofile(filename);
  1426 
  1405     if (!demofile.open(QIODevice::WriteOnly))
  1427         QFile demofile(filename);
  1406     {
  1428         if (!demofile.open(QIODevice::WriteOnly))
  1407         ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
  1429             ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
  1408         return ;
  1430         else
  1409     }
  1431         {
  1410     demofile.write(demo);
  1432             demofile.write(demo);
  1411     demofile.close();
  1433             demofile.close();
       
  1434         }
       
  1435     }
       
  1436 
       
  1437     ui.pageVideos->startEncoding(record);
  1412 }
  1438 }
  1413 
  1439 
  1414 void HWForm::startTraining(const QString & scriptName)
  1440 void HWForm::startTraining(const QString & scriptName)
  1415 {
  1441 {
  1416     CreateGame(0, 0, 0);
  1442     CreateGame(0, 0, 0);
  1453 {
  1479 {
  1454 #ifdef USE_XFIRE
  1480 #ifdef USE_XFIRE
  1455     xfire_free();
  1481     xfire_free();
  1456 #endif
  1482 #endif
  1457     config->SaveOptions();
  1483     config->SaveOptions();
       
  1484     config->SaveVideosOptions();
  1458     event->accept();
  1485     event->accept();
  1459 }
  1486 }
  1460 
  1487 
  1461 void HWForm::Music(bool checked)
  1488 void HWForm::Music(bool checked)
  1462 {
  1489 {