# HG changeset patch # User Periklis Ntanasis # Date 1369679992 -10800 # Node ID f92e205bc16717e2df6ef9348fe6c1bd7fe7b54e # Parent db48ce61653142e33dad908289d2603b90153c7c issue 562, image and description for the campaign page diff -r db48ce616531 -r f92e205bc167 QTfrontend/campaign.cpp --- a/QTfrontend/campaign.cpp Tue Jun 11 01:40:55 2013 +0300 +++ b/QTfrontend/campaign.cpp Mon May 27 21:39:52 2013 +0300 @@ -50,3 +50,14 @@ campfile.setIniCodec("UTF-8"); return campfile.value(QString("Mission %1/Script").arg(mNum)).toString(); } + +QString getCampaignImage(QString campaign, unsigned int mNum) +{ + return getCampaignScript(campaign,mNum).replace(QString(".lua"),QString(".png")); +} + +QString getCampaignMissionName(QString campaign, unsigned int mNum) +{ + return getCampaignScript(campaign,mNum).replace(QString(".lua"),QString("")); +} + diff -r db48ce616531 -r f92e205bc167 QTfrontend/campaign.h --- a/QTfrontend/campaign.h Tue Jun 11 01:40:55 2013 +0300 +++ b/QTfrontend/campaign.h Mon May 27 21:39:52 2013 +0300 @@ -25,5 +25,7 @@ QStringList getCampMissionList(QString & campaign); unsigned int getCampProgress(QString & teamName, QString & campName); QString getCampaignScript(QString campaign, unsigned int mNum); +QString getCampaignImage(QString campaign, unsigned int mNum); +QString getCampaignMissionName(QString campaign, unsigned int mNum); #endif diff -r db48ce616531 -r f92e205bc167 QTfrontend/hedgewars.qrc --- a/QTfrontend/hedgewars.qrc Tue Jun 11 01:40:55 2013 +0300 +++ b/QTfrontend/hedgewars.qrc Mon May 27 21:39:52 2013 +0300 @@ -28,6 +28,16 @@ res/botlevels/net3.png res/botlevels/net4.png res/botlevels/net5.png + res/campaign/A Classic Fairytale/first_blood.png + res/campaign/A Classic Fairytale/shadow.png + res/campaign/A Classic Fairytale/journey.png + res/campaign/A Classic Fairytale/united.png + res/campaign/A Classic Fairytale/backstab.png + res/campaign/A Classic Fairytale/dragon.png + res/campaign/A Classic Fairytale/family.png + res/campaign/A Classic Fairytale/queen.png + res/campaign/A Classic Fairytale/enemy.png + res/campaign/A Classic Fairytale/epil.png res/bonus.png res/Hedgehog.png res/net.png diff -r db48ce616531 -r f92e205bc167 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Tue Jun 11 01:40:55 2013 +0300 +++ b/QTfrontend/hwform.cpp Mon May 27 21:39:52 2013 +0300 @@ -194,6 +194,7 @@ //connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload())); #endif + previousCampaignName = ""; UpdateTeamsLists(); InitCampaignPage(); UpdateCampaignPage(0); @@ -306,7 +307,7 @@ connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign())); connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int))); connect(ui.pageCampaign->CBCampaign, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int))); - + connect(ui.pageCampaign->CBMission, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPageMission(int))); connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()), ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first @@ -1901,11 +1902,67 @@ QString tName = team.name(); unsigned int n = missionEntries.count(); unsigned int m = getCampProgress(tName, campaignName); + + // if the campaign name changes update the campaignMissionDescriptions list + // this will be used later in UpdateCampaignPageMission() to update + // the mission description in the campaign page + bool updateMissionList = false; + QSettings * m_info; + if(previousCampaignName.compare(campaignName)!=0) + { + previousCampaignName = campaignName; + updateMissionList = true; + // the following code was based on pagetraining.cpp + DataManager & dataMgr = DataManager::instance(); + // get locale + QSettings settings(dataMgr.settingsFileName(), + QSettings::IniFormat); + QString loc = settings.value("misc/locale", "").toString(); + if (loc.isEmpty()) + loc = QLocale::system().name(); + QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt"); + // if file is non-existant try with language only + if (!QFile::exists(campaignDescFile)) + campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt"); + // fallback if file for current locale is non-existant + if (!QFile::exists(campaignDescFile)) + campaignDescFile = QString("physfs://Locale/campaigns_en.txt"); + + m_info = new QSettings(campaignDescFile, QSettings::IniFormat, this); + m_info->setIniCodec("UTF-8"); + campaignMissionDescriptions.clear(); + ui.pageCampaign->CBMission->clear(); + } + for (unsigned int i = qMin(m + 1, n); i > 0; i--) { - ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1])); + if(updateMissionList) + { + campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc", + tr("No description available")).toString(); + } + ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1])); } + if(updateMissionList) + delete m_info; + UpdateCampaignPageMission(index); +} + +void HWForm::UpdateCampaignPageMission(int index) +{ + // update thumbnail + QString campaignName = ui.pageCampaign->CBCampaign->currentText(); + unsigned int mNum = ui.pageCampaign->CBMission->count() - ui.pageCampaign->CBMission->currentIndex(); + QString image = getCampaignImage(campaignName,mNum); + ui.pageCampaign->btnPreview->setIcon(QIcon((":/res/campaign/"+campaignName+"/"+image))); + // update description + // when campaign changes the UpdateCampaignPageMission is triggered with wrong values + // this will cause segfault. This check prevents illegal memory reads + if(index > -1 && index < campaignMissionDescriptions.count()) { + ui.pageCampaign->lbltitle->setText("

