Making the flow animation skippable.
authorMarja Hassinen <marja2@Vahvero.(none)>
Wed, 6 Jan 2010 15:04:24 +0000 (17:04 +0200)
committerMarja Hassinen <marja2@Vahvero.(none)>
Wed, 6 Jan 2010 15:04:24 +0000 (17:04 +0200)
src/game.cpp
src/game.h

index d64f3aa..8fab98d 100644 (file)
@@ -294,7 +294,7 @@ GameController::GameController(AvailablePieces* pieceUi, GameField* fieldUi,
     : pieceUi(pieceUi), fieldUi(fieldUi), 
       timeLabel(timeLabel), doneButton(doneButton),
       currentPiece(ppieces), rows(0), cols(0), timeLeft(0), levelRunning(false), neededFlow(0),
-      startRow(0), startCol(0), startDir(DirNone), flowRow(0), flowCol(0), flowDir(DirNone), flowPreplaced(0), flowScore(0)
+      startRow(0), startCol(0), startDir(DirNone), flowRow(0), flowCol(0), flowDir(DirNone), flowPreplaced(0), flowScore(0), animate(true)
 {
     connect(fieldUi, SIGNAL(cellClicked(int, int)), this, SLOT(onCellClicked(int, int)));
     connect(pieceUi, SIGNAL(invalidPieceSelected()), 
@@ -304,7 +304,7 @@ GameController::GameController(AvailablePieces* pieceUi, GameField* fieldUi,
 
     connect(this, SIGNAL(pieceUsed(const Piece*)), pieceUi, SLOT(onPieceUsed(const Piece*)));
 
-    connect(doneButton, SIGNAL(clicked()), this, SLOT(levelEnds()));
+    connect(doneButton, SIGNAL(clicked()), this, SLOT(onDoneClicked()));
 
     // Setup the timer, but don't start it yet
     timer.setInterval(1000);
@@ -404,7 +404,7 @@ void GameController::startLevel(QString fileName)
     // Clear piece selection
     onInvalidPieceSelected();
 
-    doneButton->setEnabled(true);
+    doneButton->setText("Done");
     timer.start();
     levelRunning = true;
     file.close();
@@ -438,12 +438,25 @@ void GameController::onInvalidPieceSelected()
     currentPiece = ppieces;
 }
 
+void GameController::onDoneClicked()
+{
+    // If the level was running, start flowing the liquid
+    if (levelRunning)
+        levelEnds();
+    // Else, skip the flowing animation
+    else {
+        animate = false;
+        flowTimer.setInterval(0);
+    }
+}
+
 void GameController::levelEnds()
 {
     if (!levelRunning) return;
 
-    doneButton->setEnabled(false);
+    doneButton->setText("Next");
     levelRunning = false;
+    animate = true;
     timer.stop();
 
     // Initiate computing the flow
@@ -479,7 +492,7 @@ void GameController::computeFlow()
         // some more time, so that the user sees the failure before we
         // emit levelFailed.
         flowDir = DirFailed;
-        flowTimer.setInterval(1000);
+        if (animate) flowTimer.setInterval(1000);
         return;
     }
     flowScore += 10;
@@ -493,7 +506,7 @@ void GameController::computeFlow()
         else
             flowDir = DirPassed;
 
-        flowTimer.setInterval(1000);
+        if (animate) flowTimer.setInterval(1000);
         return;
     }
 
@@ -518,7 +531,7 @@ void GameController::computeFlow()
     if (flowRow < 0 || flowCol < 0 || flowRow >= rows || flowCol >= cols) {
         // Out of bounds
         flowDir = DirFailed;
-        flowTimer.setInterval(1000);
+        if (animate) flowTimer.setInterval(1000);
         return;
     }
 
index df62499..4fa333d 100644 (file)
@@ -192,14 +192,16 @@ signals:
     void levelFailed();
 
 private slots:
+    void onDoneClicked();
     void onCellClicked(int row, int column);
     void onValidPieceSelected(const Piece* piece);
     void onInvalidPieceSelected();
     void onTimeout();
-    void levelEnds();
     void computeFlow();
 
 private:
+    void levelEnds();
+
     AvailablePieces* pieceUi; // Not owned
     GameField* fieldUi; // Not owned
     QLabel* timeLabel; // Not owned
@@ -222,6 +224,7 @@ private:
     Direction flowDir;
     int flowPreplaced;
     int flowScore;
+    bool animate;
 };
 
 class LevelSwitcher : public QObject