bring windows fixes from main repo
authorkoda
Thu, 13 Jun 2013 14:44:28 +0200
changeset 9219 0a4b6bb69f99
parent 9218 673bf356ad8c (current diff)
parent 9191 fc54667b1203 (diff)
child 9220 5e7db24f3489
bring windows fixes from main repo
QTfrontend/campaign.cpp
QTfrontend/hwform.cpp
QTfrontend/ui/page/pagecampaign.cpp
QTfrontend/ui/page/pagecampaign.h
cmake_modules/compilerchecks.cmake
cmake_modules/platform.cmake
--- a/QTfrontend/campaign.cpp	Wed Jun 12 19:30:44 2013 +0200
+++ b/QTfrontend/campaign.cpp	Thu Jun 13 14:44:28 2013 +0200
@@ -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(""));
+}
+
--- a/QTfrontend/campaign.h	Wed Jun 12 19:30:44 2013 +0200
+++ b/QTfrontend/campaign.h	Thu Jun 13 14:44:28 2013 +0200
@@ -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
--- a/QTfrontend/hedgewars.qrc	Wed Jun 12 19:30:44 2013 +0200
+++ b/QTfrontend/hedgewars.qrc	Thu Jun 13 14:44:28 2013 +0200
@@ -28,6 +28,16 @@
         <file>res/botlevels/net3.png</file>
         <file>res/botlevels/net4.png</file>
         <file>res/botlevels/net5.png</file>
+        <file>res/campaign/A Classic Fairytale/first_blood.png</file>
+        <file>res/campaign/A Classic Fairytale/shadow.png</file>
+        <file>res/campaign/A Classic Fairytale/journey.png</file>
+        <file>res/campaign/A Classic Fairytale/united.png</file>
+        <file>res/campaign/A Classic Fairytale/backstab.png</file>
+        <file>res/campaign/A Classic Fairytale/dragon.png</file>
+        <file>res/campaign/A Classic Fairytale/family.png</file>
+        <file>res/campaign/A Classic Fairytale/queen.png</file>
+        <file>res/campaign/A Classic Fairytale/enemy.png</file>
+        <file>res/campaign/A Classic Fairytale/epil.png</file>
         <file>res/bonus.png</file>
         <file>res/Hedgehog.png</file>
         <file>res/net.png</file>
--- a/QTfrontend/hwform.cpp	Wed Jun 12 19:30:44 2013 +0200
+++ b/QTfrontend/hwform.cpp	Thu Jun 13 14:44:28 2013 +0200
@@ -194,6 +194,8 @@
     //connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
 #endif
 
+    previousCampaignName = "";
+    previousTeamName = "";
     UpdateTeamsLists();
     InitCampaignPage();
     UpdateCampaignPage(0);
@@ -306,7 +308,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
@@ -1902,10 +1904,72 @@
     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 ||
+            previousTeamName.compare(tName) != 0)
+    {
+        if (previousTeamName.compare(tName) != 0 &&
+                previousTeamName.compare("") != 0)
+            index = qMin(m + 1, n);
+        previousCampaignName = campaignName;
+        previousTeamName = tName;
+        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--)
     {
+        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("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
+        ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]);
+    }
 }
 
 void HWForm::UpdateCampaignPageProgress(int index)
--- a/QTfrontend/hwform.h	Wed Jun 12 19:30:44 2013 +0200
+++ b/QTfrontend/hwform.h	Thu Jun 13 14:44:28 2013 +0200
@@ -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,9 @@
         HWNamegen * namegen;
         AmmoSchemeModel * ammoSchemeModel;
         QStack<int> PagesStack;
+        QString previousCampaignName;
+        QString previousTeamName;
+        QStringList campaignMissionDescriptions;
         QTime eggTimer;
         BGWidget * wBackground;
         QSignalMapper * pageSwitchMapper;
Binary file QTfrontend/res/campaign/A Classic Fairytale/backstab.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/dragon.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/enemy.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/epil.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/family.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/first_blood.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/journey.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/queen.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/shadow.png has changed
Binary file QTfrontend/res/campaign/A Classic Fairytale/united.png has changed
--- a/QTfrontend/ui/page/pagecampaign.cpp	Wed Jun 12 19:30:44 2013 +0200
+++ b/QTfrontend/ui/page/pagecampaign.cpp	Thu Jun 13 14:44:28 2013 +0200
@@ -19,6 +19,7 @@
 #include <QGridLayout>
 #include <QPushButton>
 #include <QComboBox>
+#include <QLabel>
 
 #include "pagecampaign.h"
 
@@ -31,18 +32,43 @@
     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;
 }
--- a/QTfrontend/ui/page/pagecampaign.h	Wed Jun 12 19:30:44 2013 +0200
+++ b/QTfrontend/ui/page/pagecampaign.h	Thu Jun 13 14:44:28 2013 +0200
@@ -28,7 +28,10 @@
     public:
         PageCampaign(QWidget* parent = 0);
 
+        QPushButton *btnPreview;
         QPushButton *BtnStartCampaign;
+        QLabel *lbldescription;
+        QLabel *lbltitle;
         QComboBox   *CBMission;
         QComboBox   *CBCampaign;
         QComboBox   *CBTeam;
--- a/cmake_modules/compilerchecks.cmake	Wed Jun 12 19:30:44 2013 +0200
+++ b/cmake_modules/compilerchecks.cmake	Thu Jun 13 14:44:28 2013 +0200
@@ -9,9 +9,11 @@
 
 #TODO: should there be two different checks for C and CXX?
 
-#stack protection, when found it needs to go in the linker flags too (-lssp is added)
+#stack protection, when found it needs to go in the linker flags too
+#it is disabled on win32 because it adds a dll and messes with linker
+#(see 822312 654424 on bugzilla.redhat.com)
 check_c_compiler_flag("-fstack-protector-all -fstack-protector" HAVE_STACKPROTECTOR)
-if(HAVE_STACKPROTECTOR)
+if(HAVE_STACKPROTECTOR AND (NOT WIN32))
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all -fstack-protector")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -fstack-protector")
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fstack-protector-all -fstack-protector")
--- a/cmake_modules/cpackvars.cmake	Wed Jun 12 19:30:44 2013 +0200
+++ b/cmake_modules/cpackvars.cmake	Thu Jun 13 14:44:28 2013 +0200
@@ -58,6 +58,7 @@
     "\\\\.db$"
     "\\\\.dof$"
     "\\\\.or$"
+    "\\\\.stackdump$"
     #archives
     "\\\\.zip$"
     "\\\\.gz$"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Locale/campaigns_en.txt	Thu Jun 13 14:44:28 2013 +0200
@@ -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."