Level collection selection cont. & styling.
[evilplumber] / src / game.cpp
index 0aad055..fddf831 100644 (file)
@@ -468,6 +468,11 @@ void GameController::computeFlow()
         return;
     }
 
+    if (flowDir == DirPassed) {
+        flowTimer.stop();
+        emit levelPassed(flowScore);
+    }
+
     if (flowDir == DirNone) {
         // This square contained no pipe or an incompatible pipe. Get
         // some more time, so that the user sees the failure before we
@@ -479,15 +484,15 @@ void GameController::computeFlow()
     flowScore += 10;
 
     if (flowDir == DirDone) {
+        // Again, give the user some time...
         if (flowPreplaced < neededFlow) {
             flowDir = DirFailed;
             // TODO: indicate which pipes were missing
-            flowTimer.setInterval(1000);
-        }
-        else {
-            flowTimer.stop();
-            emit levelPassed(flowScore);
         }
+        else
+            flowDir = DirPassed;
+
+        flowTimer.setInterval(1000);
         return;
     }
 
@@ -555,10 +560,15 @@ LevelSwitcher::LevelSwitcher(GameController* gameController,
 void LevelSwitcher::chooseLevelCollection()
 {
     levelList->clear();
+    bool first = true;
     foreach (const QString& collection, levelCollections) {
         QListWidgetItem *newItem = new QListWidgetItem();
         newItem->setText(collection);
         levelList->addItem(newItem); // transfers ownership
+        if (first) {
+            levelList->setCurrentItem(newItem);
+            first = false;
+        }
     }
     levelWidget->show();
 }
@@ -604,6 +614,10 @@ void LevelSwitcher::initiateLevel()
 
     QString introText = gameData.readLine();
     introText.replace("IMGDIR", IMGDIR);
+
+    // The start button might be connected to "chooseLevelCollection"
+    startButton->disconnect();
+    connect(startButton, SIGNAL(clicked()), this, SLOT(onStartClicked()));
     startLabel->setText(introText);
     startWidget->show();
 }
@@ -621,7 +635,8 @@ void LevelSwitcher::onLevelPassed(int score)
     else {
         startTitle->setText(QString("All levels passed. Score: ") + QString::number(score));
         startLabel->setText("Start a new game?");
-        // TODO: go to the level set selection screen
+        startButton->disconnect();
+        connect(startButton, SIGNAL(clicked()), this, SLOT(chooseLevelCollection()));
         level = 0;
         startWidget->show();
     }