Merge branch 'vibrationrecovery' into harmattan
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 26 Sep 2011 20:00:23 +0000 (23:00 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 27 Sep 2011 16:08:49 +0000 (19:08 +0300)
Vibration works again (did not work before with the beta2 firmware).
This time real vibration, not just a "tak tak" sound.

Conflicts:
seascene.cpp

1  2 
seascene.cpp
seascene.h

diff --combined seascene.cpp
@@@ -35,6 -35,7 +35,7 @@@
  #include <QSettings>
  #include <QPixmap>
  
  const QString ghostImageFilename_ = ":/pix/aave.png";
  const QString rockImageFilename_ =":/pix/kari.png";
  const QString octopusImageFilename_= ":/pix/tursas.png";
@@@ -59,8 -60,6 +60,8 @@@ SeaScene::SeaScene(QObject *parent) 
  
      qsrand(QTime::currentTime().msec()+2);  //+2 to avoid setting it to 1
  
 +
 +
  //Setup the level list
  
      QList<Level> levelList;
  
      Levelset set ("Original",levelList);
      levelset_ = set;
 +    availableLevelsets_.append(set);
  
      currentLevel_ = 0;
  
      totalScore_ = 0;
  
 +   //Create another set of levels and place it in the available levelsets list
 +    levelList.clear();
 +    Level set2level1(8,15,4,50);
 +    levelList.append(set2level1);
 +    Level set2level2(8,20,4,50);
 +    levelList.append(set2level2);
 +    Level set2level3(8,20,5,100);
 +    levelList.append(set2level3);
 +    Level set2level4(8,20,6,150);
 +    levelList.append(set2level4);
 +    Level set2level5(8,25,8,200);
 +    levelList.append(set2level5);
 +
 +    Levelset set2("Difficult",levelList);
 +    availableLevelsets_.append(set2);
 +
 +
      //This ensures that nextlevel will not be called until its safe to delete the Ship object.
      //Leaving out Qt::QueuedConnection or calling nextlevel directly instead of emitting the signal will CRASH
      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)));
      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();
  
  }
  
@@@ -135,9 -132,6 +152,9 @@@ void SeaScene::setupMap(int ghosts, in
      createMenuItems();
  
      createAboutBoxItems();
 +
 +    createSelectLevelsetFromListItems();
 +
      createVictoryItems();
  
      createLevelCompletedItems();
      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()));
@@@ -477,9 -475,7 +498,9 @@@ void SeaScene::handleScreenTapped(
  
      if (items.isEmpty())
      {
 +        pSelectLevelsetFromListItem_->hide();
          pPauseAction_->setChecked(false);
 +
          return;
  
      }
          qApp->quit();
      }
  
 +    else if (pItem == pChooseLevelsetItem_)
 +    {
 +        pPausetextItem_->hide();
 +        pSelectLevelsetFromListItem_->show();
 +    }
 +
 +    else
 +    {
 +        foreach (QGraphicsItem* pLevelItem, levelsetItems_)
 +        {
 +            if (pItem == pLevelItem)
 +            {
 +                QVariant variant = pLevelItem->data(0);
 +
 +                if (variant.canConvert<Levelset>())
 +                {
 +                    levelset_ = variant.value<Levelset>();
 +                    restartGame();
 +                    pPauseAction_->setChecked(false); //unpause game
 +                }
 +            }
 +        }
 +    }
 +
  }
  
  