"+ui.pageCampaign->CBMission->currentText()+"

"); + ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]); + } } void HWForm::UpdateCampaignPageProgress(int index) diff -r db48ce616531 -r f92e205bc167 QTfrontend/hwform.h --- a/QTfrontend/hwform.h Tue Jun 11 01:40:55 2013 +0300 +++ b/QTfrontend/hwform.h Mon May 27 21:39:52 2013 +0300 @@ -127,6 +127,7 @@ void Music(bool checked); void UpdateCampaignPage(int index); void UpdateCampaignPageProgress(int index); + void UpdateCampaignPageMission(int index); void InitCampaignPage(); void showFeedbackDialog(); void showFeedbackDialogNetChecked(); @@ -192,6 +193,8 @@ HWNamegen * namegen; AmmoSchemeModel * ammoSchemeModel; QStack PagesStack; + QString previousCampaignName; + QStringList campaignMissionDescriptions; QTime eggTimer; BGWidget * wBackground; QSignalMapper * pageSwitchMapper; diff -r db48ce616531 -r f92e205bc167 QTfrontend/ui/page/pagecampaign.cpp --- a/QTfrontend/ui/page/pagecampaign.cpp Tue Jun 11 01:40:55 2013 +0300 +++ b/QTfrontend/ui/page/pagecampaign.cpp Mon May 27 21:39:52 2013 +0300 @@ -19,6 +19,7 @@ #include #include #include +#include #include "pagecampaign.h" @@ -30,19 +31,44 @@ pageLayout->setColumnStretch(2, 1); pageLayout->setRowStretch(0, 1); pageLayout->setRowStretch(3, 1); + + QGridLayout * infoLayout = new QGridLayout(); + infoLayout->setColumnStretch(0, 1); + infoLayout->setColumnStretch(1, 1); + infoLayout->setColumnStretch(2, 1); + infoLayout->setColumnStretch(3, 1); + infoLayout->setColumnStretch(4, 1); + infoLayout->setRowStretch(0, 1); + infoLayout->setRowStretch(1, 1); + + // set this as default image first time page is created, this will change in hwform.cpp + btnPreview = formattedButton(":/res/campaign/A Classic Fairytale/first_blood.png", true); + infoLayout->setAlignment(btnPreview, Qt::AlignHCenter | Qt::AlignVCenter); + + lbldescription = new QLabel(); + lbldescription->setAlignment(Qt::AlignHCenter| Qt::AlignTop); + lbldescription->setWordWrap(true); + + lbltitle = new QLabel(); + lbltitle->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); CBTeam = new QComboBox(this); CBMission = new QComboBox(this); CBCampaign = new QComboBox(this); - - pageLayout->addWidget(CBTeam, 1, 1); - pageLayout->addWidget(CBCampaign, 2, 1); - pageLayout->addWidget(CBMission, 3, 1); + + infoLayout->addWidget(btnPreview,0,1,2,1); + infoLayout->addWidget(lbltitle,0,2,1,2); + infoLayout->addWidget(lbldescription,1,2,1,2); + + pageLayout->addLayout(infoLayout, 0, 0, 2, 3); + pageLayout->addWidget(CBTeam, 2, 1); + pageLayout->addWidget(CBCampaign, 3, 1); + pageLayout->addWidget(CBMission, 4, 1); BtnStartCampaign = new QPushButton(this); BtnStartCampaign->setFont(*font14); BtnStartCampaign->setText(QPushButton::tr("Go!")); - pageLayout->addWidget(BtnStartCampaign, 2, 2); + pageLayout->addWidget(BtnStartCampaign, 3, 2); return pageLayout; } diff -r db48ce616531 -r f92e205bc167 QTfrontend/ui/page/pagecampaign.h --- a/QTfrontend/ui/page/pagecampaign.h Tue Jun 11 01:40:55 2013 +0300 +++ b/QTfrontend/ui/page/pagecampaign.h Mon May 27 21:39:52 2013 +0300 @@ -28,7 +28,10 @@ public: PageCampaign(QWidget* parent = 0); + QPushButton *btnPreview; QPushButton *BtnStartCampaign; + QLabel *lbldescription; + QLabel *lbltitle; QComboBox *CBMission; QComboBox *CBCampaign; QComboBox *CBTeam; diff -r db48ce616531 -r f92e205bc167 share/hedgewars/Data/Locale/campaigns_en.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/share/hedgewars/Data/Locale/campaigns_en.txt Mon May 27 21:39:52 2013 +0300 @@ -0,0 +1,19 @@ +A Classic Fairytale-first_blood.desc="Help Leaks a lot to complete his training and become a proper hedgehog warrior. You will be trained in the art of rope, parachute, shoryuken and desert eagle." + +A Classic Fairytale-shadow.desc="Leaks a lot and Dense Cloud are going for hunting. Be prepared for the dangers awaiting you at the forest. Remember, make your choices wisely." + +A Classic Fairytale-journey.desc="Leaks a lot has to go to the other side of the island. Be fast and cautious." + +A Classic Fairytale-united.desc="After his long journey Leaks a lot is finally back to the village. However, there isn't time to rest. You have to defend the village from the rage of the cannibals." + +A Classic Fairytale-backstab.desc="The monstrous cannibals are hunting Leaks a lot and his friends. Defeat them once again and protect your allies. Use your resources accordingly to defeat the incoming enemies!" + +A Classic Fairytale-dragon.desc="Leaks a lot has to get to the other side of the lake. Become a rope master and avoid get hit by the enemy shots." + +A Classic Fairytale-family.desc="Leaks a lot has to save once more his allies. Eliminate the enemy hogs and free your comrades. Use your resources carefully as they are limited. Drill some holes in the right spot and go close to the princess." + +A Classic Fairytale-queen.desc="Leaks a lot has to fight once again. In order to win he'll have to fight the traitor and use all the resources available. Defeat the enemy!" + +A Classic Fairytale-enemy.desc="What a great twist! Leaks a lot has to fight side by side with the… “cannibals” against the common enemy. The evil cyborgs!" + +A Classic Fairytale-epil.desc="Congratulations! Leaks a lot can finally leave in peace and get praised by his new friends and his tribe. Be proud for what you succeed! You can play again previous missions and see the other possible endings"