Menu items can be selected
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Sat, 16 Jul 2011 20:32:30 +0000 (23:32 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Sat, 16 Jul 2011 20:35:17 +0000 (23:35 +0300)
Do nothing but give a debug message, though. Also, the game is unpaused
when selecting a menu item.

seascene.cpp
seascene.h
seaview.cpp
seaview.h

index 866fae1..81e4ace 100644 (file)
@@ -55,6 +55,12 @@ SeaScene::SeaScene(QObject *parent) :
 
 
 
+
+
+
+
+
+
 }
 
 void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
@@ -63,6 +69,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
 
     clear();
 
+    createMenuItems();
+
     //empty the list of moving items
 
     movingItems_.clear();
@@ -308,13 +316,22 @@ void SeaScene::pause(bool paused)
      //       qDebug() << "starting to move again";
             emit pauseOff();
             screenLitKeeper_.keepScreenLit(true);
+            if (pPausetextItem_)
+                pPausetextItem_->hide();
         }
 
         else
         {
-     //       qDebug("about to stop movement");
+         qDebug("about to stop movement");
             emit pauseOn();
             screenLitKeeper_.keepScreenLit(false);
+            if (pPausetextItem_ != NULL)
+            {
+                qDebug() << "about to show the pause text";
+                pPausetextItem_->show();
+                qDebug() << "showing pause text";
+            }
+                else qDebug() << "No pause text available";
         }
 }
 
@@ -332,26 +349,32 @@ void SeaScene::menuClicked()
     if (items.isEmpty())
         return;
 
+    //Tapping the screen unpaused the game, pause it again!
+
+
+
     //Menu functions
 
-    QString menuitem = items.at(0)->data(0).toString();
+    QGraphicsItem* pItem = items.at(0);
 
-    if (menuitem == "restart game")
-    {
 
+    if (pItem == pRestartGameItem_)
+    {
+        qDebug() << "game restart requested";
     }
 
-    else if (menuitem == "restart level")
+    else if (pItem == pRestartLevelItem_)
     {
+        qDebug() << "Level restart requested";
 
     }
 
-    else if (menuitem == "vibration effects")
+    else if (pItem == pVibrateItem_)
     {
 
     }
 
-    else if (menuitem == "about")
+    else if (pItem == pAboutItem_)
     {
 
     }
@@ -372,3 +395,35 @@ void::SeaScene::hideMenu()
 {
     menuItems_.hide();
 }
+
+void SeaScene::createMenuItems()
+{
+
+    pPausetextItem_ =  addSimpleText("Game paused. Tap to continue.");
+    pPausetextItem_->setZValue(1000);
+
+    //Menu items have pause text item as their parent and are thus added to scene automatically
+    //They are also shown and hidden with it, resulting in the menu being visble when the game is paused
+
+    pRestartGameItem_ = new QGraphicsSimpleTextItem("Restart game",pPausetextItem_);
+    pRestartGameItem_->setPos(0,200);
+    pRestartGameItem_->setZValue(1000);
+    pRestartGameItem_->setFlag(QGraphicsItem::ItemIsSelectable);
+
+    pRestartLevelItem_ = new QGraphicsSimpleTextItem("Restart level",pPausetextItem_);
+    pRestartLevelItem_->setPos(150,200);
+    pRestartLevelItem_->setZValue(1000);
+    pRestartLevelItem_->setFlag(QGraphicsItem::ItemIsSelectable);
+
+    QGraphicsRectItem * item = new QGraphicsRectItem(100,100,50,50,pPausetextItem_);
+    item->setFlag(QGraphicsItem::ItemIsSelectable);
+    QBrush brush;
+    brush.setStyle(Qt::SolidPattern);
+    item->setBrush(brush);
+
+
+
+
+
+
+}
index 69eeb6d..c9d9a54 100644 (file)
@@ -78,6 +78,8 @@ protected:
 
     QPointF* findRandomFreeSlot();
 
+    void createMenuItems();
+
     const QString ghostImageFilename_;
     const QString rockImageFilename_;
     const QString octopusImageFilename_;
@@ -93,10 +95,16 @@ protected:
 
     ScreenLitKeeper screenLitKeeper_;
 
-private:
 
     QGraphicsItemGroup menuItems_;
 
+    QGraphicsSimpleTextItem * pPausetextItem_;
+
+    QGraphicsSimpleTextItem * pRestartLevelItem_;
+    QGraphicsSimpleTextItem * pRestartGameItem_;
+    QGraphicsSimpleTextItem * pVibrateItem_;
+    QGraphicsSimpleTextItem * pAboutItem_;
+
 
 };
 
index f03d14e..8d6564e 100644 (file)
@@ -29,5 +29,9 @@ SeaView::SeaView(QWidget *parent) :
 
 void  SeaView::mousePressEvent(QMouseEvent *event)
 {
+
+    QGraphicsView::mousePressEvent(event);
     emit pauseChanged();
+
+
 }
index e6e20ed..dcbd566 100644 (file)
--- a/seaview.h
+++ b/seaview.h
@@ -31,7 +31,7 @@ class SeaView : public QGraphicsView
 public:
     explicit SeaView(QWidget *parent = 0);
 
-    virtual void mousePressEvent(QMouseEvent *event);
+   virtual void mousePressEvent(QMouseEvent *event);
 
 signals: