Added "Choose levelset" to menu. Does not work yet.
[ghostsoverboard] / seascene.cpp
1 /**************************************************************************
2         Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
3
4         Copyright (C) 2011  Heli Hyvättinen
5
6         This file is part of Ghosts Overboard
7
8         Ghosts Overboard is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 2 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 **************************************************************************/
22
23 #include "seascene.h"
24 #include "octopus.h"
25 #include "ship.h"
26 #include <QGraphicsPixmapItem>
27 #include <QDebug>
28 #include <QMessageBox>
29 #include <QTime>
30 #include <QApplication>
31 #include <QAction>
32 #include <QPushButton>
33 #include <QLabel>
34 #include <QVBoxLayout>
35 #include <QSettings>
36 #include <QPixmap>
37
38 const QString ghostImageFilename_ = ":/pix/aave.png";
39 const QString rockImageFilename_ =":/pix/kari.png";
40 const QString octopusImageFilename_= ":/pix/tursas.png";
41
42
43 SeaScene::SeaScene(QObject *parent) :
44     QGraphicsScene(parent)
45 {
46
47     setItemPointersNull();
48
49     paused_ = false;
50     screenLitKeeper_.keepScreenLit(true);
51
52     //set background
53
54     QPixmap waves (":/pix/meri.png");
55     waves.scaled(20,20);
56     setBackgroundBrush(QBrush(waves));
57
58     //set random seed
59
60     qsrand(QTime::currentTime().msec()+2);  //+2 to avoid setting it to 1
61
62
63
64 //Setup the level list
65
66     QList<Level> levelList;
67     Level level1(5,10);
68     levelList.append(level1);
69     Level level2(5,10,2,50);
70     levelList.append(level2);
71     Level level3(5,15,2,50);
72     levelList.append(level3);
73     Level level4(5,15,4,50);
74     levelList.append(level4);
75     Level level5(5,15,5,100);
76     levelList.append(level5);
77
78     Levelset set ("Original",levelList);
79     levelset_ = set;
80     availableLevelsets_.append(set);
81
82     currentLevel_ = 0;
83
84     totalScore_ = 0;
85
86    //Create another set of levels and place it in the available levelsets list
87     levelList.clear();
88     Level set2level1(8,15,4,50);
89     levelList.append(set2level1);
90     Level set2level2(8,20,4,50);
91     levelList.append(set2level2);
92     Level set2level3(8,15,5,100);
93     levelList.append(set2level3);
94     Level set2level4(8,20,6,100);
95     levelList.append(set2level4);
96     Level set2level5(8,20,6,150);
97     levelList.append(set2level5);
98
99     Levelset set2("Difficult",levelList);
100     availableLevelsets_.append(set2);
101
102
103     //This ensures that nextlevel will not be called until its safe to delete the Ship object.
104     //Leaving out Qt::QueuedConnection or calling nextlevel directly instead of emitting the signal will CRASH
105     connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()),Qt::QueuedConnection);
106
107
108     pVibrateAction_ = new QAction(tr("Vibration effects"),this);
109     pVibrateAction_->setCheckable(true);
110     connect(pVibrateAction_,SIGNAL(toggled(bool)),this,SLOT(vibrationActivate(bool)));
111     QSettings settings;
112     pVibrateAction_->setChecked(settings.value("vibration",false).toBool());
113
114
115     pPauseAction_ = new QAction(tr("Pause"),this);
116     pPauseAction_->setCheckable(true);
117     connect(pPauseAction_,SIGNAL(toggled(bool)),this,SLOT(pause(bool)));
118
119
120     autopauseTimer.setSingleShot(true);
121     autopauseTimer.setInterval(15*60*1000);
122     connect(&autopauseTimer,SIGNAL(timeout()),this,SLOT(turnPauseOn()));
123
124
125 }
126
127 void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
128 {
129     //empty the map
130
131     clear();
132
133     setItemPointersNull();
134
135     createMenuItems();
136
137     createAboutBoxItems();
138
139     createSelectLevelsetFromListItems();
140
141     createVictoryItems();
142
143     createLevelCompletedItems();
144
145
146     //empty the list of moving items
147
148     movingItems_.clear();
149
150     //empty the list of free slots
151     freeTiles_.clear();
152
153     //fill the list of free slots
154
155     int numberOfXTiles  = width() / 40;
156     int numberOfYTiles = height() /40;
157
158 //    qDebug() << numberOfXTiles << " slots in x direction";
159 //    qDebug() << numberOfYTiles << " slots in y rirection";
160
161     for (int i = 0; i < numberOfXTiles; i++ )
162     {
163         for (int j = 0; j < numberOfYTiles; j++)
164         {
165             freeTiles_.append(QPointF(i*40,j*40));
166         }
167     }
168
169
170     //spread the rocks
171
172     for (int i = 0; i < rocks; i++)
173     {
174         QPointF * pPosition = findRandomFreeSlot();
175
176         //If there was no room no point to continue
177         if (pPosition == NULL)
178             break;
179
180         QPixmap rockPixmap (":/pix/kari.png");
181         QGraphicsPixmapItem * pRock = addPixmap(rockPixmap);
182         pRock->setData(0,"rock");
183         pRock->setPos(*pPosition);
184         delete pPosition;
185
186     }
187
188     //spread the ghosts
189
190     ghostsLeft_ = ghosts;
191     spreadGhosts(ghosts);
192
193
194
195     //spread the octopuses
196
197     QList <Octopus*> octopusList;
198
199     for (int i=0; i < octopuses; i++)
200     {
201         QPointF * pPosition = findRandomFreeSlot();
202
203         //If there was no room no point to continue
204         if (pPosition == NULL)
205             break;
206
207     QPixmap octopusPixmap (":/pix/tursas.png");
208     Octopus * pOctopus = new Octopus(octopusPixmap,octopusSpeed);
209     pOctopus->setData(0,"octopus");
210     pOctopus->setPos(*pPosition);
211     addItem(pOctopus);
212     pOctopus->startMoving();
213     movingItems_.append(pOctopus);
214     connect(this,SIGNAL(pauseOn()),pOctopus,SLOT(stopMoving()));
215     connect(this,SIGNAL(pauseOff()),pOctopus,SLOT(startMoving()));
216     octopusList.append(pOctopus);
217     delete pPosition;
218
219     }
220
221
222     //place the ship
223
224     QPointF * pPosition = findRandomFreeSlot();
225     if (pPosition == NULL)
226     {
227         // Game cannot begin without a free position for ship, so give an error message and return
228
229         QMessageBox::critical(NULL,"Error! Too many objects on screen","No free space to place the ship. The game cannot start. Please choose another level.");
230         return;
231     }
232
233     QList<QPixmap> shipImages;
234     shipImages.append(QPixmap(":/pix/laiva.png"));
235     shipImages.append(QPixmap(":/pix/laiva_1aave.png"));
236     shipImages.append(QPixmap(":/pix/laiva_2aave.png"));
237     shipImages.append(QPixmap(":/pix/laiva_3aave.png"));
238     shipImages.append(QPixmap(":/pix/laiva_4aave.png"));
239     shipImages.append(QPixmap(":/pix/laiva_5aave.png"));
240     shipImages.append(QPixmap(":/pix/laiva_6aave.png"));
241     shipImages.append(QPixmap(":/pix/laiva_7aave.png"));
242     shipImages.append(QPixmap(":/pix/laiva_8aave.png"));
243     shipImages.append(QPixmap(":/pix/laiva_9aave.png"));
244     shipImages.append(QPixmap(":/pix/laiva_10aave.png"));
245
246     Ship * pShip = new Ship (shipImages);
247     pShip->setData(0,"ship");
248     pShip->setPos(*pPosition);
249     addItem(pShip);
250     connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) );
251     connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
252     connect(this,SIGNAL(vibrationActivated(bool)),pShip,SLOT(setVibrationActivate(bool)));
253     pShip->startMoving();
254     movingItems_.append(pShip);
255     connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving()));
256     connect(this,SIGNAL(pauseOff()),pShip,SLOT(startMoving()));
257     foreach (Octopus* pOctopus, octopusList)
258     {
259         connect(pOctopus,SIGNAL(droppingGhosts()),pShip,SLOT(dropAllGhosts()));
260     }
261     delete pPosition;
262 }
263
264 void SeaScene::setupMap(Level level)
265 {
266     setupMap(level.getNumberOfGhosts(),level.getNumberOfRocks(),level.getNumberOfOctopuses(),level.getOctopusSpeed());
267 }
268
269 void SeaScene::spreadGhosts(int ghosts)
270 {
271
272
273     //the octopuses and the ship may have moved from their original positions,
274     //so the list of free slots must be adjusted to exclude their current positions
275
276     QList<QPointF> temporarilyReservedSlots;
277
278     foreach (QGraphicsItem* pItem, movingItems_)
279     {
280         if (pItem == NULL)
281         {
282  //           qDebug() << "NULL item in movingItems_";
283             continue;
284         }
285
286         //round x and y down to fit the slot size
287         int x = pItem->x();
288         x = x/40;
289         x = x*40;
290
291         int y = pItem->y();
292         y = y/40;
293         y=y*40;
294
295
296         QPointF position (x,y);
297
298         //remove the tiles (potentially) occupied by the item from free slots and place in temp list if was in the list before
299
300         if (freeTiles_.removeOne(position))
301             temporarilyReservedSlots.append(position);
302
303
304         position.setX(x+40);
305
306         if (freeTiles_.removeOne(position))
307             temporarilyReservedSlots.append(position);
308
309         position.setY(y+40);
310
311         if (freeTiles_.removeOne(position))
312             temporarilyReservedSlots.append(position);
313
314         position.setX(x);
315
316         if (freeTiles_.removeOne(position))
317             temporarilyReservedSlots.append(position);
318
319     }
320
321
322     //spread ghosts in random free slots
323
324     for (int i=0; i < ghosts; i++)
325     {
326         QPointF * pPosition = findRandomFreeSlot();
327
328         //If there was no room no point to continue
329         if (pPosition == NULL)
330             return;
331
332         QPixmap ghostPixmap(":/pix/aave.png");
333         QGraphicsPixmapItem * pGhost = addPixmap(ghostPixmap);
334         pGhost->setData(0,"ghost");
335         pGhost->setPos(*pPosition);
336         delete pPosition;
337     }
338
339     //return the slots occupied by moving items to free slots
340     freeTiles_.append(temporarilyReservedSlots);
341
342     //clear temp for the next round
343     temporarilyReservedSlots.clear();
344 }
345
346 QPointF* SeaScene::findRandomFreeSlot()
347 {
348     if (freeTiles_.isEmpty())
349         return NULL;
350
351     int index = qrand()%freeTiles_.size();
352
353 //    qDebug()  << index << " index";
354     return new QPointF (freeTiles_.takeAt(index));
355
356 }
357
358 void SeaScene::removeGhost(QGraphicsItem *pGhost)
359 {
360     removeItem(pGhost);  //remove the item from scene
361     freeTiles_.append(pGhost->scenePos()); //add the item's position to free slots
362     delete pGhost;
363     ghostsLeft_--;
364     if (ghostsLeft_ == 0)
365     {
366         emit allGhostsPicked();
367  //       qDebug() << "All ghosts picked!";
368     }
369 }
370
371 void SeaScene::ghostsDropped(int ghosts)
372 {
373     ghostsLeft_ += ghosts;
374
375     spreadGhosts(ghosts);
376 }
377
378 void SeaScene::pause(bool paused)
379 {
380     //    qDebug() << "pause pressed " << paused;
381         if (paused_ == paused)
382                 return;
383
384         paused_ = paused;
385
386         if (paused == false)
387         {
388      //       qDebug() << "starting to move again";
389 //            emit fullscreenRequested();   fremantle specific (since no "show statusbar" action in harmattan version)
390             emit pauseOff();
391             screenLitKeeper_.keepScreenLit(true);
392             if (pPausetextItem_)
393                 pPausetextItem_->hide();
394
395             scoreCounter_.start();
396
397             autopauseTimer.start(); //Start counting towards autopause
398         }
399
400         else
401         {
402 //         qDebug("about to stop movement");
403             emit pauseOn();
404             screenLitKeeper_.keepScreenLit(false);
405             if (pPausetextItem_ != NULL)
406             {
407 //                qDebug() << "about to show the pause text";
408                 pPausetextItem_->show();
409 //                qDebug() << "showing pause text";
410             }
411 //                else qDebug() << "No pause text available";
412
413             levelScore_ += scoreCounter_.elapsed();
414
415             autopauseTimer.stop(); //No need to count toward autopause when already paused
416         }
417 }
418
419 void SeaScene::vibrationActivate(bool on)
420 {
421     emit vibrationActivated(on);
422 }
423
424 void SeaScene::handleScreenTapped()
425 {
426
427     //If the game is going just pause it
428     if (!paused_)
429     {
430         pPauseAction_->setChecked(true);
431         return;
432     }
433
434     //If the game is paused and about box is shown, close it and show the pause text and menu again
435
436     if(pAboutBoxItem_)
437     {
438         if(pAboutBoxItem_->isVisible())
439         {
440             pAboutBoxItem_->hide();
441             pPausetextItem_->show();
442             return;
443         }
444     }
445
446     //If the game is paused, check if the level completed item is shown
447
448     if (pLevelCompletedItem_)
449     {
450         if (pLevelCompletedItem_->isVisible())
451         {
452             pLevelCompletedItem_->hide();
453             restartLevel(); //Current level has already been set to the next one before showing the level completed item
454             pPauseAction_->setChecked(false); //unpause
455             return;
456         }
457     }
458    
459     //If the game is paused, check if the victory item is being shown
460     if(pVictoryCongratulationsItem_)
461     {
462         if (pVictoryCongratulationsItem_->isVisibleTo(NULL)) //returns visibility to scene
463         {
464             pVictoryCongratulationsItem_->hide();
465             restartGame();
466             pPauseAction_->setChecked(false); // unpause
467             return;
468         }
469     }
470
471
472     //If the game is paused and no victory or about box, check if menu item was selected
473
474     QList<QGraphicsItem *> items = selectedItems();
475
476     //if nothing selected resume play
477
478     if (items.isEmpty())
479     {
480         pPauseAction_->setChecked(false);
481         return;
482
483     }
484
485     //If something was selected check if it was one of the menu items and act on it
486     //(Nothing else should be made selectable anyway)
487
488     //Menu functions
489
490     QGraphicsItem* pItem = items.at(0); //Selecting an item brings here, thus only selecting one item should be possible
491                                        //... so we can just take the first one
492
493     //Selection is just used to get notice of a menu item being clicked, removed after use
494
495     clearSelection();
496
497
498     //Act upon the selected item
499
500
501     if (pItem == pRestartGameItem_)
502     {
503 //        qDebug() << "game restart requested";
504         restartGame();
505         pPauseAction_->setChecked(false); //unpause game
506
507     }
508
509     else if (pItem == pRestartLevelItem_)
510     {
511 //        qDebug() << "Level restart requested";
512         restartLevel();
513         pPauseAction_->setChecked(false); //unpause game
514
515     }
516
517     else if (pItem == pSettingsItem_)
518     {
519         pVibrateAction_->toggle();
520
521         QSettings settings;
522         settings.setValue("vibration",pVibrateAction_->isChecked());
523
524         QString text = pSettingsItem_->toHtml();
525         if (pVibrateAction_->isChecked())
526             text.replace(" on"," off"); //don't remove spaces or you get vibratioff...
527         else
528             text.replace(" off"," on");
529         pSettingsItem_->setHtml(text);
530     }
531
532     else if (pItem == pAboutItem_)
533     {
534         about();
535     }
536
537     else if (pItem == pQuitItem_)
538     {
539         qApp->quit();
540     }
541
542     else if (pItem == pChooseLevelsetItem_)
543     {
544         pPausetextItem_->hide();
545         pSelectLevelsetFromListItem_->show();
546     }
547
548 }
549
550
551
552 void SeaScene::createMenuItems()
553 {
554
555     QFont font;
556     font.setPixelSize(35);
557
558
559
560     pPausetextItem_ = new QGraphicsTextItem;
561
562  // This is for fremantle
563 //    pPausetextItem_->setHtml("<font size = \"5\" color = darkorange> Game paused. Tap to continue.");
564
565 //Harmattan needs bigger font
566     pPausetextItem_->setHtml("<font size = \"7\" color = darkorange> Game paused. Tap to continue.");
567
568
569     pPausetextItem_->setZValue(1000);
570     pPausetextItem_->setPos(200,50);
571     addItem(pPausetextItem_);
572     pPausetextItem_->hide();
573
574     menuItemCount_ = 0;
575
576   // This is for fremantle
577  //   QString menufonthtml = "<font size = \"4\" color = darkorange>";
578
579
580  //Harmattan needs bigger font
581         QString menufonthtml = "<font size = \"6\" color = darkorange>";
582
583
584     pRestartGameItem_ = new QGraphicsTextItem;
585     pRestartGameItem_->setHtml(tr("Restart <br> game").prepend(menufonthtml));
586     prepareForMenu(pRestartGameItem_);
587
588     pRestartLevelItem_ = new QGraphicsTextItem;
589     pRestartLevelItem_->setHtml(tr("Restart <br> level").prepend(menufonthtml));
590     prepareForMenu(pRestartLevelItem_);
591
592     pChooseLevelsetItem_ = new QGraphicsTextItem;
593     pChooseLevelsetItem_->setHtml(tr("Choose <br> levelset").prepend(menufonthtml));
594     prepareForMenu(pChooseLevelsetItem_);
595
596     pSettingsItem_ = new QGraphicsTextItem;
597     QString vibraText(tr("Turn vibration <br> effects "));
598     QString statusText;
599     if (pVibrateAction_->isChecked())
600     {
601         statusText = "off";
602     }
603     else
604     {
605         statusText = "on";
606     }
607     vibraText.append(statusText);
608     pSettingsItem_->setHtml(vibraText.prepend(menufonthtml));
609     prepareForMenu(pSettingsItem_);
610
611     pAboutItem_ = new QGraphicsTextItem;
612     pAboutItem_->setHtml(tr("About <br> game").prepend(menufonthtml));
613     prepareForMenu(pAboutItem_);
614
615     pQuitItem_ = new QGraphicsTextItem;
616     pQuitItem_->setHtml(tr("Quit <br> game").prepend(menufonthtml));
617     prepareForMenu(pQuitItem_);
618
619 }
620
621 void SeaScene::prepareForMenu(QGraphicsItem * pItem)
622 {
623
624     //Menu items have pause text item as their parent and are thus added to scene automatically
625     //They are also shown and hidden with it, resulting in the menu being visble when the game is paused
626     //Their coordinates are given relative to the parent.
627
628
629     pItem->setParentItem(pPausetextItem_);
630     pItem->setZValue(1000);
631     pItem->setFlag(QGraphicsItem::ItemIsSelectable);
632     pItem->setY(150);
633     pItem->setX(menuItemCount_++*160-150);
634  }
635
636
637 void SeaScene::about()
638 {
639     pPausetextItem_->hide();
640     pAboutBoxItem_->show();
641 }
642
643
644 void SeaScene::restartLevel()
645 {
646
647     levelScore_ = 0;
648
649     setupMap(levelset_.getLevel(currentLevel_));  //getLevel() returns default constructor Level if index is invalid, so no risk of crash
650
651     scoreCounter_.start();
652
653     vibrationActivate(pVibrateAction_->isChecked());  //Vibration effects are lost without this
654    // qDebug() << pVibrateAction_->isChecked();
655     autopauseTimer.start();  //reset counting towards autopause
656
657
658 }
659
660
661
662 void SeaScene::nextLevel()
663 {
664
665     //get score for previous level
666     levelScore_ += scoreCounter_.elapsed();
667     totalScore_ += levelScore_;
668     int highscore = levelset_.getLevelHighScore(currentLevel_);
669
670     qDebug() << highscore;
671
672     QString scoretext;
673
674     if (levelScore_ >= highscore)
675     {
676         scoretext = tr("<font size=\"7\" color = darkorange>Your time: %1.%2 s<br>Best time: %3.%4 s").arg(levelScore_/1000).arg((levelScore_%1000)/100).arg(highscore/1000).arg((highscore%1000)/100);
677     }
678
679     else //New high score!
680
681     {
682         scoretext = tr("<font size=\"7\" color = darkorange>Your time %1.%2 s is<br>the new best time!").arg(levelScore_/1000).arg((levelScore_%1000)/100);
683         levelset_.setLevelHighScore(currentLevel_,levelScore_);
684     }
685
686     //pause to show the highscore or victory screen
687
688     turnPauseOn();
689     pPausetextItem_->hide();
690
691
692     //Go to the next level if available
693     currentLevel_++;
694
695     if ( currentLevel_ < levelset_.numberOfLevels() )
696     {
697
698        pLevelCompletedItem_->setHtml(scoretext);
699        pLevelCompletedItem_->show();
700 //       restartLevel();
701     }
702
703     else //Victory!
704     {
705         int totalHighsore = levelset_.getTotalHighScore();
706         if (totalScore_ >= totalHighsore)
707         {
708             scoretext.append(tr("<br>Your total time: %1.%2 s<br>Best total time: %3.%4 s").arg(totalScore_/1000).arg((totalScore_%1000)/100).arg(totalHighsore/1000).arg((totalHighsore%1000)/100));
709         }
710         else //new total high score
711         {
712             scoretext.append(tr("<br>Your total time %1.%2 s is<br>the new best time").arg(totalScore_/1000).arg((totalScore_%1000)/100));
713             levelset_.setTotalHighScore(totalScore_);
714         }
715
716         pVictoryScoreItem_->setHtml(scoretext);
717         pVictoryCongratulationsItem_->show();
718     }
719 }
720
721
722 void SeaScene::restartGame()
723 {
724     currentLevel_ = 0;
725     totalScore_ = 0;
726     restartLevel();
727 }
728
729
730 void SeaScene::forcePause()
731 {
732     //Pause without setting the pause action state
733     pause(true);
734 }
735
736 void SeaScene::softContinue()
737 {
738     //Continue if not being paused by the user
739     // Reverts forcePause()
740
741     pause(pPauseAction_->isChecked());
742 }
743
744
745 void SeaScene::createVictoryItems()
746 {
747     pVictoryCongratulationsItem_ = new QGraphicsTextItem;
748     pVictoryCongratulationsItem_->setHtml("<font size=\"7\" color = darkorange> <b> Victory!");
749     pVictoryCongratulationsItem_->hide();
750     pVictoryCongratulationsItem_->setPos(315,30);
751     pVictoryCongratulationsItem_->setZValue(1000);
752     addItem(pVictoryCongratulationsItem_);
753
754
755     //coordinates are relative to the parent
756
757     QGraphicsTextItem * pTextItem = new QGraphicsTextItem(pVictoryCongratulationsItem_);
758     pTextItem->setHtml("<font size=\"7\" color = darkorange> Congratulations!");
759     pTextItem->setPos(-50,80);
760     pTextItem->setZValue(1000);
761
762     QGraphicsTextItem * pMiddleTextItem = new QGraphicsTextItem(pVictoryCongratulationsItem_);
763     pMiddleTextItem->setHtml("<font size=\"7\" color = darkorange> You have saved all the ghosts.");
764     pMiddleTextItem->setPos(-145,120);
765     pMiddleTextItem->setZValue(1000);
766
767
768     pVictoryScoreItem_ = new QGraphicsTextItem(pVictoryCongratulationsItem_);
769     pVictoryScoreItem_->setPos(-50,180);
770     pMiddleTextItem->setZValue(1000);
771     //Text is set at usetime!
772
773     QGraphicsTextItem * pLowestTextItem = new QGraphicsTextItem(pVictoryCongratulationsItem_);
774     pLowestTextItem->setHtml("<font size=\"7\" color = darkorange> Tap to play again");
775     pLowestTextItem->setPos(-50,360);
776     pLowestTextItem->setZValue(1000);
777 }
778
779
780 void SeaScene::createAboutBoxItems()
781 {
782     pAboutBoxItem_ = new QGraphicsTextItem;
783     addItem(pAboutBoxItem_);
784     pAboutBoxItem_->setPos(25,50);
785     pAboutBoxItem_->setZValue(1000);
786     pAboutBoxItem_->hide();
787
788     pAboutBoxItem_->setHtml(tr("<font color = darkorange size = \"7\">"
789                           "%1 <br> <font size = \"7\"> Version %2"
790                           "<p><font size = \"6\"> Copyright 2011 Heli Hyv&auml;ttinen"
791                           "<p><font size = \"6\"> License: General Public License v2"
792                           "<p><font size = \"5\"> Web: http://ghostsoverboard.garage.maemo.org/<br>"
793                           "Bug Reports: <br> https://bugs.maemo.org/"
794                           "enter_bug.cgi?product=Ghosts%20Overboard"
795                           ).arg(QApplication::applicationName(),QApplication::applicationVersion()));
796
797 }
798
799 void SeaScene::setItemPointersNull()
800 {
801     pPausetextItem_ = NULL;
802     pRestartLevelItem_ = NULL;
803     pRestartGameItem_ = NULL;
804     pSettingsItem_ = NULL;
805     pAboutItem_ = NULL;
806     pQuitItem_ = NULL ;
807 //    pMinimizeItem_ = NULL; //Fremantle spesific
808     pChooseLevelsetItem_ = NULL;
809
810     pAboutBoxItem_ = NULL;
811     pLevelCompletedItem_ = NULL;
812     pVictoryCongratulationsItem_ = NULL;
813     pVictoryScoreItem_ = NULL;
814
815 }
816
817 void SeaScene::turnPauseOn()
818 {
819     pPauseAction_->setChecked(true);
820 }
821
822
823
824 void SeaScene::createLevelCompletedItems()
825 {
826     pLevelCompletedItem_ = new QGraphicsTextItem;
827     addItem(pLevelCompletedItem_);
828     pLevelCompletedItem_->setPos(240,100);
829     pLevelCompletedItem_->setZValue(1000);
830     pLevelCompletedItem_->hide();
831     //The text is set at usetime
832
833     QGraphicsTextItem * pTapForNextLevelItem = new QGraphicsTextItem(pLevelCompletedItem_);
834     pTapForNextLevelItem->setPos(-60,100);
835     pTapForNextLevelItem->setZValue(1000);
836     pTapForNextLevelItem->setHtml("<font size=\"7\" color = darkorange>Tap to start the next level");
837 }
838
839 void SeaScene::createSelectLevelsetFromListItems()
840 {
841     pSelectLevelsetFromListItem_ = new QGraphicsTextItem;
842     addItem(pSelectLevelsetFromListItem_);
843     pSelectLevelsetFromListItem_->setPos(40,80);
844     pSelectLevelsetFromListItem_->setZValue(1000);
845     pSelectLevelsetFromListItem_->hide();
846
847     QString list ("<font color = darkorange size = \"7\">");
848
849     foreach (Levelset set, availableLevelsets_)
850     {
851         list.append(set.getName());
852         list.append("<br>");
853     }
854
855     pSelectLevelsetFromListItem_->setHtml(list);
856 }