Campaign: Select next unfinished mission after completing one
authorWuzzy <Wuzzy2@mail.ru>
Wed, 16 Jan 2019 03:40:05 +0100
changeset 14606 1d3f8cf48831
parent 14605 13b22e2f2010
child 14607 14b295892fb7
Campaign: Select next unfinished mission after completing one
ChangeLog.txt
QTfrontend/game.cpp
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/ui/page/pagecampaign.h
--- a/ChangeLog.txt	Wed Jan 16 01:39:58 2019 +0100
+++ b/ChangeLog.txt	Wed Jan 16 03:40:05 2019 +0100
@@ -63,6 +63,7 @@
 Frontend:
  + Restructure credits
  + Credits screen in main menu is now translatable
+ + More intelligent automatic mission selection in campaign screen
  * Fix force-locked schemes getting unlocked when changing map types
 
 Lua API:
--- a/QTfrontend/game.cpp	Wed Jan 16 01:39:58 2019 +0100
+++ b/QTfrontend/game.cpp	Wed Jan 16 03:40:05 2019 +0100
@@ -565,7 +565,7 @@
     emit GameStateChanged(state);
     if (gameType == gtCampaign)
     {
-        emit CampStateChanged(1);
+        emit CampStateChanged(state);
     }
     else if (gameType == gtTraining)
     {
--- a/QTfrontend/hwform.cpp	Wed Jan 16 01:39:58 2019 +0100
+++ b/QTfrontend/hwform.cpp	Wed Jan 16 03:40:05 2019 +0100
@@ -2143,26 +2143,74 @@
 
 void HWForm::UpdateCampaignPageProgress(int index)
 {
-    Q_UNUSED(index);
-
     QString missionTitle = ui.pageCampaign->CBMission->currentData().toString();
     UpdateCampaignPage(0);
+    int missionIndex = 0;
+    // Restore selected mission (because UpdateCampaignPage repopulated the list)
     for(int i=0;i<ui.pageCampaign->CBMission->count();i++)
     {
         if (ui.pageCampaign->CBMission->itemData(i).toString() == missionTitle)
         {
-            ui.pageCampaign->CBMission->setCurrentIndex(i);
+            missionIndex = i;
             break;
         }
     }
-    int i = ui.pageCampaign->CBCampaign->currentIndex();
-    QString campaignName = ui.pageCampaign->CBCampaign->itemData(i).toString();
+
+    // Get metadata
+    int c = ui.pageCampaign->CBCampaign->currentIndex();
+    QString campaignName = ui.pageCampaign->CBCampaign->itemData(c).toString();
     HWTeam team(ui.pageCampaign->CBTeam->currentText());
     QString tName = team.name();
+
+    if(index == gsFinished)
+    {
+        // Select new mission when current mission went from
+        // unfinished to finished.
+        if(ui.pageCampaign->currentMissionWon == false &&
+           isCampMissionWon(campaignName, missionIndex, tName))
+        {
+            // Traverse all missions and pick first mission that
+            // has not been won.
+            bool selected = false;
+            // start from mission that comes after the selected one
+            for(int m = missionIndex-1; m >= 0;m--)
+            {
+                if(!isCampMissionWon(campaignName, m, tName))
+                {
+                    missionIndex = m;
+                    selected = true;
+                    break;
+                }
+            }
+            // No mission selected? Let's try again from the end of the list
+            if(!selected)
+            {
+                for(int m = ui.pageCampaign->CBMission->count()-1; m > missionIndex-1; m--)
+                {
+                    if(!isCampMissionWon(campaignName, m, tName))
+                    {
+                        missionIndex = m;
+                        break;
+                    }
+                }
+            }
+            // If no mission was selected, the old selection remains unchanged.
+        }
+    }
+    else if(index == gsStarted)
+    {
+        // Remember the "won" state of current mission before we start it.
+        // We'll need it when the game has finished.
+        ui.pageCampaign->currentMissionWon = isCampMissionWon(campaignName, missionIndex, tName);
+    }
+
+    ui.pageCampaign->CBMission->setCurrentIndex(missionIndex);
+
+    // Update campaign victory status
     if(isCampWon(campaignName, tName))
-        ui.pageCampaign->CBCampaign->setItemIcon(i, finishedIcon);
+        ui.pageCampaign->CBCampaign->setItemIcon(c, finishedIcon);
     else
-        ui.pageCampaign->CBCampaign->setItemIcon(i, notFinishedIcon);
+        ui.pageCampaign->CBCampaign->setItemIcon(c, notFinishedIcon);
 }
 
 // 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]
--- a/QTfrontend/hwform.h	Wed Jan 16 01:39:58 2019 +0100
+++ b/QTfrontend/hwform.h	Wed Jan 16 03:40:05 2019 +0100
@@ -215,6 +215,8 @@
         QPropertyAnimation *animationNewOpacity;
         QPropertyAnimation *animationOldOpacity;
 
+        bool campaignMissionWon = false;
+
 #ifdef __APPLE__
         InstallController * panel;
 #endif
--- a/QTfrontend/ui/page/pagecampaign.h	Wed Jan 16 01:39:58 2019 +0100
+++ b/QTfrontend/ui/page/pagecampaign.h	Wed Jan 16 03:40:05 2019 +0100
@@ -35,6 +35,7 @@
         QComboBox   *CBMission;
         QComboBox   *CBCampaign;
         QComboBox   *CBTeam;
+        bool currentMissionWon = false;
 
     protected:
         QLayout * bodyLayoutDefinition();