QTfrontend/hwform.cpp
changeset 7411 efc75c2d3be9
parent 7313 162bc562335b
parent 7245 53f73f4ae203
child 7490 c422845b8d1f
equal deleted inserted replaced
7409:fd91aa100ce0 7411:efc75c2d3be9
    49 #endif
    49 #endif
    50 
    50 
    51 #include "hwform.h"
    51 #include "hwform.h"
    52 #include "game.h"
    52 #include "game.h"
    53 #include "team.h"
    53 #include "team.h"
       
    54 #include "campaign.h"
    54 #include "teamselect.h"
    55 #include "teamselect.h"
    55 #include "selectWeapon.h"
    56 #include "selectWeapon.h"
    56 #include "gameuiconfig.h"
    57 #include "gameuiconfig.h"
    57 #include "pageinfo.h"
    58 #include "pageinfo.h"
    58 #include "pagetraining.h"
    59 #include "pagetraining.h"
   160     QShortcut * updateData = new QShortcut(QKeySequence("F5"), this);
   161     QShortcut * updateData = new QShortcut(QKeySequence("F5"), this);
   161     connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
   162     connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
   162 #endif
   163 #endif
   163 
   164 
   164     UpdateTeamsLists();
   165     UpdateTeamsLists();
       
   166     InitCampaignPage();
   165     UpdateCampaignPage(0);
   167     UpdateCampaignPage(0);
   166     UpdateWeapons();
   168     UpdateWeapons();
   167 
   169 
   168     // connect all goBack signals
   170     // connect all goBack signals
   169     int nPages = ui.Pages->count();
   171     int nPages = ui.Pages->count();
   271 
   273 
   272     connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&)));
   274     connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&)));
   273 
   275 
   274     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   276     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   275     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   277     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
       
   278     connect(ui.pageCampaign->CBCampaign, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   276 
   279 
   277 
   280 
   278     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
   281     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
   279             ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first
   282             ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first
   280     connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   283     connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
  1352 }
  1355 }
  1353 
  1356 
  1354 void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo)
  1357 void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo)
  1355 {
  1358 {
  1356     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
  1359     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
       
  1360     connect(game, SIGNAL(CampStateChanged(int)), this, SLOT(UpdateCampaignPageProgress(int)));
  1357     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
  1361     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
  1358     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
  1362     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);
  1363     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 &)));
  1364     connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
  1361     m_lastDemo = QByteArray();
  1365     m_lastDemo = QByteArray();
  1416 
  1420 
  1417 void HWForm::StartCampaign()
  1421 void HWForm::StartCampaign()
  1418 {
  1422 {
  1419     CreateGame(0, 0, 0);
  1423     CreateGame(0, 0, 0);
  1420 
  1424 
  1421     game->StartCampaign(ui.pageCampaign->CBSelect->itemData(ui.pageCampaign->CBSelect->currentIndex()).toString());
  1425     QComboBox *combo = ui.pageCampaign->CBMission;
       
  1426     QString camp = ui.pageCampaign->CBCampaign->currentText();
       
  1427     unsigned int mNum = combo->count() - combo->currentIndex();
       
  1428     QString miss = getCampaignScript(camp, mNum);
       
  1429     QString campTeam = ui.pageCampaign->CBTeam->currentText();
       
  1430 
       
  1431     game->StartCampaign(camp, miss, campTeam);
  1422 }
  1432 }
  1423 
  1433 
  1424 void HWForm::CreateNetGame()
  1434 void HWForm::CreateNetGame()
  1425 {
  1435 {
  1426     QString ammo;
  1436     QString ammo;
  1542         wBackground->setFixedSize(w, h);
  1552         wBackground->setFixedSize(w, h);
  1543         wBackground->move(0, 0);
  1553         wBackground->move(0, 0);
  1544     }
  1554     }
  1545 }
  1555 }
  1546 
  1556 
       
  1557 void HWForm::InitCampaignPage()
       
  1558 {
       
  1559     ui.pageCampaign->CBCampaign->clear();
       
  1560     HWTeam team(ui.pageCampaign->CBTeam->currentText());
       
  1561 
       
  1562     QStringList entries = DataManager::instance().entryList(
       
  1563                                   "Missions/Campaign",
       
  1564                                   QDir::Dirs,
       
  1565                                   QStringList("[^\\.]*")
       
  1566                               );
       
  1567 
       
  1568     unsigned int n = entries.count();
       
  1569     for(unsigned int i = 0; i < n; i++)
       
  1570     {
       
  1571         ui.pageCampaign->CBCampaign->addItem(QString(entries[i]), QString(entries[i]));
       
  1572     }
       
  1573 }
       
  1574 
       
  1575 
  1547 void HWForm::UpdateCampaignPage(int index)
  1576 void HWForm::UpdateCampaignPage(int index)
  1548 {
  1577 {
  1549     Q_UNUSED(index);
  1578     Q_UNUSED(index);
  1550 
  1579 
  1551     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1580     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1552     ui.pageCampaign->CBSelect->clear();
  1581     ui.pageCampaign->CBMission->clear();
  1553 
  1582 
  1554     QStringList entries = DataManager::instance().entryList(
  1583     QString campaignName = ui.pageCampaign->CBCampaign->currentText();
  1555                               "Missions/Campaign",
  1584     QStringList missionEntries = getCampMissionList(campaignName);
  1556                               QDir::Files,
  1585     QString tName = team.name();
  1557                               QStringList("*#*.lua")
  1586     unsigned int n = missionEntries.count();
  1558                           );
  1587     unsigned int m = getCampProgress(tName, campaignName);
  1559 
  1588 
  1560     unsigned int n = entries.count();
  1589     for (unsigned int i = min(m + 1, n); i > 0; i--)
  1561     for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++)
  1590     {
  1562     {
  1591         ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
  1563         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
  1592     }
  1564     }
  1593 }
       
  1594 
       
  1595 void HWForm::UpdatecampaignPageProgress(int index)
       
  1596 {
       
  1597   int missionIndex = ui.pageCampaign->CBMission->currentIndex();
       
  1598   UpdateCampaignPage(0);
       
  1599   ui.pageCampaign->CBMission->setCurrentIndex(missionIndex);
  1565 }
  1600 }
  1566 
  1601 
  1567 // 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]
  1602 // 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]
  1568 QString HWForm::getDemoArguments()
  1603 QString HWForm::getDemoArguments()
  1569 {
  1604 {