Menu items in correct places again
[ghostsoverboard] / seascene.h
1 /**************************************************************************
2         Ghosts Overboard - a game for Maemo 5
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
24 #ifndef SEASCENE_H
25 #define SEASCENE_H
26
27 #include <QGraphicsScene>
28 #include<QGraphicsItemGroup>
29 #include "screenlitkeeper.h"
30 #include "level.h"
31 #include "levelset.h"
32 #include <QAction>
33 #include <QTimer>
34 #include <QSystemDeviceInfo>
35 #include <QTime>
36
37 using namespace QtMobility;
38
39 class SeaScene : public QGraphicsScene
40 {
41     Q_OBJECT
42 public:
43     explicit SeaScene(QObject *parent = 0);
44
45 signals:
46
47     void allGhostsPicked();
48     void pauseOn();
49     void pauseOff();
50     void vibrationActivated(bool on);
51     void minimizeRequested();
52     void fullscreenRequested();
53     void deviceJustLocked();
54
55 public slots:
56
57     /*! Places all needed items for a level to (re)start.
58     Relies on the scene size to be explicitly set to a a value that will persist troughout play.
59     @param ghosts the number of ghosts to be placed on the map
60     @param rocks the number of rocks to be placed on the map
61     @param octopuses number of octopuses to be placed on the map
62     */
63     void setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed);
64
65     void setupMap(Level level);
66
67     void spreadGhosts(int ghosts);
68
69     void removeGhost(QGraphicsItem * pGhost);
70
71     void ghostsDropped(int ghosts);
72
73     void pause (bool paused);
74
75     void vibrationActivate(bool);
76
77     void handleScreenTapped();
78
79     void about();
80
81     void restartLevel();
82
83     void nextLevel();
84
85     void restartGame();
86
87     void forcePause();
88
89     void softContinue();
90
91     void setItemPointersNull();
92
93     void turnPauseOn();
94
95     void handleDeviceLocked(bool isLocked);
96
97     void pollDeviceLocked();
98
99
100
101
102
103 protected:
104
105     /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
106         The position is the upper left corner of a free 40x40 pixels slot.
107     */
108
109     QPointF* findRandomFreeSlot();
110
111     void createMenuItems();
112     void prepareForMenu(QGraphicsItem * pItem);
113     void createAboutBoxItems();
114     void createVictoryItems();
115     void createLevelCompletedItems();
116     void createSelectLevelsetFromListItems();
117
118     const QString ghostImageFilename_;
119     const QString rockImageFilename_;
120     const QString octopusImageFilename_;
121     const QStringList shipImageFilenames_;
122
123     QList<QPointF> freeTiles_;
124
125     int ghostsLeft_;
126
127     QList<QGraphicsItem*> movingItems_;
128
129     bool paused_;
130
131     ScreenLitKeeper screenLitKeeper_;
132
133     int menuItemCount_;
134
135     QGraphicsTextItem * pPausetextItem_;
136
137     QGraphicsTextItem * pRestartLevelItem_;
138     QGraphicsTextItem * pRestartGameItem_;
139     QGraphicsTextItem * pSettingsItem_;
140     QGraphicsTextItem * pAboutItem_;
141     QGraphicsTextItem * pQuitItem_;
142     QGraphicsTextItem * pMinimizeItem_;
143     QGraphicsTextItem * pChooseLevelsetItem_;
144
145     QGraphicsTextItem * pVictoryCongratulationsItem_;
146     QGraphicsTextItem * pVictoryScoreItem_;
147     QGraphicsTextItem * pAboutBoxItem_;
148
149     QGraphicsTextItem * pLevelCompletedItem_;
150
151     QGraphicsTextItem * pSelectLevelsetFromListItem_;
152
153     QList<QGraphicsItem *>  levelsetItems_;
154
155     QList<Levelset> availableLevelsets_;
156
157     Levelset levelset_;
158
159     int currentLevel_;
160
161
162     QAction* pVibrateAction_;
163
164     QAction* pPauseAction_;
165
166     QTimer autopauseTimer;
167
168     QSystemDeviceInfo deviceInfo_;
169
170     bool alreadyLocked_;
171
172     QTimer deviceLockPollTimer_;
173
174     QTime scoreCounter_;
175     int totalScore_;
176     int levelScore_;
177
178 };
179
180 #endif // SEASCENE_H