1355 { |
1356 { |
1356 game = new HWGame(config, gamecfg, ammo, pTeamSelWidget); |
1357 game = new HWGame(config, gamecfg, ammo, pTeamSelWidget); |
1357 connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
1358 connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
1358 connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &))); |
1359 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); |
1360 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 &))); |
1361 connect(game, SIGNAL(HaveRecord(RecordType, const QByteArray &)), this, SLOT(GetRecord(RecordType, const QByteArray &))); |
1361 m_lastDemo = QByteArray(); |
1362 m_lastDemo = QByteArray(); |
1362 } |
1363 } |
1363 |
1364 |
1364 void HWForm::ShowErrorMessage(const QString & msg) |
1365 void HWForm::ShowErrorMessage(const QString & msg) |
1365 { |
1366 { |
1366 QMessageBox::warning(this, |
1367 QMessageBox::warning(this, |
1367 "Hedgewars", |
1368 "Hedgewars", |
1368 msg); |
1369 msg); |
1369 } |
1370 } |
1370 |
1371 |
1371 void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
1372 void HWForm::GetRecord(RecordType type, const QByteArray & record) |
1372 { |
1373 { |
1373 QString filename; |
1374 if (type != rtNeither) |
1374 QByteArray demo = record; |
1375 { |
1375 QString recordFileName = |
1376 QString filename; |
1376 config->appendDateTimeToRecordName() ? |
1377 QByteArray demo = record; |
1377 QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") : |
1378 QString recordFileName = |
1378 "LastRound"; |
1379 config->appendDateTimeToRecordName() ? |
1379 |
1380 QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") : |
1380 QStringList versionParts = cVersionString->split('-'); |
1381 "LastRound"; |
1381 if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) ) |
1382 |
1382 recordFileName = recordFileName + "_" + versionParts[1].replace(':','-'); |
1383 QStringList versionParts = cVersionString->split('-'); |
1383 |
1384 if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) ) |
1384 if (isDemo) |
1385 recordFileName = recordFileName + "_" + versionParts[1].replace(':','-'); |
1385 { |
1386 |
1386 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
1387 if (type == rtDemo) |
1387 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
1388 { |
1388 demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD")); |
1389 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
1389 filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd"; |
1390 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
1390 m_lastDemo = demo; |
1391 demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD")); |
1391 } |
1392 filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd"; |
1392 else |
1393 m_lastDemo = demo; |
1393 { |
1394 } |
1394 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
1395 else |
1395 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
1396 { |
1396 filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws"; |
1397 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
1397 } |
1398 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
1398 |
1399 filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws"; |
1399 |
1400 } |
1400 QFile demofile(filename); |
1401 |
1401 if (!demofile.open(QIODevice::WriteOnly)) |
1402 QFile demofile(filename); |
1402 { |
1403 if (!demofile.open(QIODevice::WriteOnly)) |
1403 ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
1404 ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
1404 return ; |
1405 else |
1405 } |
1406 { |
1406 demofile.write(demo); |
1407 demofile.write(demo); |
1407 demofile.close(); |
1408 demofile.close(); |
|
1409 } |
|
1410 } |
|
1411 |
|
1412 QDir videosDir(cfgdir->absolutePath() + "/Videos/"); |
|
1413 QStringList files = videosDir.entryList(QStringList("*.txtout"), QDir::Files); |
|
1414 for (QStringList::iterator str = files.begin(); str != files.end(); str++) |
|
1415 { |
|
1416 str->chop(7); // remove ".txtout" |
|
1417 // need to rename this file to not open it twice |
|
1418 videosDir.rename(*str + ".txtout", *str + ".txtin"); |
|
1419 HWRecorder* pRecorder = new HWRecorder(config); |
|
1420 pRecorder->EncodeVideo(record, *str); |
|
1421 } |
1408 } |
1422 } |
1409 |
1423 |
1410 void HWForm::startTraining(const QString & scriptName) |
1424 void HWForm::startTraining(const QString & scriptName) |
1411 { |
1425 { |
1412 CreateGame(0, 0, 0); |
1426 CreateGame(0, 0, 0); |