QTfrontend/hwform.cpp
branchhedgeroid
changeset 5824 2e5835130d9a
parent 5773 c277657854a2
child 5849 b84b41aba275
equal deleted inserted replaced
5733:5ab22736bdb6 5824:2e5835130d9a
    36 #include <QTableView>
    36 #include <QTableView>
    37 #include <QCryptographicHash>
    37 #include <QCryptographicHash>
    38 #include <QSignalMapper>
    38 #include <QSignalMapper>
    39 #include <QShortcut>
    39 #include <QShortcut>
    40 #include <QDesktopServices>
    40 #include <QDesktopServices>
       
    41 #include <QInputDialog>
    41 
    42 
    42 #include "hwform.h"
    43 #include "hwform.h"
    43 #include "game.h"
    44 #include "game.h"
    44 #include "team.h"
    45 #include "team.h"
    45 #include "namegen.h"
    46 #include "namegen.h"
   149     connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   150     connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   150     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
   151     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
   151     
   152     
   152     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   153     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   153     pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE);
   154     pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE);
       
   155 
   154     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   156     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   155     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_DATADOWNLOAD);
   157     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
       
   158 
       
   159     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
       
   160     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   156 
   161 
   157     connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   162     connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   158     connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   163     connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   159 
   164 
       
   165     connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
   160     connect(ui.pageDataDownload->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
   166     connect(ui.pageDataDownload->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
   161 
   167 
   162     connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
   168     connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
   163     connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
   169     connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
   164 
   170 
   221 
   227 
   222     connect(ui.pageInfo->BtnSnapshots, SIGNAL(clicked()), this, SLOT(OpenSnapshotFolder()));
   228     connect(ui.pageInfo->BtnSnapshots, SIGNAL(clicked()), this, SLOT(OpenSnapshotFolder()));
   223     connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
   229     connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
   224 
   230 
   225     connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
   231     connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
       
   232     connect(ui.pageGameStats, SIGNAL(saveDemoRequested()), this, SLOT(saveDemoWithCustomName()));
   226 
   233 
   227     connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame()));
   234     connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame()));
   228     connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   235     connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   229     pageSwitchMapper->setMapping(ui.pageSinglePlayer->BtnTrainPage, ID_PAGE_TRAINING);
   236     pageSwitchMapper->setMapping(ui.pageSinglePlayer->BtnTrainPage, ID_PAGE_TRAINING);
   230 
   237 
   617     } else {
   624     } else {
   618         curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   625         curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   619     }
   626     }
   620 
   627 
   621     QStringList tmnames;
   628     QStringList tmnames;
   622     QListIterator<HWTeam> it(curTeamSelWidget->getDontPlayingTeams());
   629 
   623     while(it.hasNext()) tmnames += it.next().TeamName;
   630     foreach(HWTeam team, curTeamSelWidget->getNotPlayingTeams())
       
   631         tmnames += team.TeamName;
   624 
   632 
   625     //UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
   633     //UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
   626     UpdateTeamsLists();
   634     UpdateTeamsLists();
   627 
   635 
   628     GoToPage(ID_PAGE_SETUP);
   636     GoToPage(ID_PAGE_SETUP);
  1031     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
  1039     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
  1032     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
  1040     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
  1033     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
  1041     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
  1034     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
  1042     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
  1035     connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
  1043     connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
       
  1044     m_lastDemo = QByteArray();
  1036 }
  1045 }
  1037 
  1046 
  1038 void HWForm::ShowErrorMessage(const QString & msg)
  1047 void HWForm::ShowErrorMessage(const QString & msg)
  1039 {
  1048 {
  1040     QMessageBox::warning(this,
  1049     QMessageBox::warning(this,
  1059     {
  1068     {
  1060         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
  1069         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
  1061         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
  1070         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
  1062         demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
  1071         demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
  1063         filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
  1072         filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
       
  1073         m_lastDemo = demo;
  1064     } else
  1074     } else
  1065     {
  1075     {
  1066         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
  1076         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
  1067         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
  1077         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
  1068         filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1078         filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1073     if (!demofile.open(QIODevice::WriteOnly))
  1083     if (!demofile.open(QIODevice::WriteOnly))
  1074     {
  1084     {
  1075         ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
  1085         ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
  1076         return ;
  1086         return ;
  1077     }
  1087     }
  1078     demofile.write(demo.constData(), demo.size());
  1088     demofile.write(demo);
  1079     demofile.close();
  1089     demofile.close();
  1080 }
  1090 }
  1081 
  1091 
  1082 void HWForm::StartTraining()
  1092 void HWForm::StartTraining()
  1083 {
  1093 {
  1291 #endif
  1301 #endif
  1292     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1302     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1293     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  1303     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  1294 }
  1304 }
  1295 
  1305 
       
  1306 void HWForm::saveDemoWithCustomName()
       
  1307 {
       
  1308     if(!m_lastDemo.isEmpty())
       
  1309     {
       
  1310         QString fileName;
       
  1311         bool ok = false;
       
  1312         do
       
  1313         {
       
  1314             fileName = QInputDialog::getText(this, tr("Demo name"), tr("Demo name:"));
       
  1315             
       
  1316             if(!fileName.isEmpty())
       
  1317             {
       
  1318                 QString filePath = cfgdir->absolutePath() + "/Demos/" + fileName + "." + *cProtoVer + ".hwd";
       
  1319                 QFile demofile(filePath);
       
  1320                 ok = demofile.open(QIODevice::WriteOnly);
       
  1321                 if (!ok)
       
  1322                     ShowErrorMessage(tr("Cannot save record to file %1").arg(filePath));
       
  1323                 else
       
  1324                 {
       
  1325                     ok = -1 != demofile.write(m_lastDemo);
       
  1326                     demofile.close();
       
  1327                 }
       
  1328             }
       
  1329         } while(!fileName.isEmpty() && !ok);
       
  1330     }
       
  1331 }
       
  1332