@@@ -609,10 -581,6 +630,10 @@@ void SeaScene::createMenuItems(
      pRestartLevelItem_->setHtml(tr("Restart <br> level").prepend(menufonthtml));
      prepareForMenu(pRestartLevelItem_);
  
 +    pChooseLevelsetItem_ = new QGraphicsTextItem;
 +    pChooseLevelsetItem_->setHtml(tr("Choose <br> levelset").prepend(menufonthtml));
 +    prepareForMenu(pChooseLevelsetItem_);
 +
      pSettingsItem_ = new QGraphicsTextItem;
      QString vibraText(tr("Turn vibration <br> effects "));
      QString statusText;
@@@ -645,20 -613,12 +666,20 @@@ void SeaScene::prepareForMenu(QGraphics
      //They are also shown and hidden with it, resulting in the menu being visble when the game is paused
      //Their coordinates are given relative to the parent.
  
 +    int itemsPerRow = 3;
  
      pItem->setParentItem(pPausetextItem_);
      pItem->setZValue(1000);
      pItem->setFlag(QGraphicsItem::ItemIsSelectable);
 -    pItem->setY(150);
 -    pItem->setX(menuItemCount_++*160-150);
 +
 +    if (menuItemCount_< itemsPerRow)
 +    {
 +        pItem->setY(120);
 +    }
 +    else pItem->setY(240);
 +
 +
 +    pItem->setX((menuItemCount_++%itemsPerRow)*180-10);
   }
  
  
@@@ -680,6 -640,7 +701,7 @@@ void SeaScene::restartLevel(
  
      vibrationActivate(pVibrateAction_->isChecked());  //Vibration effects are lost without this
     // qDebug() << pVibrateAction_->isChecked();
      autopauseTimer.start();  //reset counting towards autopause
  
  
@@@ -833,11 -794,9 +855,11 @@@ void SeaScene::setItemPointersNull(
      pAboutItem_ = NULL;
      pQuitItem_ = NULL ;
  //    pMinimizeItem_ = NULL; //Fremantle spesific
 +    pChooseLevelsetItem_ = NULL;
  
      pAboutBoxItem_ = NULL;
      pLevelCompletedItem_ = NULL;
 +    pVictoryCongratulationsItem_ = NULL;
      pVictoryScoreItem_ = NULL;
  
  }
@@@ -864,42 -823,15 +886,58 @@@ void SeaScene::createLevelCompletedItem
      pTapForNextLevelItem->setHtml("<font size=\"7\" color = darkorange>Tap to start the next level");
  }
  
 -void SeaScene::resourcesAvailable()
 +void SeaScene::createSelectLevelsetFromListItems()
  {
 -    qDebug() << "Resources available";
 -    vibrationAllowed_ = true;
 -}
 -void SeaScene::resourcesLost()
 -{
 -    qDebug() << "Resources lost";
 -    vibrationAllowed_ = false;
 -}
 +    if (availableLevelsets_.isEmpty()) //Something is badly wrong in code if this is true...
 +            return;
 +
 +
 +    pSelectLevelsetFromListItem_ = new QGraphicsTextItem;
 +    addItem(pSelectLevelsetFromListItem_);
 +    pSelectLevelsetFromListItem_->setPos(295,60);
 +    pSelectLevelsetFromListItem_->setZValue(1000);
 +    pSelectLevelsetFromListItem_->hide();
 +
++
 +    QString fontstring ("<font color = darkorange size = \"7\">");
 +
 +    pSelectLevelsetFromListItem_->setHtml(tr("Choose a levelset").prepend(fontstring));
 +
 +    int yPos = 100;
 +
 +    levelsetItems_.clear();
 +
  
 +    foreach (Levelset set, availableLevelsets_)
 +    {
 +        QGraphicsTextItem * pItem = new QGraphicsTextItem(pSelectLevelsetFromListItem_);
 +        QString text (fontstring);
 +        if (levelset_.getName() == set.getName())
 +            text.append("<b>");
 +        text.append(set.getName());
 +        pItem->setHtml(text);
 +        pItem->setPos(65,yPos);
 +        yPos+=80;
 +        pItem->setZValue(1000);
 +        pItem->setFlag(QGraphicsItem::ItemIsSelectable);
 +        pItem->setData(0,QVariant::fromValue(set));
 +        levelsetItems_.append(pItem);
 +
 +    }
 +
 +  }
++
++
++    void SeaScene::resourcesAvailable()
++    {
++        qDebug() << "Resources available";
++        vibrationAllowed_ = true;
++    }
++
++
++    void SeaScene::resourcesLost()
++    {
++        qDebug() << "Resources lost";
++        vibrationAllowed_ = false;
++    }
diff --combined seascene.h
@@@ -32,6 -32,7 +32,7 @@@
  #include <QAction>
  #include <QTimer>
  #include <QTime>
+ #include <policy/resource-set.h>
  
  class SeaScene : public QGraphicsScene
  {
@@@ -46,6 -47,7 +47,7 @@@ signals
      void pauseOff();
      void vibrationActivated(bool on);
  
  public slots:
  
      /*! Places all needed items for a level to (re)start.
  
      void turnPauseOn();
  
+     void resourcesAvailable();
+     void resourcesLost();
  
  
 +
 +
  protected:
  
      /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
      void createAboutBoxItems();
      void createVictoryItems();
      void createLevelCompletedItems();
 +    void createSelectLevelsetFromListItems();
  
      const QString ghostImageFilename_;
      const QString rockImageFilename_;
      QGraphicsTextItem * pSettingsItem_;
      QGraphicsTextItem * pAboutItem_;
      QGraphicsTextItem * pQuitItem_;
 +    QGraphicsTextItem * pChooseLevelsetItem_;
  
      QGraphicsTextItem * pVictoryScoreItem_;
      QGraphicsTextItem * pAboutBoxItem_;
  
      QGraphicsTextItem * pLevelCompletedItem_;
  
 +    QGraphicsTextItem * pSelectLevelsetFromListItem_;
 +
 +    QList<QGraphicsItem *>  levelsetItems_;
 +
 +    QList<Levelset> availableLevelsets_;
  
      Levelset levelset_;
  
      QTime scoreCounter_;
      int totalScore_;
      int levelScore_;
+     ResourcePolicy::ResourceSet * pResourceSet_;
+     bool vibrationAllowed_;
  };
  
  #endif // SEASCENE_H