Merge branch 'vibrationrecovery' into harmattan
[ghostsoverboard] / seascene.cpp
index c957570..de57ba4 100644 (file)
@@ -35,6 +35,7 @@
 #include <QSettings>
 #include <QPixmap>
 
+
 const QString ghostImageFilename_ = ":/pix/aave.png";
 const QString rockImageFilename_ =":/pix/kari.png";
 const QString octopusImageFilename_= ":/pix/tursas.png";
@@ -105,6 +106,8 @@ SeaScene::SeaScene(QObject *parent) :
     connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()),Qt::QueuedConnection);
 
 
+
+
     pVibrateAction_ = new QAction(tr("Vibration effects"),this);
     pVibrateAction_->setCheckable(true);
     connect(pVibrateAction_,SIGNAL(toggled(bool)),this,SLOT(vibrationActivate(bool)));
@@ -121,6 +124,20 @@ SeaScene::SeaScene(QObject *parent) :
     autopauseTimer.setInterval(15*60*1000);
     connect(&autopauseTimer,SIGNAL(timeout()),this,SLOT(turnPauseOn()));
 
+    vibrationAllowed_ = false;
+    pResourceSet_ = new ResourcePolicy::ResourceSet("game",this);
+    ResourcePolicy::VibraResource * pVibraResource = new ResourcePolicy::VibraResource();
+    pVibraResource->setOptional(false); //The only resource of the set, so no sense for it to be optional
+    pResourceSet_->addResourceObject(pVibraResource);
+
+    connect(pResourceSet_,SIGNAL(resourcesGranted(const QList< ResourcePolicy::ResourceType >)),this,SLOT(resourcesAvailable()));
+    connect(pResourceSet_,SIGNAL(lostResources()),this,SLOT(resourcesLost()));
+
+    //To test whether resources were succesfully asked but not given
+    connect(pResourceSet_,SIGNAL(resourcesDenied()),this,SLOT(resourcesLost()));
+    pResourceSet_->setAlwaysReply();
+
+    pResourceSet_->acquire();
 
 }
 
@@ -250,6 +267,10 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
     connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) );
     connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
     connect(this,SIGNAL(vibrationActivated(bool)),pShip,SLOT(setVibrationActivate(bool)));
+    if (vibrationAllowed_)
+        pShip->allowVibration(); //Vibration is disallowed by default so only allowing needs to be done explicitly
+    connect(pResourceSet_,SIGNAL(resourcesGranted(const QList< ResourcePolicy::ResourceType >)),pShip,SLOT(allowVibration()));
+    connect(pResourceSet_,SIGNAL(lostResources()),pShip,SLOT(disallowVibration()));
     pShip->startMoving();
     movingItems_.append(pShip);
     connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving()));
@@ -680,6 +701,7 @@ void SeaScene::restartLevel()
 
     vibrationActivate(pVibrateAction_->isChecked());  //Vibration effects are lost without this
    // qDebug() << pVibrateAction_->isChecked();
+
     autopauseTimer.start();  //reset counting towards autopause
 
 
@@ -866,6 +888,7 @@ void SeaScene::createLevelCompletedItems()
 
 void SeaScene::createSelectLevelsetFromListItems()
 {
+
     if (availableLevelsets_.isEmpty()) //Something is badly wrong in code if this is true...
             return;
 
@@ -876,6 +899,7 @@ void SeaScene::createSelectLevelsetFromListItems()
     pSelectLevelsetFromListItem_->setZValue(1000);
     pSelectLevelsetFromListItem_->hide();
 
+
     QString fontstring ("<font color = darkorange size = \"7\">");
 
     pSelectLevelsetFromListItem_->setHtml(tr("Choose a levelset").prepend(fontstring));
@@ -903,3 +927,17 @@ void SeaScene::createSelectLevelsetFromListItems()
     }
 
   }
+
+
+    void SeaScene::resourcesAvailable()
+    {
+        qDebug() << "Resources available";
+        vibrationAllowed_ = true;
+    }
+
+
+    void SeaScene::resourcesLost()
+    {
+        qDebug() << "Resources lost";
+        vibrationAllowed_ = false;
+    }