From 2954b395f3e06984ba87db37240498e09796827d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Sun, 17 Jul 2011 00:00:02 +0300 Subject: [PATCH] All menu items in place. Still do nothing. Substituted vibrate with settings, as togglable hard to implement and other settings will come later. Must make it to open a dialog where vibrate can be changed and the settings are saved. --- seascene.cpp | 49 ++++++++++++++++++++++++------------------------- seascene.h | 8 +++----- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/seascene.cpp b/seascene.cpp index 81e4ace..28ad362 100644 --- a/seascene.cpp +++ b/seascene.cpp @@ -369,7 +369,7 @@ void SeaScene::menuClicked() } - else if (pItem == pVibrateItem_) + else if (pItem == pSettingsItem_) { } @@ -386,44 +386,43 @@ void SeaScene::menuClicked() } -void SeaScene::showMenu() -{ - menuItems_.show(); -} -void::SeaScene::hideMenu() -{ - menuItems_.hide(); -} void SeaScene::createMenuItems() { pPausetextItem_ = addSimpleText("Game paused. Tap to continue."); pPausetextItem_->setZValue(1000); + pPausetextItem_->setPos(250,50); + pPausetextItem_->hide(); - //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 + menuItemCount_ = 0; - pRestartGameItem_ = new QGraphicsSimpleTextItem("Restart game",pPausetextItem_); - pRestartGameItem_->setPos(0,200); - pRestartGameItem_->setZValue(1000); - pRestartGameItem_->setFlag(QGraphicsItem::ItemIsSelectable); + pRestartGameItem_ = new QGraphicsSimpleTextItem("Restart game"); + prepareForMenu(pRestartGameItem_); - pRestartLevelItem_ = new QGraphicsSimpleTextItem("Restart level",pPausetextItem_); - pRestartLevelItem_->setPos(150,200); - pRestartLevelItem_->setZValue(1000); - pRestartLevelItem_->setFlag(QGraphicsItem::ItemIsSelectable); + pRestartLevelItem_ = new QGraphicsSimpleTextItem("Restart level"); + prepareForMenu(pRestartLevelItem_); - QGraphicsRectItem * item = new QGraphicsRectItem(100,100,50,50,pPausetextItem_); - item->setFlag(QGraphicsItem::ItemIsSelectable); - QBrush brush; - brush.setStyle(Qt::SolidPattern); - item->setBrush(brush); + pSettingsItem_ = new QGraphicsSimpleTextItem("Settings"); + prepareForMenu(pSettingsItem_); + pAboutItem_ = new QGraphicsSimpleTextItem("About"); + prepareForMenu(pAboutItem_); +} +void SeaScene::prepareForMenu(QGraphicsItem * pItem) +{ + //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 + //Their coordinates are given relative to the parent. + pItem->setParentItem(pPausetextItem_); + pItem->setZValue(1000); + pItem->setFlag(QGraphicsItem::ItemIsSelectable); + pItem->setY(150); + pItem->setX(menuItemCount_++*150-250); + } -} diff --git a/seascene.h b/seascene.h index c9d9a54..7690d57 100644 --- a/seascene.h +++ b/seascene.h @@ -66,9 +66,6 @@ public slots: void menuClicked(); - void showMenu(); - - void hideMenu(); protected: @@ -79,6 +76,7 @@ protected: QPointF* findRandomFreeSlot(); void createMenuItems(); + void prepareForMenu(QGraphicsItem * pItem); const QString ghostImageFilename_; const QString rockImageFilename_; @@ -96,13 +94,13 @@ protected: ScreenLitKeeper screenLitKeeper_; - QGraphicsItemGroup menuItems_; + int menuItemCount_; QGraphicsSimpleTextItem * pPausetextItem_; QGraphicsSimpleTextItem * pRestartLevelItem_; QGraphicsSimpleTextItem * pRestartGameItem_; - QGraphicsSimpleTextItem * pVibrateItem_; + QGraphicsSimpleTextItem * pSettingsItem_; QGraphicsSimpleTextItem * pAboutItem_; -- 1.7.9.5