-rw-r--r-- | noncore/games/kpacman/kpacman.cpp | 23 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacman.h | 18 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacmanwidget.cpp | 9 | ||||
-rw-r--r-- | noncore/games/kpacman/referee.cpp | 4 | ||||
-rw-r--r-- | noncore/games/kpacman/score.cpp | 61 |
5 files changed, 14 insertions, 101 deletions
diff --git a/noncore/games/kpacman/kpacman.cpp b/noncore/games/kpacman/kpacman.cpp index 7df6ef0..d9d2d69 100644 --- a/noncore/games/kpacman/kpacman.cpp +++ b/noncore/games/kpacman/kpacman.cpp | |||
@@ -1,329 +1,324 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kpacman.h> | 5 | #include <kpacman.h> |
6 | #include <kpacman.moc> | 6 | #include <kpacman.moc> |
7 | #include <kcolordlg.h> | 7 | #include <kcolordlg.h> |
8 | #elif defined( QPE_PORT ) | 8 | #elif defined( QPE_PORT ) |
9 | #include <qmenubar.h> | 9 | #include <qmenubar.h> |
10 | #include "config.h" | 10 | #include "config.h" |
11 | #include <qapplication.h> | 11 | #include <qapplication.h> |
12 | #include "kpacman.h" | 12 | #include "kpacman.h" |
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | #include <qkeycode.h> | 15 | #include <qkeycode.h> |
16 | #include <qcolor.h> | 16 | #include <qcolor.h> |
17 | #include <qstring.h> | 17 | #include <qstring.h> |
18 | #include <qpopmenu.h> | 18 | #include <qpopmenu.h> |
19 | #include <qmsgbox.h> | 19 | #include <qmsgbox.h> |
20 | 20 | ||
21 | Kpacman::Kpacman(QWidget *parent, const char *name) | 21 | Kpacman::Kpacman(QWidget *parent, const char *name) |
22 | : KTMainWindow(parent, name) | 22 | : KTMainWindow(parent, name) |
23 | { | 23 | { |
24 | schemesPopup = new QList<QPopupMenu>; | 24 | schemesPopup = new QList<QPopupMenu>; |
25 | schemesPopup->setAutoDelete(TRUE); | 25 | schemesPopup->setAutoDelete(TRUE); |
26 | 26 | ||
27 | menu(); | 27 | menu(); |
28 | 28 | ||
29 | view = new KpacmanWidget( this, QString(name)+"widget"); | 29 | m_view = new QWidget( this, "m_view" ); |
30 | m_view->setBackgroundColor( black ); | ||
31 | m_layout = new QGridLayout( m_view ); | ||
32 | m_layout->setMargin( 7 ); | ||
30 | 33 | ||
31 | #ifndef QWS | 34 | view = new KpacmanWidget( this, QString(name)+"widget"); |
32 | setFixedSize(view->width(), view->height()); | 35 | m_layout->addWidget( view, 0, 0 ); |
33 | #else | 36 | |
34 | setCaption( "Kpacman" ); | 37 | setCaption( "KPacman" ); |
35 | #endif | ||
36 | 38 | ||
37 | view->referee->setFocus(); | 39 | view->referee->setFocus(); |
38 | 40 | ||
39 | connect(view->referee, SIGNAL(setScore(int, int)), | 41 | connect(view->referee, SIGNAL(setScore(int, int)), |
40 | view->score, SLOT(setScore(int, int))); | 42 | view->score, SLOT(setScore(int, int))); |
41 | connect(view->referee, SIGNAL(setPoints(int)), | 43 | connect(view->referee, SIGNAL(setPoints(int)), |
42 | view->score, SLOT(set(int))); | 44 | view->score, SLOT(set(int))); |
43 | connect(view->referee, SIGNAL(setLifes(int)), | 45 | connect(view->referee, SIGNAL(setLifes(int)), |
44 | view->status, SLOT(setLifes(int))); | 46 | view->status, SLOT(setLifes(int))); |
45 | connect(view->referee, SIGNAL(setLevel(int)), | 47 | connect(view->referee, SIGNAL(setLevel(int)), |
46 | view->status, SLOT(setLevel(int))); | 48 | view->status, SLOT(setLevel(int))); |
47 | connect(view->referee, SIGNAL(forcedHallOfFame(bool)), | 49 | connect(view->referee, SIGNAL(forcedHallOfFame(bool)), |
48 | this, SLOT(forcedHallOfFame(bool))); | 50 | this, SLOT(forcedHallOfFame(bool))); |
49 | connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused())); | 51 | connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused())); |
50 | connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew())); | 52 | connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew())); |
51 | 53 | ||
52 | connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew())); | 54 | connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew())); |
53 | connect(view->score, SIGNAL(forcedHallOfFame(bool)), | 55 | connect(view->score, SIGNAL(forcedHallOfFame(bool)), |
54 | this, SLOT(forcedHallOfFame(bool))); | 56 | this, SLOT(forcedHallOfFame(bool))); |
55 | 57 | ||
56 | APP_CONFIG_BEGIN( cfg ); | 58 | APP_CONFIG_BEGIN( cfg ); |
57 | focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE); | 59 | focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE); |
58 | focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE); | 60 | focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE); |
59 | hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE); | 61 | hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE); |
60 | APP_CONFIG_END( cfg ); | 62 | APP_CONFIG_END( cfg ); |
61 | 63 | ||
62 | toggleFocusOutPause(); | 64 | toggleFocusOutPause(); |
63 | toggleFocusInContinue(); | 65 | toggleFocusInContinue(); |
64 | toggleHideMouseCursor(); | 66 | toggleHideMouseCursor(); |
65 | 67 | ||
66 | #ifndef QWS | 68 | setCentralWidget( m_view ); |
67 | menuBar->show(); | ||
68 | view->show(); | ||
69 | setMenu(menuBar); | ||
70 | setView(view); | ||
71 | #else | ||
72 | setCentralWidget( view ); | ||
73 | #endif | ||
74 | } | 69 | } |
75 | 70 | ||
76 | Kpacman::~Kpacman() | 71 | Kpacman::~Kpacman() |
77 | { | 72 | { |
78 | APP_CONFIG_BEGIN( cfg ); | 73 | APP_CONFIG_BEGIN( cfg ); |
79 | cfg->writeEntry("FocusOutPause", focusOutPause); | 74 | cfg->writeEntry("FocusOutPause", focusOutPause); |
80 | cfg->writeEntry("FocusInContinue", focusInContinue); | 75 | cfg->writeEntry("FocusInContinue", focusInContinue); |
81 | cfg->writeEntry("HideMouseCursor", hideMouseCursor); | 76 | cfg->writeEntry("HideMouseCursor", hideMouseCursor); |
82 | APP_CONFIG_END( cfg ); | 77 | APP_CONFIG_END( cfg ); |
83 | delete _menuBar; | 78 | delete _menuBar; |
84 | } | 79 | } |
85 | 80 | ||
86 | void Kpacman::menu() | 81 | void Kpacman::menu() |
87 | { | 82 | { |
88 | gamePopup = new QPopupMenu(); | 83 | gamePopup = new QPopupMenu(); |
89 | CHECK_PTR( gamePopup ); | 84 | CHECK_PTR( gamePopup ); |
90 | newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2); | 85 | newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2); |
91 | pauseID = gamePopup->insertItem(tr("&Pause"), | 86 | pauseID = gamePopup->insertItem(tr("&Pause"), |
92 | this, SLOT(pauseKpacman()), Key_F3); | 87 | this, SLOT(pauseKpacman()), Key_F3); |
93 | hofID = gamePopup->insertItem(tr("&Hall of fame"), | 88 | hofID = gamePopup->insertItem(tr("&Hall of fame"), |
94 | this, SLOT(toggleHallOfFame()), Key_F4); | 89 | this, SLOT(toggleHallOfFame()), Key_F4); |
95 | gamePopup->insertSeparator(); | 90 | gamePopup->insertSeparator(); |
96 | gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q); | 91 | gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q); |
97 | gamePopup->setCheckable(TRUE); | 92 | gamePopup->setCheckable(TRUE); |
98 | 93 | ||
99 | optionsPopup = new QPopupMenu(); | 94 | optionsPopup = new QPopupMenu(); |
100 | CHECK_PTR(optionsPopup); | 95 | CHECK_PTR(optionsPopup); |
101 | 96 | ||
102 | modesPopup = new QPopupMenu(); | 97 | modesPopup = new QPopupMenu(); |
103 | CHECK_PTR(modesPopup); | 98 | CHECK_PTR(modesPopup); |
104 | 99 | ||
105 | hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"), | 100 | hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"), |
106 | this, SLOT(toggleHideMouseCursor()), | 101 | this, SLOT(toggleHideMouseCursor()), |
107 | CTRL+Key_H); | 102 | CTRL+Key_H); |
108 | optionsPopup->insertSeparator(); | 103 | optionsPopup->insertSeparator(); |
109 | 104 | ||
110 | if (lookupSchemes() > 0) { | 105 | if (lookupSchemes() > 0) { |
111 | optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup); | 106 | optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup); |
112 | optionsPopup->insertSeparator(); | 107 | optionsPopup->insertSeparator(); |
113 | } | 108 | } |
114 | 109 | ||
115 | focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"), | 110 | focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"), |
116 | this, SLOT(toggleFocusOutPause())); | 111 | this, SLOT(toggleFocusOutPause())); |
117 | focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"), | 112 | focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"), |
118 | this, SLOT(toggleFocusInContinue())); | 113 | this, SLOT(toggleFocusInContinue())); |
119 | optionsPopup->insertSeparator(); | 114 | optionsPopup->insertSeparator(); |
120 | 115 | ||
121 | optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys())); | 116 | optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys())); |
122 | 117 | ||
123 | #ifndef QWS | 118 | #ifndef QWS |
124 | QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n" | 119 | QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n" |
125 | "Joerg Thoennissen (joe@dsite.de)\n\n" | 120 | "Joerg Thoennissen (joe@dsite.de)\n\n" |
126 | "A pacman game for the KDE Desktop\n\n" | 121 | "A pacman game for the KDE Desktop\n\n" |
127 | "The program based on the source of ksnake\n" | 122 | "The program based on the source of ksnake\n" |
128 | "by Michel Filippi (mfilippi@sade.rhein-main.de).\n" | 123 | "by Michel Filippi (mfilippi@sade.rhein-main.de).\n" |
129 | "The design was strongly influenced by the pacman\n" | 124 | "The design was strongly influenced by the pacman\n" |
130 | "(c) 1980 MIDWAY MFG.CO.\n\n" | 125 | "(c) 1980 MIDWAY MFG.CO.\n\n" |
131 | "I like to thank my girlfriend Elke Krueers for\n" | 126 | "I like to thank my girlfriend Elke Krueers for\n" |
132 | "the last 10 years of her friendship.\n"); | 127 | "the last 10 years of her friendship.\n"); |
133 | aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE); | 128 | aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE); |
134 | aboutText.replace(QRegExp("@VERSION@"), VERSION); | 129 | aboutText.replace(QRegExp("@VERSION@"), VERSION); |
135 | QPopupMenu *helpPopup = helpMenu(aboutText, FALSE); | 130 | QPopupMenu *helpPopup = helpMenu(aboutText, FALSE); |
136 | #endif | 131 | #endif |
137 | 132 | ||
138 | //_menuBar = new KMenuBar(this); | 133 | //_menuBar = new KMenuBar(this); |
139 | //CHECK_PTR( _menuBar ); | 134 | //CHECK_PTR( _menuBar ); |
140 | //_menuBar->insertItem(tr("&Game"), gamePopup); | 135 | //_menuBar->insertItem(tr("&Game"), gamePopup); |
141 | //_menuBar->insertItem(tr("&Options"), optionsPopup); | 136 | //_menuBar->insertItem(tr("&Options"), optionsPopup); |
142 | //_menuBar->insertSeparator(); | 137 | //_menuBar->insertSeparator(); |
143 | #ifndef QWS | 138 | #ifndef QWS |
144 | _menuBar->insertItem(tr("&Help"), helpPopup); | 139 | _menuBar->insertItem(tr("&Help"), helpPopup); |
145 | #endif | 140 | #endif |
146 | } | 141 | } |
147 | 142 | ||
148 | int Kpacman::lookupSchemes() | 143 | int Kpacman::lookupSchemes() |
149 | { | 144 | { |
150 | APP_CONFIG_BEGIN( cfg ); | 145 | APP_CONFIG_BEGIN( cfg ); |
151 | int ModeCount = cfg->readNumEntry("ModeCount", -1); | 146 | int ModeCount = cfg->readNumEntry("ModeCount", -1); |
152 | int Mode = cfg->readNumEntry("Mode", -1); | 147 | int Mode = cfg->readNumEntry("Mode", -1); |
153 | int SchemeCount = cfg->readNumEntry("SchemeCount"); | 148 | int SchemeCount = cfg->readNumEntry("SchemeCount"); |
154 | int Scheme = cfg->readNumEntry("Scheme", -1); | 149 | int Scheme = cfg->readNumEntry("Scheme", -1); |
155 | 150 | ||
156 | if (SchemeCount == 0 || Scheme == -1) { | 151 | if (SchemeCount == 0 || Scheme == -1) { |
157 | QMessageBox::warning(this, tr("Configuration Error"), | 152 | QMessageBox::warning(this, tr("Configuration Error"), |
158 | tr("There are no schemes defined,\n" | 153 | tr("There are no schemes defined,\n" |
159 | "or no scheme is selected.")); | 154 | "or no scheme is selected.")); |
160 | APP_CONFIG_END( cfg ); | 155 | APP_CONFIG_END( cfg ); |
161 | return 0; | 156 | return 0; |
162 | } | 157 | } |
163 | 158 | ||
164 | connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); | 159 | connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); |
165 | modeID.resize(ModeCount > 0 ? ModeCount : 0); | 160 | modeID.resize(ModeCount > 0 ? ModeCount : 0); |
166 | 161 | ||
167 | if (!schemesPopup->isEmpty()) | 162 | if (!schemesPopup->isEmpty()) |
168 | schemesPopup->clear(); | 163 | schemesPopup->clear(); |
169 | 164 | ||
170 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 165 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
171 | 166 | ||
172 | QString ModeGroup; | 167 | QString ModeGroup; |
173 | QString ModeName; | 168 | QString ModeName; |
174 | 169 | ||
175 | for (int m = 0; m < ModeCount; m++) { | 170 | for (int m = 0; m < ModeCount; m++) { |
176 | ModeGroup.sprintf("Mode %d", m); | 171 | ModeGroup.sprintf("Mode %d", m); |
177 | cfg->setGroup(ModeGroup); | 172 | cfg->setGroup(ModeGroup); |
178 | 173 | ||
179 | ModeName = cfg->readEntry("Description", ModeGroup); | 174 | ModeName = cfg->readEntry("Description", ModeGroup); |
180 | 175 | ||
181 | QPopupMenu *p = new QPopupMenu; | 176 | QPopupMenu *p = new QPopupMenu; |
182 | p->setCheckable(TRUE); | 177 | p->setCheckable(TRUE); |
183 | connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); | 178 | connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int))); |
184 | schemesPopup->append(p); | 179 | schemesPopup->append(p); |
185 | 180 | ||
186 | modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m)); | 181 | modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m)); |
187 | modesPopup->setItemEnabled(modeID[m], FALSE); | 182 | modesPopup->setItemEnabled(modeID[m], FALSE); |
188 | modesPopup->setItemChecked(modeID[m], m == Mode); | 183 | modesPopup->setItemChecked(modeID[m], m == Mode); |
189 | } | 184 | } |
190 | 185 | ||
191 | schemeID.resize(SchemeCount); | 186 | schemeID.resize(SchemeCount); |
192 | schemeMode.resize(SchemeCount); | 187 | schemeMode.resize(SchemeCount); |
193 | 188 | ||
194 | QString SchemeGroup; | 189 | QString SchemeGroup; |
195 | QString SchemeName; | 190 | QString SchemeName; |
196 | int SchemeMode; | 191 | int SchemeMode; |
197 | 192 | ||
198 | for (int i = 0; i < SchemeCount; i++) { | 193 | for (int i = 0; i < SchemeCount; i++) { |
199 | SchemeGroup.sprintf("Scheme %d", i); | 194 | SchemeGroup.sprintf("Scheme %d", i); |
200 | cfg->setGroup(SchemeGroup); | 195 | cfg->setGroup(SchemeGroup); |
201 | 196 | ||
202 | SchemeName = cfg->readEntry("Description", SchemeGroup); | 197 | SchemeName = cfg->readEntry("Description", SchemeGroup); |
203 | SchemeMode = cfg->readNumEntry("Mode", -1); | 198 | SchemeMode = cfg->readNumEntry("Mode", -1); |
204 | 199 | ||
205 | schemeMode[i] = SchemeMode; | 200 | schemeMode[i] = SchemeMode; |
206 | if (SchemeMode == -1) { | 201 | if (SchemeMode == -1) { |
207 | schemeID[i] = modesPopup->insertItem(SchemeName); | 202 | schemeID[i] = modesPopup->insertItem(SchemeName); |
208 | modesPopup->setItemChecked(schemeID[i], i == Scheme); | 203 | modesPopup->setItemChecked(schemeID[i], i == Scheme); |
209 | } else { | 204 | } else { |
210 | schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName); | 205 | schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName); |
211 | schemesPopup->at(SchemeMode)-> | 206 | schemesPopup->at(SchemeMode)-> |
212 | setItemChecked(schemeID[i], i == Scheme); | 207 | setItemChecked(schemeID[i], i == Scheme); |
213 | modesPopup->setItemEnabled(modeID[SchemeMode], TRUE); | 208 | modesPopup->setItemEnabled(modeID[SchemeMode], TRUE); |
214 | } | 209 | } |
215 | } | 210 | } |
216 | 211 | ||
217 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 212 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
218 | 213 | ||
219 | APP_CONFIG_END( cfg ); | 214 | APP_CONFIG_END( cfg ); |
220 | return SchemeCount; | 215 | return SchemeCount; |
221 | } | 216 | } |
222 | 217 | ||
223 | void Kpacman::quitKpacman() | 218 | void Kpacman::quitKpacman() |
224 | { | 219 | { |
225 | APP_QUIT(); | 220 | APP_QUIT(); |
226 | } | 221 | } |
227 | 222 | ||
228 | void Kpacman::newKpacman() | 223 | void Kpacman::newKpacman() |
229 | { | 224 | { |
230 | if (!gamePopup->isItemEnabled(hofID)) | 225 | if (!gamePopup->isItemEnabled(hofID)) |
231 | gamePopup->setItemEnabled(hofID, TRUE); | 226 | gamePopup->setItemEnabled(hofID, TRUE); |
232 | 227 | ||
233 | if (gamePopup->isItemChecked(hofID)) | 228 | if (gamePopup->isItemChecked(hofID)) |
234 | toggleHallOfFame(); | 229 | toggleHallOfFame(); |
235 | 230 | ||
236 | if (gamePopup->isItemChecked(pauseID)) | 231 | if (gamePopup->isItemChecked(pauseID)) |
237 | pauseKpacman(); | 232 | pauseKpacman(); |
238 | 233 | ||
239 | view->referee->play(); | 234 | view->referee->play(); |
240 | } | 235 | } |
241 | 236 | ||
242 | void Kpacman::pauseKpacman() | 237 | void Kpacman::pauseKpacman() |
243 | { | 238 | { |
244 | view->referee->pause(); | 239 | view->referee->pause(); |
245 | view->score->setPause(gamePopup->isItemChecked(pauseID)); | 240 | view->score->setPause(gamePopup->isItemChecked(pauseID)); |
246 | } | 241 | } |
247 | 242 | ||
248 | void Kpacman::toggleHallOfFame() | 243 | void Kpacman::toggleHallOfFame() |
249 | { | 244 | { |
250 | gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID)); | 245 | gamePopup->setItemChecked(hofID, !gamePopup->isItemChecked(hofID)); |
251 | view->referee->toggleHallOfFame(); | 246 | view->referee->toggleHallOfFame(); |
252 | 247 | ||
253 | if (gamePopup->isItemChecked(hofID)) { | 248 | if (gamePopup->isItemChecked(hofID)) { |
254 | view->referee->lower(); | 249 | view->referee->lower(); |
255 | view->status->lower(); | 250 | view->status->lower(); |
256 | } else { | 251 | } else { |
257 | view->status->raise(); | 252 | view->status->raise(); |
258 | view->referee->raise(); | 253 | view->referee->raise(); |
259 | view->referee->setFocus(); | 254 | view->referee->setFocus(); |
260 | } | 255 | } |
261 | } | 256 | } |
262 | 257 | ||
263 | /* | 258 | /* |
264 | * Disable or enable the "Hall of fame"-menuitem if the referee says so. | 259 | * Disable or enable the "Hall of fame"-menuitem if the referee says so. |
265 | * This is done, to disable turning off the "hall of fame"-display, in the automated | 260 | * This is done, to disable turning off the "hall of fame"-display, in the automated |
266 | * sequence of displaying the introduction, the demonstration (or playing) and the | 261 | * sequence of displaying the introduction, the demonstration (or playing) and the |
267 | * hall of fame. | 262 | * hall of fame. |
268 | * If on == TRUE then also lower the referee and the status widgets. | 263 | * If on == TRUE then also lower the referee and the status widgets. |
269 | */ | 264 | */ |
270 | void Kpacman::forcedHallOfFame(bool on) | 265 | void Kpacman::forcedHallOfFame(bool on) |
271 | { | 266 | { |
272 | if (!on && !gamePopup->isItemChecked(hofID)) | 267 | if (!on && !gamePopup->isItemChecked(hofID)) |
273 | return; | 268 | return; |
274 | 269 | ||
275 | gamePopup->setItemEnabled(hofID, !on); | 270 | gamePopup->setItemEnabled(hofID, !on); |
276 | gamePopup->setItemChecked(hofID, on); | 271 | gamePopup->setItemChecked(hofID, on); |
277 | 272 | ||
278 | view->referee->toggleHallOfFame(); | 273 | view->referee->toggleHallOfFame(); |
279 | if (on) { | 274 | if (on) { |
280 | view->referee->lower(); | 275 | view->referee->lower(); |
281 | view->status->lower(); | 276 | view->status->lower(); |
282 | } else { | 277 | } else { |
283 | view->status->raise(); | 278 | view->status->raise(); |
284 | view->referee->raise(); | 279 | view->referee->raise(); |
285 | view->referee->setFocus(); | 280 | view->referee->setFocus(); |
286 | view->referee->intro(); | 281 | view->referee->intro(); |
287 | } | 282 | } |
288 | } | 283 | } |
289 | 284 | ||
290 | void Kpacman::togglePaused() | 285 | void Kpacman::togglePaused() |
291 | { | 286 | { |
292 | static bool checked = FALSE; | 287 | static bool checked = FALSE; |
293 | checked = !checked; | 288 | checked = !checked; |
294 | gamePopup->setItemChecked( pauseID, checked ); | 289 | gamePopup->setItemChecked( pauseID, checked ); |
295 | view->score->setPause(gamePopup->isItemChecked(pauseID)); | 290 | view->score->setPause(gamePopup->isItemChecked(pauseID)); |
296 | } | 291 | } |
297 | 292 | ||
298 | /* | 293 | /* |
299 | * This disables the "New Game" menuitem to prevent interruptions of the current | 294 | * This disables the "New Game" menuitem to prevent interruptions of the current |
300 | * play. | 295 | * play. |
301 | */ | 296 | */ |
302 | void Kpacman::toggleNew() | 297 | void Kpacman::toggleNew() |
303 | { | 298 | { |
304 | gamePopup->setItemEnabled(newID, !gamePopup->isItemEnabled(newID)); | 299 | gamePopup->setItemEnabled(newID, !gamePopup->isItemEnabled(newID)); |
305 | } | 300 | } |
306 | 301 | ||
307 | void Kpacman::toggleHideMouseCursor() | 302 | void Kpacman::toggleHideMouseCursor() |
308 | { | 303 | { |
309 | hideMouseCursor = !hideMouseCursor; | 304 | hideMouseCursor = !hideMouseCursor; |
310 | optionsPopup->setItemChecked(hideMouseCursorID, hideMouseCursor); | 305 | optionsPopup->setItemChecked(hideMouseCursorID, hideMouseCursor); |
311 | if (hideMouseCursor) | 306 | if (hideMouseCursor) |
312 | view->setCursor(blankCursor); | 307 | view->setCursor(blankCursor); |
313 | else | 308 | else |
314 | view->setCursor(arrowCursor); | 309 | view->setCursor(arrowCursor); |
315 | } | 310 | } |
316 | 311 | ||
317 | void Kpacman::toggleFocusOutPause() | 312 | void Kpacman::toggleFocusOutPause() |
318 | { | 313 | { |
319 | focusOutPause = !focusOutPause; | 314 | focusOutPause = !focusOutPause; |
320 | optionsPopup->setItemChecked(focusOutPauseID, focusOutPause); | 315 | optionsPopup->setItemChecked(focusOutPauseID, focusOutPause); |
321 | view->referee->setFocusOutPause(focusOutPause); | 316 | view->referee->setFocusOutPause(focusOutPause); |
322 | } | 317 | } |
323 | 318 | ||
324 | void Kpacman::toggleFocusInContinue() | 319 | void Kpacman::toggleFocusInContinue() |
325 | { | 320 | { |
326 | focusInContinue = !focusInContinue; | 321 | focusInContinue = !focusInContinue; |
327 | optionsPopup->setItemChecked(focusInContinueID, focusInContinue); | 322 | optionsPopup->setItemChecked(focusInContinueID, focusInContinue); |
328 | view->referee->setFocusInContinue(focusInContinue); | 323 | view->referee->setFocusInContinue(focusInContinue); |
329 | } | 324 | } |
diff --git a/noncore/games/kpacman/kpacman.h b/noncore/games/kpacman/kpacman.h index d7de9de..2c1de70 100644 --- a/noncore/games/kpacman/kpacman.h +++ b/noncore/games/kpacman/kpacman.h | |||
@@ -1,95 +1,83 @@ | |||
1 | #ifndef KPACMAN_H | 1 | #ifndef KPACMAN_H |
2 | #define KPACMAN_H | 2 | #define KPACMAN_H |
3 | 3 | ||
4 | #ifdef HAVE_CONFIG_H | 4 | #ifdef HAVE_CONFIG_H |
5 | #include <config.h> | 5 | #include <config.h> |
6 | #endif | 6 | #endif |
7 | 7 | ||
8 | #include "portable.h" | 8 | #include "portable.h" |
9 | 9 | ||
10 | #if defined( KDE2_PORT ) | ||
11 | #include <kapp.h> | ||
12 | #include <klocale.h> | ||
13 | #include <ktmainwindow.h> | ||
14 | #include <kmenubar.h> | ||
15 | #elif defined( QPE_PORT ) | ||
16 | #include <qmainwindow.h> | 10 | #include <qmainwindow.h> |
17 | class QMenuBar; | 11 | class QMenuBar; |
18 | #endif | ||
19 | |||
20 | #include <qregexp.h> | 12 | #include <qregexp.h> |
21 | 13 | ||
22 | #include "kpacmanwidget.h" | 14 | #include "kpacmanwidget.h" |
23 | 15 | ||
24 | #include <qpopmenu.h> | 16 | #include <qpopmenu.h> |
25 | 17 | ||
26 | #include <qlist.h> | 18 | #include <qlist.h> |
27 | #include <qfileinf.h> | 19 | #include <qfileinf.h> |
20 | #include <qlayout.h> | ||
28 | 21 | ||
29 | #if defined( KDE2_PORT ) | ||
30 | #include <referee.h> | ||
31 | #include <status.h> | ||
32 | #include <score.h> | ||
33 | #include <keys.h> | ||
34 | #elif defined( QPE_PORT ) | ||
35 | #include "referee.h" | 22 | #include "referee.h" |
36 | #include "status.h" | 23 | #include "status.h" |
37 | #include "score.h" | 24 | #include "score.h" |
38 | #include "keys.h" | 25 | #include "keys.h" |
39 | #endif | ||
40 | 26 | ||
41 | class Kpacman : public KTMainWindow | 27 | class Kpacman : public KTMainWindow |
42 | { | 28 | { |
43 | Q_OBJECT | 29 | Q_OBJECT |
44 | public: | 30 | public: |
45 | Kpacman(QWidget *parent = 0, const char *name = 0); | 31 | Kpacman(QWidget *parent = 0, const char *name = 0); |
46 | virtual ~Kpacman(); | 32 | virtual ~Kpacman(); |
47 | 33 | ||
48 | public slots: | 34 | public slots: |
49 | void forcedHallOfFame(bool); | 35 | void forcedHallOfFame(bool); |
50 | 36 | ||
51 | private slots: | 37 | private slots: |
52 | void newKpacman(); | 38 | void newKpacman(); |
53 | void pauseKpacman(); | 39 | void pauseKpacman(); |
54 | void toggleHallOfFame(); | 40 | void toggleHallOfFame(); |
55 | void toggleNew(); | 41 | void toggleNew(); |
56 | void togglePaused(); | 42 | void togglePaused(); |
57 | void quitKpacman(); | 43 | void quitKpacman(); |
58 | 44 | ||
59 | void schemeChecked(int); | 45 | void schemeChecked(int); |
60 | void toggleFocusOutPause(); | 46 | void toggleFocusOutPause(); |
61 | void toggleFocusInContinue(); | 47 | void toggleFocusInContinue(); |
62 | void toggleHideMouseCursor(); | 48 | void toggleHideMouseCursor(); |
63 | void confKeys(); | 49 | void confKeys(); |
64 | 50 | ||
65 | protected: | 51 | protected: |
66 | 52 | ||
67 | private: | 53 | private: |
68 | KpacmanWidget *view; | 54 | KpacmanWidget *view; |
69 | 55 | ||
70 | void menu(); | 56 | void menu(); |
71 | 57 | ||
72 | int lookupSchemes(); | 58 | int lookupSchemes(); |
73 | 59 | ||
60 | QGridLayout *m_layout; | ||
61 | QWidget *m_view; | ||
74 | KMenuBar *_menuBar; | 62 | KMenuBar *_menuBar; |
75 | QPopupMenu *gamePopup; | 63 | QPopupMenu *gamePopup; |
76 | QPopupMenu *optionsPopup; | 64 | QPopupMenu *optionsPopup; |
77 | QPopupMenu *modesPopup; | 65 | QPopupMenu *modesPopup; |
78 | QList<QPopupMenu> *schemesPopup; | 66 | QList<QPopupMenu> *schemesPopup; |
79 | 67 | ||
80 | int newID; | 68 | int newID; |
81 | int pauseID; | 69 | int pauseID; |
82 | int hofID; | 70 | int hofID; |
83 | QArray<int> modeID; | 71 | QArray<int> modeID; |
84 | QArray<int> schemeID; | 72 | QArray<int> schemeID; |
85 | QArray<int> schemeMode; | 73 | QArray<int> schemeMode; |
86 | int focusOutPauseID; | 74 | int focusOutPauseID; |
87 | int focusInContinueID; | 75 | int focusInContinueID; |
88 | int hideMouseCursorID; | 76 | int hideMouseCursorID; |
89 | 77 | ||
90 | bool focusOutPause; | 78 | bool focusOutPause; |
91 | bool focusInContinue; | 79 | bool focusInContinue; |
92 | bool hideMouseCursor; | 80 | bool hideMouseCursor; |
93 | }; | 81 | }; |
94 | 82 | ||
95 | #endif // KPACMAN_H | 83 | #endif // KPACMAN_H |
diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp index 215dcda..feb782c 100644 --- a/noncore/games/kpacman/kpacmanwidget.cpp +++ b/noncore/games/kpacman/kpacmanwidget.cpp | |||
@@ -1,162 +1,153 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <kapp.h> | 5 | #include <kapp.h> |
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kstddirs.h> | 7 | #include <kstddirs.h> |
8 | #include <kpacmanwidget.h> | 8 | #include <kpacmanwidget.h> |
9 | #include <kpacmanwidget.moc> | 9 | #include <kpacmanwidget.moc> |
10 | #elif defined( QPE_PORT ) | 10 | #elif defined( QPE_PORT ) |
11 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
12 | #include "config.h" | 12 | #include "config.h" |
13 | #include "kpacmanwidget.h" | 13 | #include "kpacmanwidget.h" |
14 | #endif | 14 | #endif |
15 | 15 | ||
16 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
17 | 17 | ||
18 | #include "bitfont.h" | 18 | #include "bitfont.h" |
19 | #include "score.h" | 19 | #include "score.h" |
20 | #include "referee.h" | 20 | #include "referee.h" |
21 | #include "status.h" | 21 | #include "status.h" |
22 | 22 | ||
23 | KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) | 23 | KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name) |
24 | : QWidget( parent, name ) | 24 | : QWidget( parent, name ) |
25 | { | 25 | { |
26 | bitfont = NULL; | 26 | bitfont = NULL; |
27 | fontName = ""; | 27 | fontName = ""; |
28 | 28 | ||
29 | scheme = mode = -1; | 29 | scheme = mode = -1; |
30 | confScheme(); | 30 | confScheme(); |
31 | 31 | ||
32 | score = new Score(this, name, scheme, mode, bitfont); | 32 | score = new Score(this, name, scheme, mode, bitfont); |
33 | referee = new Referee( this, name, scheme, mode, bitfont); | 33 | referee = new Referee( this, name, scheme, mode, bitfont); |
34 | status = new Status(this, name, scheme, mode); | 34 | status = new Status(this, name, scheme, mode); |
35 | 35 | ||
36 | #ifndef QWS | ||
37 | setFixedSize(referee->width(), bitfont->height()*3 + referee->height() + status->height()); | ||
38 | #else | ||
39 | setBackgroundColor( black ); | 36 | setBackgroundColor( black ); |
40 | #endif | ||
41 | } | 37 | } |
42 | 38 | ||
43 | KpacmanWidget::~KpacmanWidget() | 39 | KpacmanWidget::~KpacmanWidget() |
44 | { | 40 | { |
45 | } | 41 | } |
46 | 42 | ||
47 | void KpacmanWidget::confMisc(bool defGroup) | 43 | void KpacmanWidget::confMisc(bool defGroup) |
48 | { | 44 | { |
49 | APP_CONFIG_BEGIN( cfg ); | 45 | APP_CONFIG_BEGIN( cfg ); |
50 | //KStandardDirs *dirs = KGlobal::dirs(); | 46 | //KStandardDirs *dirs = KGlobal::dirs(); |
51 | QString findPath; | 47 | QString findPath; |
52 | 48 | ||
53 | if (defGroup || cfg->hasKey("Font")) { | 49 | if (defGroup || cfg->hasKey("Font")) { |
54 | fontName = cfg->readEntry("Font"); | 50 | fontName = cfg->readEntry("Font"); |
55 | 51 | ||
56 | if (fontName.left(1) != "/" && fontName.left(1) != "~") | 52 | if (fontName.left(1) != "/" && fontName.left(1) != "~") |
57 | fontName.insert(0, "fonts/"); | 53 | fontName.insert(0, "fonts/"); |
58 | if (fontName.right(1) == "/") | 54 | if (fontName.right(1) == "/") |
59 | fontName.append("font.xbm"); | 55 | fontName.append("font.xbm"); |
60 | 56 | ||
61 | //findPath = dirs->findResource("appdata", fontName); | 57 | //findPath = dirs->findResource("appdata", fontName); |
62 | findPath = FIND_APP_DATA( fontName ); | 58 | findPath = FIND_APP_DATA( fontName ); |
63 | if (!findPath.isEmpty()) | 59 | if (!findPath.isEmpty()) |
64 | fontName = findPath; | 60 | fontName = findPath; |
65 | 61 | ||
66 | bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); | 62 | bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e); |
67 | bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); | 63 | bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f); |
68 | } | 64 | } |
69 | APP_CONFIG_END( cfg ); | 65 | APP_CONFIG_END( cfg ); |
70 | } | 66 | } |
71 | 67 | ||
72 | void KpacmanWidget::confScheme() | 68 | void KpacmanWidget::confScheme() |
73 | { | 69 | { |
74 | APP_CONFIG_BEGIN( cfg ); | 70 | APP_CONFIG_BEGIN( cfg ); |
75 | QString lastFontName = fontName; | 71 | QString lastFontName = fontName; |
76 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 72 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
77 | QString newgroup; | 73 | QString newgroup; |
78 | 74 | ||
79 | // if not set, read mode and scheme from the configfile | 75 | // if not set, read mode and scheme from the configfile |
80 | if (mode == -1 && scheme == -1) { | 76 | if (mode == -1 && scheme == -1) { |
81 | scheme = cfg->readNumEntry("Scheme", -1); | 77 | scheme = cfg->readNumEntry("Scheme", -1); |
82 | mode = cfg->readNumEntry("Mode", -1); | 78 | mode = cfg->readNumEntry("Mode", -1); |
83 | 79 | ||
84 | // if mode is not set in the defGroup-group, lookup the scheme group | 80 | // if mode is not set in the defGroup-group, lookup the scheme group |
85 | if (scheme != -1 || mode == -1) { | 81 | if (scheme != -1 || mode == -1) { |
86 | newgroup.sprintf("Scheme %d", scheme); | 82 | newgroup.sprintf("Scheme %d", scheme); |
87 | cfg->setGroup(newgroup); | 83 | cfg->setGroup(newgroup); |
88 | 84 | ||
89 | mode = cfg->readNumEntry("Mode", -1); | 85 | mode = cfg->readNumEntry("Mode", -1); |
90 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 86 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
91 | } | 87 | } |
92 | } | 88 | } |
93 | 89 | ||
94 | confMisc(); | 90 | confMisc(); |
95 | 91 | ||
96 | if (mode != -1) { | 92 | if (mode != -1) { |
97 | newgroup.sprintf("Mode %d", mode); | 93 | newgroup.sprintf("Mode %d", mode); |
98 | cfg->setGroup(newgroup); | 94 | cfg->setGroup(newgroup); |
99 | 95 | ||
100 | confMisc(FALSE); | 96 | confMisc(FALSE); |
101 | } | 97 | } |
102 | 98 | ||
103 | if (scheme != -1) { | 99 | if (scheme != -1) { |
104 | newgroup.sprintf("Scheme %d", scheme); | 100 | newgroup.sprintf("Scheme %d", scheme); |
105 | cfg->setGroup(newgroup); | 101 | cfg->setGroup(newgroup); |
106 | 102 | ||
107 | confMisc(FALSE); | 103 | confMisc(FALSE); |
108 | } | 104 | } |
109 | 105 | ||
110 | if (lastFontName != fontName) { | 106 | if (lastFontName != fontName) { |
111 | 107 | ||
112 | if (bitfont != 0) | 108 | if (bitfont != 0) |
113 | delete bitfont; | 109 | delete bitfont; |
114 | 110 | ||
115 | bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); | 111 | bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar); |
116 | if (bitfont->width() == 0 || bitfont->height() == 0) { | 112 | if (bitfont->width() == 0 || bitfont->height() == 0) { |
117 | QString msg = tr("The bitfont could not be contructed.\n\n" | 113 | QString msg = tr("The bitfont could not be contructed.\n\n" |
118 | "The file '@FONTNAME@' does not exist,\n" | 114 | "The file '@FONTNAME@' does not exist,\n" |
119 | "or is of an unknown format."); | 115 | "or is of an unknown format."); |
120 | msg.replace(QRegExp("@FONTNAME@"), fontName); | 116 | msg.replace(QRegExp("@FONTNAME@"), fontName); |
121 | // QMessageBox::critical(this, tr("Initialization Error"), msg); | 117 | // QMessageBox::critical(this, tr("Initialization Error"), msg); |
122 | printf("%s\n", msg.data()); | 118 | printf("%s\n", msg.data()); |
123 | } | 119 | } |
124 | } | 120 | } |
125 | 121 | ||
126 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 122 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
127 | APP_CONFIG_END( cfg ); | 123 | APP_CONFIG_END( cfg ); |
128 | } | 124 | } |
129 | 125 | ||
130 | void KpacmanWidget::setScheme(int Scheme, int Mode) | 126 | void KpacmanWidget::setScheme(int Scheme, int Mode) |
131 | { | 127 | { |
132 | mode = Mode; | 128 | mode = Mode; |
133 | scheme = Scheme; | 129 | scheme = Scheme; |
134 | 130 | ||
135 | confScheme(); | 131 | confScheme(); |
136 | 132 | ||
137 | score->setScheme(Scheme, Mode, bitfont); | 133 | score->setScheme(Scheme, Mode, bitfont); |
138 | referee->setScheme(Scheme, Mode, bitfont); | 134 | referee->setScheme(Scheme, Mode, bitfont); |
139 | status->setScheme(Scheme, Mode); | 135 | status->setScheme(Scheme, Mode); |
140 | 136 | ||
141 | #ifndef QWS | ||
142 | setFixedSize(referee->width(), | ||
143 | bitfont->height()*3 + referee->height() + status->height()); | ||
144 | #endif | ||
145 | |||
146 | score->repaint(FALSE); | 137 | score->repaint(FALSE); |
147 | referee->repaint(FALSE); | 138 | referee->repaint(FALSE); |
148 | status->repaint(FALSE); | 139 | status->repaint(FALSE); |
149 | } | 140 | } |
150 | 141 | ||
151 | void KpacmanWidget::resizeEvent( QResizeEvent * ) | 142 | void KpacmanWidget::resizeEvent( QResizeEvent * ) |
152 | { | 143 | { |
153 | referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); | 144 | referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); |
154 | referee->setBackgroundColor(BLACK); | 145 | referee->setBackgroundColor(BLACK); |
155 | 146 | ||
156 | status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), | 147 | status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(), |
157 | status->height()); | 148 | status->height()); |
158 | status->setBackgroundColor(BLACK); | 149 | status->setBackgroundColor(BLACK); |
159 | 150 | ||
160 | score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height()); | 151 | score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height()); |
161 | score->setBackgroundColor(BLACK); | 152 | score->setBackgroundColor(BLACK); |
162 | } | 153 | } |
diff --git a/noncore/games/kpacman/referee.cpp b/noncore/games/kpacman/referee.cpp index 70916f0..81f331b 100644 --- a/noncore/games/kpacman/referee.cpp +++ b/noncore/games/kpacman/referee.cpp | |||
@@ -478,516 +478,516 @@ void Referee::fillStrList(QStrList &list, QString values, int max) | |||
478 | } | 478 | } |
479 | if (values.find(',') >= 0) { | 479 | if (values.find(',') >= 0) { |
480 | value = values.left(values.find(',')); | 480 | value = values.left(values.find(',')); |
481 | values.remove(0,values.find(',')+1); | 481 | values.remove(0,values.find(',')+1); |
482 | } | 482 | } |
483 | if (!value.isEmpty()) | 483 | if (!value.isEmpty()) |
484 | last = value; | 484 | last = value; |
485 | 485 | ||
486 | list.append(last); | 486 | list.append(last); |
487 | } | 487 | } |
488 | } | 488 | } |
489 | 489 | ||
490 | void Referee::fillMapName() | 490 | void Referee::fillMapName() |
491 | { | 491 | { |
492 | QStrList list = mapName; | 492 | QStrList list = mapName; |
493 | 493 | ||
494 | if (!mapName.isEmpty()) | 494 | if (!mapName.isEmpty()) |
495 | mapName.clear(); | 495 | mapName.clear(); |
496 | 496 | ||
497 | QString map; | 497 | QString map; |
498 | 498 | ||
499 | QFileInfo fileInfo; | 499 | QFileInfo fileInfo; |
500 | 500 | ||
501 | for (uint i = 0; i < list.count(); i++) { | 501 | for (uint i = 0; i < list.count(); i++) { |
502 | map = list.at(i); | 502 | map = list.at(i); |
503 | 503 | ||
504 | if (map.left(1) != "/" && map.left(1) != "~") | 504 | if (map.left(1) != "/" && map.left(1) != "~") |
505 | map = FIND_APP_DATA( mapDirectory+map ); | 505 | map = FIND_APP_DATA( mapDirectory+map ); |
506 | 506 | ||
507 | fileInfo.setFile(map); | 507 | fileInfo.setFile(map); |
508 | if (!fileInfo.isReadable()) | 508 | if (!fileInfo.isReadable()) |
509 | map = ""; | 509 | map = ""; |
510 | 510 | ||
511 | mapName.append(map); | 511 | mapName.append(map); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | 514 | ||
515 | void Referee::confLevels(bool defGroup) | 515 | void Referee::confLevels(bool defGroup) |
516 | { | 516 | { |
517 | APP_CONFIG_BEGIN( cfg ); | 517 | APP_CONFIG_BEGIN( cfg ); |
518 | if (defGroup || cfg->hasKey("Levels")) | 518 | if (defGroup || cfg->hasKey("Levels")) |
519 | maxLevel = cfg->readNumEntry("Levels", 13); | 519 | maxLevel = cfg->readNumEntry("Levels", 13); |
520 | APP_CONFIG_END( cfg ); | 520 | APP_CONFIG_END( cfg ); |
521 | } | 521 | } |
522 | 522 | ||
523 | void Referee::confMisc(bool defGroup) | 523 | void Referee::confMisc(bool defGroup) |
524 | { | 524 | { |
525 | APP_CONFIG_BEGIN( cfg ); | 525 | APP_CONFIG_BEGIN( cfg ); |
526 | if (defGroup || cfg->hasKey("PixmapDirectory")) { | 526 | if (defGroup || cfg->hasKey("PixmapDirectory")) { |
527 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); | 527 | pixmapDirectory = cfg->readEntry("PixmapDirectory"); |
528 | 528 | ||
529 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") | 529 | if (pixmapDirectory.left(1) != "/" && pixmapDirectory.left(1) != "~") |
530 | pixmapDirectory.insert(0, "pics/"); | 530 | pixmapDirectory.insert(0, "pics/"); |
531 | if (pixmapDirectory.right(1) != "/") | 531 | if (pixmapDirectory.right(1) != "/") |
532 | pixmapDirectory.append("/"); | 532 | pixmapDirectory.append("/"); |
533 | } | 533 | } |
534 | 534 | ||
535 | if (defGroup || cfg->hasKey("MapDirectory")) { | 535 | if (defGroup || cfg->hasKey("MapDirectory")) { |
536 | mapDirectory = cfg->readEntry("MapDirectory"); | 536 | mapDirectory = cfg->readEntry("MapDirectory"); |
537 | 537 | ||
538 | if (mapDirectory.left(1) != "/" && mapDirectory.left(1) != "~") | 538 | if (mapDirectory.left(1) != "/" && mapDirectory.left(1) != "~") |
539 | mapDirectory.insert(0, "maps/"); | 539 | mapDirectory.insert(0, "maps/"); |
540 | if (mapDirectory.right(1) != "/") | 540 | if (mapDirectory.right(1) != "/") |
541 | mapDirectory.append("/"); | 541 | mapDirectory.append("/"); |
542 | } | 542 | } |
543 | 543 | ||
544 | if (defGroup || cfg->hasKey("MapName")) | 544 | if (defGroup || cfg->hasKey("MapName")) |
545 | fillStrList(mapName, cfg->readEntry("MapName", "map"), maxLevel+1); | 545 | fillStrList(mapName, cfg->readEntry("MapName", "map"), maxLevel+1); |
546 | 546 | ||
547 | if (defGroup || cfg->hasKey("MonsterIQ")) | 547 | if (defGroup || cfg->hasKey("MonsterIQ")) |
548 | fillArray(monsterIQ, cfg->readEntry("MonsterIQ", "0,170,180,170,180,170,180"), maxLevel+1); | 548 | fillArray(monsterIQ, cfg->readEntry("MonsterIQ", "0,170,180,170,180,170,180"), maxLevel+1); |
549 | if (defGroup || cfg->hasKey("FruitIQ")) | 549 | if (defGroup || cfg->hasKey("FruitIQ")) |
550 | fillArray(fruitIQ, cfg->readEntry("FruitIQ", "0,170,180,170,180,170,180"), maxLevel+1); | 550 | fillArray(fruitIQ, cfg->readEntry("FruitIQ", "0,170,180,170,180,170,180"), maxLevel+1); |
551 | if (defGroup || cfg->hasKey("FruitIndex")) | 551 | if (defGroup || cfg->hasKey("FruitIndex")) |
552 | fillArray(fruitIndex, cfg->readEntry("FruitIndex", "0"), maxLevel+1); | 552 | fillArray(fruitIndex, cfg->readEntry("FruitIndex", "0"), maxLevel+1); |
553 | APP_CONFIG_END( cfg ); | 553 | APP_CONFIG_END( cfg ); |
554 | } | 554 | } |
555 | 555 | ||
556 | void Referee::confTiming(bool defGroup) | 556 | void Referee::confTiming(bool defGroup) |
557 | { | 557 | { |
558 | APP_CONFIG_BEGIN( cfg ); | 558 | APP_CONFIG_BEGIN( cfg ); |
559 | if (defGroup || cfg->hasKey("SpeedMS")) | 559 | if (defGroup || cfg->hasKey("SpeedMS")) |
560 | fillArray(speed, cfg->readEntry("SpeedMS", "20"), maxLevel+1); | 560 | fillArray(speed, cfg->readEntry("SpeedMS", "20"), maxLevel+1); |
561 | if (defGroup || cfg->hasKey("PacmanTicks")) | 561 | if (defGroup || cfg->hasKey("PacmanTicks")) |
562 | fillArray(pacmanTicks,cfg->readEntry("PacmanTicks", "3"), maxLevel+1); | 562 | fillArray(pacmanTicks,cfg->readEntry("PacmanTicks", "3"), maxLevel+1); |
563 | if (defGroup || cfg->hasKey("RemTicks")) | 563 | if (defGroup || cfg->hasKey("RemTicks")) |
564 | fillArray(remTicks, cfg->readEntry("RemTicks", "1"), maxLevel+1); | 564 | fillArray(remTicks, cfg->readEntry("RemTicks", "1"), maxLevel+1); |
565 | if (defGroup || cfg->hasKey("DangerousTicks")) | 565 | if (defGroup || cfg->hasKey("DangerousTicks")) |
566 | fillArray(dangerousTicks, cfg->readEntry("DangerousTicks", "3"), maxLevel+1); | 566 | fillArray(dangerousTicks, cfg->readEntry("DangerousTicks", "3"), maxLevel+1); |
567 | if (defGroup || cfg->hasKey("HarmlessTicks")) | 567 | if (defGroup || cfg->hasKey("HarmlessTicks")) |
568 | fillArray(harmlessTicks, cfg->readEntry("HarmlessTicks", "7,6,,5,,4"), maxLevel+1); | 568 | fillArray(harmlessTicks, cfg->readEntry("HarmlessTicks", "7,6,,5,,4"), maxLevel+1); |
569 | if (defGroup || cfg->hasKey("HarmlessDurationTicks")) | 569 | if (defGroup || cfg->hasKey("HarmlessDurationTicks")) |
570 | fillArray(harmlessDurTicks, cfg->readEntry("HarmlessDurationTicks", "375,,,300,,250,200,150"), maxLevel+1); | 570 | fillArray(harmlessDurTicks, cfg->readEntry("HarmlessDurationTicks", "375,,,300,,250,200,150"), maxLevel+1); |
571 | if (defGroup || cfg->hasKey("HarmlessWarningTicks")) | 571 | if (defGroup || cfg->hasKey("HarmlessWarningTicks")) |
572 | fillArray(harmlessWarnTicks, cfg->readEntry("HarmlessWarningTicks", "135"), maxLevel+1); | 572 | fillArray(harmlessWarnTicks, cfg->readEntry("HarmlessWarningTicks", "135"), maxLevel+1); |
573 | if (defGroup || cfg->hasKey("ArrestTicks")) | 573 | if (defGroup || cfg->hasKey("ArrestTicks")) |
574 | fillArray(arrestTicks, cfg->readEntry("ArrestTicks", "6"), maxLevel+1); | 574 | fillArray(arrestTicks, cfg->readEntry("ArrestTicks", "6"), maxLevel+1); |
575 | if (defGroup || cfg->hasKey("ArrestDurationTicks")) | 575 | if (defGroup || cfg->hasKey("ArrestDurationTicks")) |
576 | fillArray(arrestDurTicks, cfg->readEntry("ArrestDurationTicks", "200,,,150"), maxLevel+1); | 576 | fillArray(arrestDurTicks, cfg->readEntry("ArrestDurationTicks", "200,,,150"), maxLevel+1); |
577 | if (defGroup || cfg->hasKey("FruitTicks")) | 577 | if (defGroup || cfg->hasKey("FruitTicks")) |
578 | fillArray(fruitTicks, cfg->readEntry("FruitTicks", "7,6,,5,,4"), maxLevel+1); | 578 | fillArray(fruitTicks, cfg->readEntry("FruitTicks", "7,6,,5,,4"), maxLevel+1); |
579 | if (defGroup || cfg->hasKey("FruitAppearsTicks")) | 579 | if (defGroup || cfg->hasKey("FruitAppearsTicks")) |
580 | fillArray(fruitAppearsTicks, cfg->readEntry("FruitAppearsTicks", "1000,,1500,2000,2500,3000,3500,4000"), maxLevel+1); | 580 | fillArray(fruitAppearsTicks, cfg->readEntry("FruitAppearsTicks", "1000,,1500,2000,2500,3000,3500,4000"), maxLevel+1); |
581 | if (defGroup || cfg->hasKey("FruitDurationTicks")) | 581 | if (defGroup || cfg->hasKey("FruitDurationTicks")) |
582 | fillArray(fruitDurTicks, cfg->readEntry("FruitDurationTicks", "500,,,400,350,300,,250,200,150"), maxLevel+1); | 582 | fillArray(fruitDurTicks, cfg->readEntry("FruitDurationTicks", "500,,,400,350,300,,250,200,150"), maxLevel+1); |
583 | if (defGroup || cfg->hasKey("FruitScoreDurationTicks")) | 583 | if (defGroup || cfg->hasKey("FruitScoreDurationTicks")) |
584 | fillArray(fruitScoreDurTicks, cfg->readEntry("FruitScoreDurationTicks", "150"), maxLevel+1); | 584 | fillArray(fruitScoreDurTicks, cfg->readEntry("FruitScoreDurationTicks", "150"), maxLevel+1); |
585 | 585 | ||
586 | if (defGroup || cfg->hasKey("MonsterScoreDurationMS")) | 586 | if (defGroup || cfg->hasKey("MonsterScoreDurationMS")) |
587 | monsterScoreDurMS = cfg->readNumEntry("MonsterScoreDurationMS", 1000); | 587 | monsterScoreDurMS = cfg->readNumEntry("MonsterScoreDurationMS", 1000); |
588 | if (defGroup || cfg->hasKey("PlayerDurationMS")) | 588 | if (defGroup || cfg->hasKey("PlayerDurationMS")) |
589 | playerDurMS = cfg->readNumEntry("PlayerDurationMS", 3000); | 589 | playerDurMS = cfg->readNumEntry("PlayerDurationMS", 3000); |
590 | if (defGroup || cfg->hasKey("ReadyDurationMS")) | 590 | if (defGroup || cfg->hasKey("ReadyDurationMS")) |
591 | readyDurMS = cfg->readNumEntry("ReadyDurationMS", 2000); | 591 | readyDurMS = cfg->readNumEntry("ReadyDurationMS", 2000); |
592 | if (defGroup || cfg->hasKey("GameOverDurationMS")) | 592 | if (defGroup || cfg->hasKey("GameOverDurationMS")) |
593 | gameOverDurMS = cfg->readNumEntry("GameOverDurationMS", 3000); | 593 | gameOverDurMS = cfg->readNumEntry("GameOverDurationMS", 3000); |
594 | if (defGroup || cfg->hasKey("AfterPauseMS")) | 594 | if (defGroup || cfg->hasKey("AfterPauseMS")) |
595 | afterPauseMS = cfg->readNumEntry("AfterPauseMS", 1000); | 595 | afterPauseMS = cfg->readNumEntry("AfterPauseMS", 1000); |
596 | if (defGroup || cfg->hasKey("DyingPreAnimationMS")) | 596 | if (defGroup || cfg->hasKey("DyingPreAnimationMS")) |
597 | dyingPreAnimationMS = cfg->readNumEntry("DyingPreAnimationMS", 1000); | 597 | dyingPreAnimationMS = cfg->readNumEntry("DyingPreAnimationMS", 1000); |
598 | if (defGroup || cfg->hasKey("DyingAnimationMS")) | 598 | if (defGroup || cfg->hasKey("DyingAnimationMS")) |
599 | dyingAnimationMS = cfg->readNumEntry("DyingAnimationMS", 100); | 599 | dyingAnimationMS = cfg->readNumEntry("DyingAnimationMS", 100); |
600 | if (defGroup || cfg->hasKey("DyingPostAnimationMS")) | 600 | if (defGroup || cfg->hasKey("DyingPostAnimationMS")) |
601 | dyingPostAnimationMS = cfg->readNumEntry("DyingPostAnimationMS", 500); | 601 | dyingPostAnimationMS = cfg->readNumEntry("DyingPostAnimationMS", 500); |
602 | if (defGroup || cfg->hasKey("IntroAnimationMS")) | 602 | if (defGroup || cfg->hasKey("IntroAnimationMS")) |
603 | introAnimationMS = cfg->readNumEntry("IntroAnimationMS", 800); | 603 | introAnimationMS = cfg->readNumEntry("IntroAnimationMS", 800); |
604 | if (defGroup || cfg->hasKey("IntroPostAnimationMS")) | 604 | if (defGroup || cfg->hasKey("IntroPostAnimationMS")) |
605 | introPostAnimationMS = cfg->readNumEntry("IntroPostAnimationMS", 1000); | 605 | introPostAnimationMS = cfg->readNumEntry("IntroPostAnimationMS", 1000); |
606 | if (defGroup || cfg->hasKey("LevelUpPreAnimationMS")) | 606 | if (defGroup || cfg->hasKey("LevelUpPreAnimationMS")) |
607 | levelUpPreAnimationMS = cfg->readNumEntry("LevelUpPreAnimationMS", 2000); | 607 | levelUpPreAnimationMS = cfg->readNumEntry("LevelUpPreAnimationMS", 2000); |
608 | if (defGroup || cfg->hasKey("LevelUpAnimationMS")) | 608 | if (defGroup || cfg->hasKey("LevelUpAnimationMS")) |
609 | levelUpAnimationMS = cfg->readNumEntry("LevelUpAnimationMS", 2000); | 609 | levelUpAnimationMS = cfg->readNumEntry("LevelUpAnimationMS", 2000); |
610 | if (defGroup || cfg->hasKey("EnergizerAnimationMS")) | 610 | if (defGroup || cfg->hasKey("EnergizerAnimationMS")) |
611 | energizerAnimationMS = cfg->readNumEntry("EnergizerAnimationMS", 200); | 611 | energizerAnimationMS = cfg->readNumEntry("EnergizerAnimationMS", 200); |
612 | APP_CONFIG_END( cfg ); | 612 | APP_CONFIG_END( cfg ); |
613 | } | 613 | } |
614 | 614 | ||
615 | void Referee::confScoring(bool defGroup) | 615 | void Referee::confScoring(bool defGroup) |
616 | { | 616 | { |
617 | APP_CONFIG_BEGIN( cfg ); | 617 | APP_CONFIG_BEGIN( cfg ); |
618 | if (defGroup || cfg->hasKey("PointScore")) | 618 | if (defGroup || cfg->hasKey("PointScore")) |
619 | pointScore = cfg->readNumEntry("PointScore", 10); | 619 | pointScore = cfg->readNumEntry("PointScore", 10); |
620 | if (defGroup || cfg->hasKey("EnergizerScore")) | 620 | if (defGroup || cfg->hasKey("EnergizerScore")) |
621 | energizerScore = cfg->readNumEntry("EnergizerScore", 50); | 621 | energizerScore = cfg->readNumEntry("EnergizerScore", 50); |
622 | if (defGroup || cfg->hasKey("FruitScore")) | 622 | if (defGroup || cfg->hasKey("FruitScore")) |
623 | fillArray(fruitScore, cfg->readEntry("FruitScore", "100,300,500,,700,,1000,,2000,,3000,,5000"), maxLevel+1); | 623 | fillArray(fruitScore, cfg->readEntry("FruitScore", "100,300,500,,700,,1000,,2000,,3000,,5000"), maxLevel+1); |
624 | if (defGroup || cfg->hasKey("MonsterScore")) | 624 | if (defGroup || cfg->hasKey("MonsterScore")) |
625 | fillArray(monsterScore, cfg->readEntry("MonsterScore", "200,400,800,1600"), 4); | 625 | fillArray(monsterScore, cfg->readEntry("MonsterScore", "200,400,800,1600"), 4); |
626 | if (defGroup || cfg->hasKey("ExtraLifeScore")) | 626 | if (defGroup || cfg->hasKey("ExtraLifeScore")) |
627 | fillArray(extraLifeScore, cfg->readEntry("ExtraLifeScore", "10000"), -1); | 627 | fillArray(extraLifeScore, cfg->readEntry("ExtraLifeScore", "10000"), -1); |
628 | APP_CONFIG_END( cfg ); | 628 | APP_CONFIG_END( cfg ); |
629 | } | 629 | } |
630 | 630 | ||
631 | void Referee::confScheme() | 631 | void Referee::confScheme() |
632 | { | 632 | { |
633 | APP_CONFIG_BEGIN( cfg ); | 633 | APP_CONFIG_BEGIN( cfg ); |
634 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 634 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
635 | QString newgroup; | 635 | QString newgroup; |
636 | 636 | ||
637 | // if not set, read mode and scheme from the configfile | 637 | // if not set, read mode and scheme from the configfile |
638 | if (mode == -1 && scheme == -1) { | 638 | if (mode == -1 && scheme == -1) { |
639 | scheme = cfg->readNumEntry("Scheme", -1); | 639 | scheme = cfg->readNumEntry("Scheme", -1); |
640 | mode = cfg->readNumEntry("Mode", -1); | 640 | mode = cfg->readNumEntry("Mode", -1); |
641 | 641 | ||
642 | // if mode is not set in the defGroup-group, lookup the scheme group | 642 | // if mode is not set in the defGroup-group, lookup the scheme group |
643 | if (scheme != -1 || mode == -1) { | 643 | if (scheme != -1 || mode == -1) { |
644 | newgroup.sprintf("Scheme %d", scheme); | 644 | newgroup.sprintf("Scheme %d", scheme); |
645 | cfg->setGroup(newgroup); | 645 | cfg->setGroup(newgroup); |
646 | 646 | ||
647 | mode = cfg->readNumEntry("Mode", -1); | 647 | mode = cfg->readNumEntry("Mode", -1); |
648 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 648 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
649 | } | 649 | } |
650 | } | 650 | } |
651 | 651 | ||
652 | confLevels(); | 652 | confLevels(); |
653 | 653 | ||
654 | if (mode != -1) { | 654 | if (mode != -1) { |
655 | newgroup.sprintf("Mode %d", mode); | 655 | newgroup.sprintf("Mode %d", mode); |
656 | cfg->setGroup(newgroup); | 656 | cfg->setGroup(newgroup); |
657 | 657 | ||
658 | confLevels(FALSE); | 658 | confLevels(FALSE); |
659 | } | 659 | } |
660 | 660 | ||
661 | if (scheme != -1) { | 661 | if (scheme != -1) { |
662 | newgroup.sprintf("Scheme %d", scheme); | 662 | newgroup.sprintf("Scheme %d", scheme); |
663 | cfg->setGroup(newgroup); | 663 | cfg->setGroup(newgroup); |
664 | 664 | ||
665 | confLevels(FALSE); | 665 | confLevels(FALSE); |
666 | } | 666 | } |
667 | 667 | ||
668 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 668 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
669 | 669 | ||
670 | confMisc(); | 670 | confMisc(); |
671 | confTiming(); | 671 | confTiming(); |
672 | confScoring(); | 672 | confScoring(); |
673 | 673 | ||
674 | if (mode != -1) { | 674 | if (mode != -1) { |
675 | newgroup.sprintf("Mode %d", mode); | 675 | newgroup.sprintf("Mode %d", mode); |
676 | cfg->setGroup(newgroup); | 676 | cfg->setGroup(newgroup); |
677 | 677 | ||
678 | confMisc(FALSE); | 678 | confMisc(FALSE); |
679 | confTiming(FALSE); | 679 | confTiming(FALSE); |
680 | confScoring(FALSE); | 680 | confScoring(FALSE); |
681 | } | 681 | } |
682 | 682 | ||
683 | if (scheme != -1) { | 683 | if (scheme != -1) { |
684 | newgroup.sprintf("Scheme %d", scheme); | 684 | newgroup.sprintf("Scheme %d", scheme); |
685 | cfg->setGroup(newgroup); | 685 | cfg->setGroup(newgroup); |
686 | 686 | ||
687 | confMisc(FALSE); | 687 | confMisc(FALSE); |
688 | confTiming(FALSE); | 688 | confTiming(FALSE); |
689 | confScoring(FALSE); | 689 | confScoring(FALSE); |
690 | } | 690 | } |
691 | 691 | ||
692 | fillMapName(); | 692 | fillMapName(); |
693 | 693 | ||
694 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 694 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
695 | APP_CONFIG_END( cfg ); | 695 | APP_CONFIG_END( cfg ); |
696 | } | 696 | } |
697 | 697 | ||
698 | void Referee::setScheme(int Scheme, int Mode, Bitfont *font) | 698 | void Referee::setScheme(int Scheme, int Mode, Bitfont *font) |
699 | { | 699 | { |
700 | mode = Mode; | 700 | mode = Mode; |
701 | scheme = Scheme; | 701 | scheme = Scheme; |
702 | 702 | ||
703 | confScheme(); | 703 | confScheme(); |
704 | 704 | ||
705 | pix->setScheme(scheme, mode, font); | 705 | pix->setScheme(scheme, mode, font); |
706 | 706 | ||
707 | pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); | 707 | pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); |
708 | fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); | 708 | fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); |
709 | 709 | ||
710 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 710 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
711 | if (m) | 711 | if (m) |
712 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); | 712 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); |
713 | 713 | ||
714 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) | 714 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) |
715 | if (e) | 715 | if (e) |
716 | e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); | 716 | e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); |
717 | 717 | ||
718 | if (gameState.testBit(Introducing)) | 718 | if (gameState.testBit(Introducing)) |
719 | for (int i = 0; i < (gameState.testBit(Init) ? timerCount : 15); i++) | 719 | for (int i = 0; i < (gameState.testBit(Init) ? timerCount : 15); i++) |
720 | introPaint(i); | 720 | introPaint(i); |
721 | 721 | ||
722 | setFixedSize(pix->levelPix().size()); | 722 | setFixedSize(pix->levelPix().size()); |
723 | repaint(); | 723 | repaint(); |
724 | } | 724 | } |
725 | 725 | ||
726 | void Referee::keyPressEvent( QKeyEvent *k ) | 726 | void Referee::keyPressEvent( QKeyEvent *k ) |
727 | { | 727 | { |
728 | uint key = k->key(); | 728 | uint key = k->key(); |
729 | #ifdef QWS | 729 | #ifdef QWS |
730 | // "OK" => new game | 730 | // "OK" => new game |
731 | if ( key == Key_F33 || key == Key_F2 || key == Key_Enter ) | 731 | if ( key == Key_F33 || key == Key_F2 || key == Key_Enter ) |
732 | play(); | 732 | play(); |
733 | else if ( !gameState.testBit(Playing) && | 733 | else if ( !gameState.testBit(Playing) && |
734 | key == Key_Up || | 734 | ( key == Key_Up || |
735 | key == Key_Down || | 735 | key == Key_Down || |
736 | key == Key_Right || | 736 | key == Key_Right || |
737 | key == Key_Left ) | 737 | key == Key_Left )) |
738 | play(); | 738 | play(); |
739 | // "Space" => pause | 739 | // "Space" => pause |
740 | //else if ( key == Key_Space || key == Key_F3 ) | 740 | //else if ( key == Key_Space || key == Key_F3 ) |
741 | // pause(); | 741 | // pause(); |
742 | // "Menu" => hall of fame | 742 | // "Menu" => hall of fame |
743 | //else if ( key == Key_F11 || key == Key_F4 ) | 743 | //else if ( key == Key_F11 || key == Key_F4 ) |
744 | // toggleHallOfFame(); | 744 | // toggleHallOfFame(); |
745 | #endif | 745 | #endif |
746 | 746 | ||
747 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame) || | 747 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame) || |
748 | gameState.testBit(Demonstration) || gameState.testBit(Dying) || | 748 | gameState.testBit(Demonstration) || gameState.testBit(Dying) || |
749 | gameState.testBit(Ready) || gameState.testBit(LevelDone) || | 749 | gameState.testBit(Ready) || gameState.testBit(LevelDone) || |
750 | !gameState.testBit(Playing)) | 750 | !gameState.testBit(Playing)) |
751 | return; | 751 | return; |
752 | 752 | ||
753 | if (key == UpKey) | 753 | if (key == UpKey) |
754 | pacman->setDirection(N); | 754 | pacman->setDirection(N); |
755 | else if (key == DownKey) | 755 | else if (key == DownKey) |
756 | pacman->setDirection(S); | 756 | pacman->setDirection(S); |
757 | else if (key == RightKey) | 757 | else if (key == RightKey) |
758 | pacman->setDirection(E); | 758 | pacman->setDirection(E); |
759 | else if (key == LeftKey) | 759 | else if (key == LeftKey) |
760 | pacman->setDirection(W); | 760 | pacman->setDirection(W); |
761 | 761 | ||
762 | #ifdef CHEATS | 762 | #ifdef CHEATS |
763 | else if (key == Key_L) { printf("levelUp()\n"); levelUp(); } | 763 | else if (key == Key_L) { printf("levelUp()\n"); levelUp(); } |
764 | else if (key == Key_F) { printf("fruit->move(TRUE)\n"); fruit->move(TRUE); repaint(FALSE); } | 764 | else if (key == Key_F) { printf("fruit->move(TRUE)\n"); fruit->move(TRUE); repaint(FALSE); } |
765 | else if (key == Key_E) { printf("setLifes(++lifes)\n"); emit setLifes(++lifes); } | 765 | else if (key == Key_E) { printf("setLifes(++lifes)\n"); emit setLifes(++lifes); } |
766 | #endif | 766 | #endif |
767 | 767 | ||
768 | else { | 768 | else { |
769 | k->ignore(); | 769 | k->ignore(); |
770 | return; | 770 | return; |
771 | } | 771 | } |
772 | k->accept(); | 772 | k->accept(); |
773 | } | 773 | } |
774 | 774 | ||
775 | void Referee::score(int p) | 775 | void Referee::score(int p) |
776 | { | 776 | { |
777 | if (!gameState.testBit(Playing)) | 777 | if (!gameState.testBit(Playing)) |
778 | return; | 778 | return; |
779 | 779 | ||
780 | if ((points += p) < 0) | 780 | if ((points += p) < 0) |
781 | points = 0; | 781 | points = 0; |
782 | 782 | ||
783 | emit setPoints(points); | 783 | emit setPoints(points); |
784 | 784 | ||
785 | if (points >= nextExtraLifeScore) { | 785 | if (points >= nextExtraLifeScore) { |
786 | emit setLifes(++lifes); | 786 | emit setLifes(++lifes); |
787 | if (extraLifeScoreIndex < (int) extraLifeScore.size()-1) | 787 | if (extraLifeScoreIndex < (int) extraLifeScore.size()-1) |
788 | extraLifeScoreIndex++; | 788 | extraLifeScoreIndex++; |
789 | if (extraLifeScore[extraLifeScoreIndex] < 0) | 789 | if (extraLifeScore[extraLifeScoreIndex] < 0) |
790 | nextExtraLifeScore = extraLifeScore[extraLifeScoreIndex] * -1; | 790 | nextExtraLifeScore = extraLifeScore[extraLifeScoreIndex] * -1; |
791 | else | 791 | else |
792 | nextExtraLifeScore += extraLifeScore[extraLifeScoreIndex]; | 792 | nextExtraLifeScore += extraLifeScore[extraLifeScoreIndex]; |
793 | } | 793 | } |
794 | } | 794 | } |
795 | 795 | ||
796 | void Referee::eaten() | 796 | void Referee::eaten() |
797 | { | 797 | { |
798 | if (gameState.testBit(Ready)) | 798 | if (gameState.testBit(Ready)) |
799 | return; | 799 | return; |
800 | 800 | ||
801 | stop(); | 801 | stop(); |
802 | 802 | ||
803 | if (monstersEaten < 4) | 803 | if (monstersEaten < 4) |
804 | monstersEaten++; | 804 | monstersEaten++; |
805 | 805 | ||
806 | gameState.setBit(Scoring); | 806 | gameState.setBit(Scoring); |
807 | score(monsterScore[monstersEaten-1]); | 807 | score(monsterScore[monstersEaten-1]); |
808 | 808 | ||
809 | repaint(pix->rect(pix->rect(pacman->position(), MonsterPix), | 809 | repaint(pix->rect(pix->rect(pacman->position(), MonsterPix), |
810 | pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))); | 810 | pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))); |
811 | 811 | ||
812 | if (--timerCount > 0) | 812 | if (--timerCount > 0) |
813 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(eaten())); | 813 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(eaten())); |
814 | else { | 814 | else { |
815 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 815 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
816 | if (m && m->direction() == X && !gameState.testBit(Introducing)) | 816 | if (m && m->direction() == X && !gameState.testBit(Introducing)) |
817 | m->setDirection(N); | 817 | m->setDirection(N); |
818 | if (monstersEaten != 4 || !gameState.testBit(Introducing)) | 818 | if (monstersEaten != 4 || !gameState.testBit(Introducing)) |
819 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(start())); | 819 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(start())); |
820 | } | 820 | } |
821 | } | 821 | } |
822 | 822 | ||
823 | void Referee::toggleHallOfFame() | 823 | void Referee::toggleHallOfFame() |
824 | { | 824 | { |
825 | gameState.toggleBit(HallOfFame); | 825 | gameState.toggleBit(HallOfFame); |
826 | } | 826 | } |
827 | 827 | ||
828 | void Referee::hallOfFame() | 828 | void Referee::hallOfFame() |
829 | { | 829 | { |
830 | if (gameState.testBit(HallOfFame)) // If the HallOfFame is switched on manually, toggle the | 830 | if (gameState.testBit(HallOfFame)) // If the HallOfFame is switched on manually, toggle the |
831 | toggleHallOfFame(); // bit twice. | 831 | toggleHallOfFame(); // bit twice. |
832 | 832 | ||
833 | emit setLevel(0); // Clear status display for hall of fame | 833 | emit setLevel(0); // Clear status display for hall of fame |
834 | emit setScore(level, 0); | 834 | emit setScore(level, 0); |
835 | emit forcedHallOfFame(TRUE); | 835 | emit forcedHallOfFame(TRUE); |
836 | } | 836 | } |
837 | 837 | ||
838 | void Referee::pause() | 838 | void Referee::pause() |
839 | { | 839 | { |
840 | static int pausedTimer = 0; | 840 | static int pausedTimer = 0; |
841 | 841 | ||
842 | if (!gameState.testBit(Paused)) { | 842 | if (!gameState.testBit(Paused)) { |
843 | pausedTimer = gameTimer; | 843 | pausedTimer = gameTimer; |
844 | stop(); | 844 | stop(); |
845 | stopEnergizer(); | 845 | stopEnergizer(); |
846 | gameState.setBit(Paused); | 846 | gameState.setBit(Paused); |
847 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); | 847 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); |
848 | } else { | 848 | } else { |
849 | gameState.clearBit(Paused); | 849 | gameState.clearBit(Paused); |
850 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); | 850 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); |
851 | if (pausedTimer) { | 851 | if (pausedTimer) { |
852 | pausedTimer = 0; | 852 | pausedTimer = 0; |
853 | start(); | 853 | start(); |
854 | } | 854 | } |
855 | } | 855 | } |
856 | emit togglePaused(); | 856 | emit togglePaused(); |
857 | } | 857 | } |
858 | 858 | ||
859 | void Referee::intro() | 859 | void Referee::intro() |
860 | { | 860 | { |
861 | stop(); | 861 | stop(); |
862 | stopEnergizer(); | 862 | stopEnergizer(); |
863 | bool paused = gameState.testBit(Paused); | 863 | bool paused = gameState.testBit(Paused); |
864 | 864 | ||
865 | gameState.fill(FALSE); | 865 | gameState.fill(FALSE); |
866 | gameState.setBit(Introducing); | 866 | gameState.setBit(Introducing); |
867 | gameState.setBit(Init); | 867 | gameState.setBit(Init); |
868 | 868 | ||
869 | if (paused) | 869 | if (paused) |
870 | gameState.setBit(Paused); | 870 | gameState.setBit(Paused); |
871 | 871 | ||
872 | level = 0; | 872 | level = 0; |
873 | emit setLevel(level); | 873 | emit setLevel(level); |
874 | 874 | ||
875 | board->init(Intro); | 875 | board->init(Intro); |
876 | pix->setLevel(level); | 876 | pix->setLevel(level); |
877 | 877 | ||
878 | initPacman(); | 878 | initPacman(); |
879 | initFruit(); | 879 | initFruit(); |
880 | initMonsters(); | 880 | initMonsters(); |
881 | initEnergizers(); | 881 | initEnergizers(); |
882 | 882 | ||
883 | repaint(); | 883 | repaint(); |
884 | 884 | ||
885 | monstersEaten = 0; | 885 | monstersEaten = 0; |
886 | timerCount = 0; | 886 | timerCount = 0; |
887 | introPlay(); | 887 | introPlay(); |
888 | } | 888 | } |
889 | 889 | ||
890 | void Referee::introMonster(int id) | 890 | void Referee::introMonster(int id) |
891 | { | 891 | { |
892 | Monster *m = new Monster(board, id); | 892 | Monster *m = new Monster(board, id); |
893 | 893 | ||
894 | m->setPosition((10+id*6)*BoardWidth+10); | 894 | m->setPosition((10+id*6)*BoardWidth+10); |
895 | m->setDirection(E); | 895 | m->setDirection(E); |
896 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); | 896 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); |
897 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); | 897 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); |
898 | 898 | ||
899 | if (m->body() != -1) | 899 | if (m->body() != -1) |
900 | pix->draw(m->position(), RoomPix, MonsterPix, m->body()); | 900 | pix->draw(m->position(), RoomPix, MonsterPix, m->body()); |
901 | if (m->eyes() != -1) | 901 | if (m->eyes() != -1) |
902 | pix->draw(m->position(), RoomPix, EyesPix, m->eyes()); | 902 | pix->draw(m->position(), RoomPix, EyesPix, m->eyes()); |
903 | 903 | ||
904 | repaint(pix->rect(m->position(), MonsterPix), FALSE); | 904 | repaint(pix->rect(m->position(), MonsterPix), FALSE); |
905 | m->setPosition(OUT); | 905 | m->setPosition(OUT); |
906 | } | 906 | } |
907 | 907 | ||
908 | void Referee::introPaint(int t) | 908 | void Referee::introPaint(int t) |
909 | { | 909 | { |
910 | QString pts; | 910 | QString pts; |
911 | 911 | ||
912 | switch (t) { | 912 | switch (t) { |
913 | case 0 : repaint(pix->draw(16, 6, RoomPix, tr("CHARACTER"), WHITE, QColor(), AlignLeft), FALSE); | 913 | case 0 : repaint(pix->draw(16, 6, RoomPix, tr("CHARACTER"), WHITE, QColor(), AlignLeft), FALSE); |
914 | repaint(pix->draw(36, 6, RoomPix, tr("/"), WHITE, QColor(), AlignLeft), FALSE); | 914 | repaint(pix->draw(36, 6, RoomPix, tr("/"), WHITE, QColor(), AlignLeft), FALSE); |
915 | repaint(pix->draw(40, 6, RoomPix, tr("NICKNAME"), WHITE, QColor(), AlignLeft), FALSE); | 915 | repaint(pix->draw(40, 6, RoomPix, tr("NICKNAME"), WHITE, QColor(), AlignLeft), FALSE); |
916 | break; | 916 | break; |
917 | case 1 : introMonster(0); | 917 | case 1 : introMonster(0); |
918 | break; | 918 | break; |
919 | case 2 : repaint(pix->draw(16, 10, RoomPix, tr("-SHADOW"), RED, QColor(), AlignLeft), FALSE); | 919 | case 2 : repaint(pix->draw(16, 10, RoomPix, tr("-SHADOW"), RED, QColor(), AlignLeft), FALSE); |
920 | break; | 920 | break; |
921 | case 3 : repaint(pix->draw(38, 10, RoomPix, tr("\"BLINKY\""), RED, QColor(), AlignLeft), FALSE); | 921 | case 3 : repaint(pix->draw(38, 10, RoomPix, tr("\"BLINKY\""), RED, QColor(), AlignLeft), FALSE); |
922 | break; | 922 | break; |
923 | case 4 : introMonster(1); | 923 | case 4 : introMonster(1); |
924 | break; | 924 | break; |
925 | case 5 : repaint(pix->draw(16, 16, RoomPix, tr("-SPEEDY"), PINK, QColor(), AlignLeft), FALSE); | 925 | case 5 : repaint(pix->draw(16, 16, RoomPix, tr("-SPEEDY"), PINK, QColor(), AlignLeft), FALSE); |
926 | break; | 926 | break; |
927 | case 6 : repaint(pix->draw(38, 16, RoomPix, tr("\"PINKY\""), PINK, QColor(), AlignLeft), FALSE); | 927 | case 6 : repaint(pix->draw(38, 16, RoomPix, tr("\"PINKY\""), PINK, QColor(), AlignLeft), FALSE); |
928 | break; | 928 | break; |
929 | case 7 : introMonster(2); | 929 | case 7 : introMonster(2); |
930 | break; | 930 | break; |
931 | case 8 : repaint(pix->draw(16, 22, RoomPix, tr("-BASHFUL"), CYAN, QColor(), AlignLeft), FALSE); | 931 | case 8 : repaint(pix->draw(16, 22, RoomPix, tr("-BASHFUL"), CYAN, QColor(), AlignLeft), FALSE); |
932 | break; | 932 | break; |
933 | case 9 : repaint(pix->draw(38, 22, RoomPix, tr("\"INKY\""), CYAN, QColor(), AlignLeft), FALSE); | 933 | case 9 : repaint(pix->draw(38, 22, RoomPix, tr("\"INKY\""), CYAN, QColor(), AlignLeft), FALSE); |
934 | break; | 934 | break; |
935 | case 10 : introMonster(3); | 935 | case 10 : introMonster(3); |
936 | break; | 936 | break; |
937 | case 11 : repaint(pix->draw(16, 28, RoomPix, tr("-POKEY"), ORANGE, QColor(), AlignLeft), FALSE); | 937 | case 11 : repaint(pix->draw(16, 28, RoomPix, tr("-POKEY"), ORANGE, QColor(), AlignLeft), FALSE); |
938 | break; | 938 | break; |
939 | case 12 : repaint(pix->draw(38, 28, RoomPix, tr("\"CLYDE\""), ORANGE, QColor(), AlignLeft), FALSE); | 939 | case 12 : repaint(pix->draw(38, 28, RoomPix, tr("\"CLYDE\""), ORANGE, QColor(), AlignLeft), FALSE); |
940 | break; | 940 | break; |
941 | case 13 : pts.sprintf("%d", pointScore); | 941 | case 13 : pts.sprintf("%d", pointScore); |
942 | repaint(pix->draw(28, 44, RoomPix, pts.data(), WHITE, QColor(), AlignRight), FALSE); | 942 | repaint(pix->draw(28, 44, RoomPix, pts.data(), WHITE, QColor(), AlignRight), FALSE); |
943 | repaint(pix->draw(31, 44, RoomPix, "\x1C\x1D\x1E", WHITE, QColor(), AlignLeft), FALSE); | 943 | repaint(pix->draw(31, 44, RoomPix, "\x1C\x1D\x1E", WHITE, QColor(), AlignLeft), FALSE); |
944 | pts.sprintf("%d", energizerScore); | 944 | pts.sprintf("%d", energizerScore); |
945 | repaint(pix->draw(28, 48, RoomPix, pts.data(), WHITE, QColor(), AlignRight), FALSE); | 945 | repaint(pix->draw(28, 48, RoomPix, pts.data(), WHITE, QColor(), AlignRight), FALSE); |
946 | repaint(pix->draw(31, 48, RoomPix, "\x1C\x1D\x1E", WHITE, QColor(), AlignLeft), FALSE); | 946 | repaint(pix->draw(31, 48, RoomPix, "\x1C\x1D\x1E", WHITE, QColor(), AlignLeft), FALSE); |
947 | break; | 947 | break; |
948 | case 14 : // "@ 1980 MIDWAY MFG.CO." | 948 | case 14 : // "@ 1980 MIDWAY MFG.CO." |
949 | #if defined( KDE2_PORT ) | 949 | #if defined( KDE2_PORT ) |
950 | repaint(pix->draw(30, 58, RoomPix, "© 1998-2002 J.THÖNNISSEN", PINK), FALSE); | 950 | repaint(pix->draw(30, 58, RoomPix, "© 1998-2002 J.THÖNNISSEN", PINK), FALSE); |
951 | #elif defined( QPE_PORT ) | 951 | #elif defined( QPE_PORT ) |
952 | repaint(pix->draw(30, 55, RoomPix, "© 1998-2002 J.THÖNNISSEN", PINK), FALSE); | 952 | repaint(pix->draw(30, 55, RoomPix, "© 1998-2002 J.THÖNNISSEN", PINK), FALSE); |
953 | repaint(pix->draw(29, 58, RoomPix, tr("QTOPIA PORT: CATALIN CLIMOV"), GREEN), FALSE); | 953 | repaint(pix->draw(29, 58, RoomPix, tr("QTOPIA PORT: CATALIN CLIMOV"), GREEN), FALSE); |
954 | repaint(pix->draw(29, 61, RoomPix, tr("PRESS CURSOR TO START"), GREEN), FALSE); | 954 | repaint(pix->draw(29, 61, RoomPix, tr("PRESS CURSOR TO START"), GREEN), FALSE); |
955 | #endif | 955 | #endif |
956 | break; | 956 | break; |
957 | } | 957 | } |
958 | } | 958 | } |
959 | 959 | ||
960 | void Referee::introPlay() | 960 | void Referee::introPlay() |
961 | { | 961 | { |
962 | if (!gameState.testBit(Introducing) || gameState.testBit(Ready)) | 962 | if (!gameState.testBit(Introducing) || gameState.testBit(Ready)) |
963 | return; | 963 | return; |
964 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { | 964 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame)) { |
965 | QTimer::singleShot(afterPauseMS, this, SLOT(introPlay())); | 965 | QTimer::singleShot(afterPauseMS, this, SLOT(introPlay())); |
966 | return; | 966 | return; |
967 | } | 967 | } |
968 | 968 | ||
969 | if (!gameState.testBit(Init)) { | 969 | if (!gameState.testBit(Init)) { |
970 | if (monstersEaten == 4) { | 970 | if (monstersEaten == 4) { |
971 | stop(); | 971 | stop(); |
972 | QTimer::singleShot(introPostAnimationMS, this, SLOT(demo())); | 972 | QTimer::singleShot(introPostAnimationMS, this, SLOT(demo())); |
973 | } | 973 | } |
974 | if (pacman->direction() == W) { | 974 | if (pacman->direction() == W) { |
975 | int id = -1; | 975 | int id = -1; |
976 | if (pacman->position() == 37*BoardWidth-6) | 976 | if (pacman->position() == 37*BoardWidth-6) |
977 | id = 0; | 977 | id = 0; |
978 | else | 978 | else |
979 | if (board->isMonster(37*BoardWidth-6)) | 979 | if (board->isMonster(37*BoardWidth-6)) |
980 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 980 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
981 | if (m && m->position() == 37*BoardWidth-6) { | 981 | if (m && m->position() == 37*BoardWidth-6) { |
982 | id = m->id(); | 982 | id = m->id(); |
983 | id++; | 983 | id++; |
984 | break; | 984 | break; |
985 | } | 985 | } |
986 | 986 | ||
987 | if (id >= 0 && id <= 4) | 987 | if (id >= 0 && id <= 4) |
988 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 988 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
989 | if (m && m->id() == id && m->position() == OUT) { | 989 | if (m && m->id() == id && m->position() == OUT) { |
990 | m->setPosition(37*BoardWidth-1); | 990 | m->setPosition(37*BoardWidth-1); |
991 | m->setDirection(W); | 991 | m->setDirection(W); |
992 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); | 992 | m->setDangerous(dangerousTicks[level], monsterIQ[level]); |
993 | board->set(37*BoardWidth-1, monsterhome, id); | 993 | board->set(37*BoardWidth-1, monsterhome, id); |
diff --git a/noncore/games/kpacman/score.cpp b/noncore/games/kpacman/score.cpp index 17dbf0a..b3ff3d9 100644 --- a/noncore/games/kpacman/score.cpp +++ b/noncore/games/kpacman/score.cpp | |||
@@ -225,418 +225,357 @@ void Score::keyPressEvent(QKeyEvent *k) | |||
225 | 225 | ||
226 | if (ascii >= bitfont->firstChar() && ascii <= bitfont->lastChar()) { | 226 | if (ascii >= bitfont->firstChar() && ascii <= bitfont->lastChar()) { |
227 | cursor.chr = ascii; | 227 | cursor.chr = ascii; |
228 | hallOfFame[lastScore].name.at(cursor.x-14) = cursor.chr; | 228 | hallOfFame[lastScore].name.at(cursor.x-14) = cursor.chr; |
229 | if (++cursor.x > 16) | 229 | if (++cursor.x > 16) |
230 | cursor.x = 14; | 230 | cursor.x = 14; |
231 | } | 231 | } |
232 | } | 232 | } |
233 | } | 233 | } |
234 | 234 | ||
235 | if (key == Key_Return) { | 235 | if (key == Key_Return) { |
236 | playerName[lastPlayer] = hallOfFame[lastScore].name; | 236 | playerName[lastPlayer] = hallOfFame[lastScore].name; |
237 | write(); | 237 | write(); |
238 | read(); | 238 | read(); |
239 | lastScore = -1; | 239 | lastScore = -1; |
240 | cursor.x = -1; | 240 | cursor.x = -1; |
241 | cursor.y = -1; | 241 | cursor.y = -1; |
242 | // killTimers(); | 242 | // killTimers(); |
243 | emit toggleNew(); | 243 | emit toggleNew(); |
244 | end(); | 244 | end(); |
245 | } | 245 | } |
246 | 246 | ||
247 | if (x != cursor.x || y != cursor.y) { | 247 | if (x != cursor.x || y != cursor.y) { |
248 | if (cursor.x != -1) | 248 | if (cursor.x != -1) |
249 | cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); | 249 | cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); |
250 | scrollRepeat = FALSE; | 250 | scrollRepeat = FALSE; |
251 | repaint(rect(x, y*1.25, cursor.chr), FALSE); | 251 | repaint(rect(x, y*1.25, cursor.chr), FALSE); |
252 | } else | 252 | } else |
253 | hallOfFame[lastScore].name.at(cursor.x-14) = cursor.chr; | 253 | hallOfFame[lastScore].name.at(cursor.x-14) = cursor.chr; |
254 | 254 | ||
255 | if (key == UpKey || key == Key_Up || key == DownKey || key == Key_Down) | 255 | if (key == UpKey || key == Key_Up || key == DownKey || key == Key_Down) |
256 | scrollRepeat = TRUE; | 256 | scrollRepeat = TRUE; |
257 | else | 257 | else |
258 | repaint(rect(cursor.x, cursor.y*1.25, cursor.chr), FALSE); | 258 | repaint(rect(cursor.x, cursor.y*1.25, cursor.chr), FALSE); |
259 | } | 259 | } |
260 | 260 | ||
261 | void Score::initKeys() | 261 | void Score::initKeys() |
262 | { | 262 | { |
263 | APP_CONFIG_BEGIN( cfg ); | 263 | APP_CONFIG_BEGIN( cfg ); |
264 | QString up("Up"); | 264 | QString up("Up"); |
265 | up = cfg->readEntry("upKey", (const char*) up); | 265 | up = cfg->readEntry("upKey", (const char*) up); |
266 | UpKey = KAccel::stringToKey(up); | 266 | UpKey = KAccel::stringToKey(up); |
267 | 267 | ||
268 | QString down("Down"); | 268 | QString down("Down"); |
269 | down = cfg->readEntry("downKey", (const char*) down); | 269 | down = cfg->readEntry("downKey", (const char*) down); |
270 | DownKey = KAccel::stringToKey(down); | 270 | DownKey = KAccel::stringToKey(down); |
271 | 271 | ||
272 | QString left("Left"); | 272 | QString left("Left"); |
273 | left = cfg->readEntry("leftKey", (const char*) left); | 273 | left = cfg->readEntry("leftKey", (const char*) left); |
274 | LeftKey = KAccel::stringToKey(left); | 274 | LeftKey = KAccel::stringToKey(left); |
275 | 275 | ||
276 | QString right("Right"); | 276 | QString right("Right"); |
277 | right = cfg->readEntry("rightKey", (const char*) right); | 277 | right = cfg->readEntry("rightKey", (const char*) right); |
278 | RightKey = KAccel::stringToKey(right); | 278 | RightKey = KAccel::stringToKey(right); |
279 | APP_CONFIG_END( cfg ); | 279 | APP_CONFIG_END( cfg ); |
280 | } | 280 | } |
281 | 281 | ||
282 | void Score::confTiming(bool defGroup) | 282 | void Score::confTiming(bool defGroup) |
283 | { | 283 | { |
284 | APP_CONFIG_BEGIN( cfg ); | 284 | APP_CONFIG_BEGIN( cfg ); |
285 | if (defGroup || cfg->hasKey("CursorBlinkMS")) | 285 | if (defGroup || cfg->hasKey("CursorBlinkMS")) |
286 | cursorBlinkMS = cfg->readNumEntry("CursorBlinkMS", 250); | 286 | cursorBlinkMS = cfg->readNumEntry("CursorBlinkMS", 250); |
287 | if (defGroup || cfg->hasKey("HallOfFameMS")) | 287 | if (defGroup || cfg->hasKey("HallOfFameMS")) |
288 | hallOfFameMS = cfg->readNumEntry("HallOfFameMS", 7000); | 288 | hallOfFameMS = cfg->readNumEntry("HallOfFameMS", 7000); |
289 | if (defGroup || cfg->hasKey("AfterPauseMS")) | 289 | if (defGroup || cfg->hasKey("AfterPauseMS")) |
290 | afterPauseMS = cfg->readNumEntry("AfterPauseMS", 1000); | 290 | afterPauseMS = cfg->readNumEntry("AfterPauseMS", 1000); |
291 | APP_CONFIG_END( cfg ); | 291 | APP_CONFIG_END( cfg ); |
292 | } | 292 | } |
293 | 293 | ||
294 | void Score::confScheme() | 294 | void Score::confScheme() |
295 | { | 295 | { |
296 | APP_CONFIG_BEGIN( cfg ); | 296 | APP_CONFIG_BEGIN( cfg ); |
297 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 297 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
298 | QString newgroup; | 298 | QString newgroup; |
299 | 299 | ||
300 | // if not set, read mode and scheme from the configfile | 300 | // if not set, read mode and scheme from the configfile |
301 | if (mode == -1 && scheme == -1) { | 301 | if (mode == -1 && scheme == -1) { |
302 | scheme = cfg->readNumEntry("Scheme", -1); | 302 | scheme = cfg->readNumEntry("Scheme", -1); |
303 | mode = cfg->readNumEntry("Mode", -1); | 303 | mode = cfg->readNumEntry("Mode", -1); |
304 | 304 | ||
305 | // if mode is not set in the defGroup-group, lookup the scheme group | 305 | // if mode is not set in the defGroup-group, lookup the scheme group |
306 | if (scheme != -1 || mode == -1) { | 306 | if (scheme != -1 || mode == -1) { |
307 | newgroup.sprintf("Scheme %d", scheme); | 307 | newgroup.sprintf("Scheme %d", scheme); |
308 | cfg->setGroup(newgroup); | 308 | cfg->setGroup(newgroup); |
309 | 309 | ||
310 | mode = cfg->readNumEntry("Mode", -1); | 310 | mode = cfg->readNumEntry("Mode", -1); |
311 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 311 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | 314 | ||
315 | int oldCursorBlinkMS = cursorBlinkMS; | 315 | int oldCursorBlinkMS = cursorBlinkMS; |
316 | 316 | ||
317 | confTiming(); | 317 | confTiming(); |
318 | 318 | ||
319 | if (mode != -1) { | 319 | if (mode != -1) { |
320 | newgroup.sprintf("Mode %d", mode); | 320 | newgroup.sprintf("Mode %d", mode); |
321 | cfg->setGroup(newgroup); | 321 | cfg->setGroup(newgroup); |
322 | 322 | ||
323 | confTiming(FALSE); | 323 | confTiming(FALSE); |
324 | } | 324 | } |
325 | 325 | ||
326 | if (scheme != -1) { | 326 | if (scheme != -1) { |
327 | newgroup.sprintf("Scheme %d", scheme); | 327 | newgroup.sprintf("Scheme %d", scheme); |
328 | cfg->setGroup(newgroup); | 328 | cfg->setGroup(newgroup); |
329 | 329 | ||
330 | confTiming(FALSE); | 330 | confTiming(FALSE); |
331 | } | 331 | } |
332 | 332 | ||
333 | if (cursorBlinkMS != oldCursorBlinkMS) { | 333 | if (cursorBlinkMS != oldCursorBlinkMS) { |
334 | if (cursorBlinkTimer) | 334 | if (cursorBlinkTimer) |
335 | killTimer(cursorBlinkTimer); | 335 | killTimer(cursorBlinkTimer); |
336 | cursorBlinkTimer = startTimer(cursorBlinkMS); | 336 | cursorBlinkTimer = startTimer(cursorBlinkMS); |
337 | } | 337 | } |
338 | 338 | ||
339 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 339 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
340 | APP_CONFIG_END( cfg ); | 340 | APP_CONFIG_END( cfg ); |
341 | } | 341 | } |
342 | 342 | ||
343 | void Score::setScheme(int Scheme, int Mode, Bitfont *font) | 343 | void Score::setScheme(int Scheme, int Mode, Bitfont *font) |
344 | { | 344 | { |
345 | mode = Mode; | 345 | mode = Mode; |
346 | scheme = Scheme; | 346 | scheme = Scheme; |
347 | 347 | ||
348 | confScheme(); | 348 | confScheme(); |
349 | 349 | ||
350 | bitfont = font; | 350 | bitfont = font; |
351 | 351 | ||
352 | for (int p = 0; p < maxPlayer; p++) | 352 | for (int p = 0; p < maxPlayer; p++) |
353 | for (uint i = 0; i < playerName[p].length(); i++) | 353 | for (uint i = 0; i < playerName[p].length(); i++) |
354 | if (playerName[p].at(i) < bitfont->firstChar() || | 354 | if (playerName[p].at(i) < bitfont->firstChar() || |
355 | playerName[p].at(i) > bitfont->lastChar()) | 355 | playerName[p].at(i) > bitfont->lastChar()) |
356 | playerName[p].at(i) = playerName[p].at(i).upper(); | 356 | playerName[p].at(i) = playerName[p].at(i).upper(); |
357 | 357 | ||
358 | for (int i = 0; i < 10; i++) | 358 | for (int i = 0; i < 10; i++) |
359 | for (uint j = 0; j < hallOfFame[i].name.length(); j++) | 359 | for (uint j = 0; j < hallOfFame[i].name.length(); j++) |
360 | if (hallOfFame[i].name.at(j) < bitfont->firstChar() || | 360 | if (hallOfFame[i].name.at(j) < bitfont->firstChar() || |
361 | hallOfFame[i].name.at(j) > bitfont->lastChar()) | 361 | hallOfFame[i].name.at(j) > bitfont->lastChar()) |
362 | hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); | 362 | hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); |
363 | 363 | ||
364 | if (cursor.chr.unicode() < bitfont->firstChar() || | 364 | if (cursor.chr.unicode() < bitfont->firstChar() || |
365 | cursor.chr.unicode() > bitfont->lastChar()) | 365 | cursor.chr.unicode() > bitfont->lastChar()) |
366 | cursor.chr = cursor.chr.upper(); | 366 | cursor.chr = cursor.chr.upper(); |
367 | } | 367 | } |
368 | 368 | ||
369 | void Score::set(int score) | 369 | void Score::set(int score) |
370 | { | 370 | { |
371 | set(score, 0); | 371 | set(score, 0); |
372 | } | 372 | } |
373 | 373 | ||
374 | void Score::set(int score, int player) | 374 | void Score::set(int score, int player) |
375 | { | 375 | { |
376 | if (player < 0 || player >= maxPlayer) | 376 | if (player < 0 || player >= maxPlayer) |
377 | return; | 377 | return; |
378 | 378 | ||
379 | lastPlayer = player; | 379 | lastPlayer = player; |
380 | playerScore[lastPlayer] = score; | 380 | playerScore[lastPlayer] = score; |
381 | 381 | ||
382 | QString s; | 382 | QString s; |
383 | 383 | ||
384 | s.sprintf("%6d0", playerScore[lastPlayer]/10); | 384 | s.sprintf("%6d0", playerScore[lastPlayer]/10); |
385 | repaint(rect(0, 1, s), FALSE); | 385 | repaint(rect(0, 1, s), FALSE); |
386 | 386 | ||
387 | if (score > HighScore) { | 387 | if (score > HighScore) { |
388 | HighScore = score; | 388 | HighScore = score; |
389 | s.sprintf("%8d0", HighScore/10); | 389 | s.sprintf("%8d0", HighScore/10); |
390 | repaint(rect(8, 1, s), FALSE); | 390 | repaint(rect(8, 1, s), FALSE); |
391 | } | 391 | } |
392 | } | 392 | } |
393 | 393 | ||
394 | /* | 394 | /* |
395 | * Set the score for player after the game if over. If the score is in the | 395 | * Set the score for player after the game if over. If the score is in the |
396 | * high scores then the hall of fame is updated (shifted) and the scoreboard | 396 | * high scores then the hall of fame is updated (shifted) and the scoreboard |
397 | * is shown. | 397 | * is shown. |
398 | */ | 398 | */ |
399 | 399 | ||
400 | void Score::setScore(int level, int player) | 400 | void Score::setScore(int level, int player) |
401 | { | 401 | { |
402 | lastScore = -1; | 402 | lastScore = -1; |
403 | 403 | ||
404 | if (player < 0 || player >= maxPlayer || level == 0) { | 404 | if (player < 0 || player >= maxPlayer || level == 0) { |
405 | if (level != 0) | 405 | if (level != 0) |
406 | emit toggleNew(); | 406 | emit toggleNew(); |
407 | QTimer::singleShot(hallOfFameMS, this, SLOT(end())); | 407 | QTimer::singleShot(hallOfFameMS, this, SLOT(end())); |
408 | return; | 408 | return; |
409 | } | 409 | } |
410 | 410 | ||
411 | lastPlayer = player; | 411 | lastPlayer = player; |
412 | 412 | ||
413 | for (int i = 0; i < 10; i++) | 413 | for (int i = 0; i < 10; i++) |
414 | if ( playerScore[lastPlayer] > hallOfFame[i].points) { | 414 | if ( playerScore[lastPlayer] > hallOfFame[i].points) { |
415 | lastScore = i; | 415 | lastScore = i; |
416 | break; | 416 | break; |
417 | } | 417 | } |
418 | 418 | ||
419 | if (lastScore < 0) { | 419 | if (lastScore < 0) { |
420 | emit toggleNew(); | 420 | emit toggleNew(); |
421 | QTimer::singleShot(hallOfFameMS, this, SLOT(end())); | 421 | QTimer::singleShot(hallOfFameMS, this, SLOT(end())); |
422 | return; | 422 | return; |
423 | } | 423 | } |
424 | 424 | ||
425 | for (int i = 9; i > lastScore && i > 0; i--) | 425 | for (int i = 9; i > lastScore && i > 0; i--) |
426 | hallOfFame[i] = hallOfFame[i-1]; | 426 | hallOfFame[i] = hallOfFame[i-1]; |
427 | 427 | ||
428 | hallOfFame[lastScore].points = playerScore[lastPlayer]; | 428 | hallOfFame[lastScore].points = playerScore[lastPlayer]; |
429 | hallOfFame[lastScore].levels = level; | 429 | hallOfFame[lastScore].levels = level; |
430 | hallOfFame[lastScore].moment = QDateTime::currentDateTime(); | 430 | hallOfFame[lastScore].moment = QDateTime::currentDateTime(); |
431 | hallOfFame[lastScore].name = playerName[lastPlayer]; | 431 | hallOfFame[lastScore].name = playerName[lastPlayer]; |
432 | 432 | ||
433 | cursor.x = 14; | 433 | cursor.x = 14; |
434 | cursor.y = 11+lastScore; | 434 | cursor.y = 11+lastScore; |
435 | cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); | 435 | cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); |
436 | 436 | ||
437 | // startTimer(cursorBlinkMS); | 437 | // startTimer(cursorBlinkMS); |
438 | setFocus(); | 438 | setFocus(); |
439 | } | 439 | } |
440 | 440 | ||
441 | /* | 441 | /* |
442 | * Read the highscores, if no file or a file shorter than 4 bytes (versions before 0.2.4 stores only | 442 | * Read the highscores, if no file or a file shorter than 4 bytes (versions before 0.2.4 stores only |
443 | * the points of one highscore) exists - the highscores were initialized with default values. | 443 | * the points of one highscore) exists - the highscores were initialized with default values. |
444 | */ | 444 | */ |
445 | void Score::read() | 445 | void Score::read() |
446 | { | 446 | { |
447 | if (highscoreFile.exists() && highscoreFile.size() > 4) { | 447 | if (highscoreFile.exists() && highscoreFile.size() > 4) { |
448 | if (highscoreFile.open(IO_ReadOnly)) { | 448 | if (highscoreFile.open(IO_ReadOnly)) { |
449 | QDataStream s(&highscoreFile); | 449 | QDataStream s(&highscoreFile); |
450 | char *name; | 450 | char *name; |
451 | for (int i = 0; i < 10; i++) { | 451 | for (int i = 0; i < 10; i++) { |
452 | s >> hallOfFame[i].points >> hallOfFame[i].levels >> hallOfFame[i].duration >> | 452 | s >> hallOfFame[i].points >> hallOfFame[i].levels >> hallOfFame[i].duration >> |
453 | hallOfFame[i].moment >> name; | 453 | hallOfFame[i].moment >> name; |
454 | hallOfFame[i].name = QString::fromLatin1(name); | 454 | hallOfFame[i].name = QString::fromLatin1(name); |
455 | delete(name); | 455 | delete(name); |
456 | } | 456 | } |
457 | highscoreFile.close(); | 457 | highscoreFile.close(); |
458 | } | 458 | } |
459 | } else { | 459 | } else { |
460 | for (int i = 0; i < 10; i++) { | 460 | for (int i = 0; i < 10; i++) { |
461 | hallOfFame[i].points = 5000; | 461 | hallOfFame[i].points = 5000; |
462 | hallOfFame[i].levels = 0; | 462 | hallOfFame[i].levels = 0; |
463 | hallOfFame[i].duration = QTime(); | 463 | hallOfFame[i].duration = QTime(); |
464 | hallOfFame[i].moment = QDateTime(); | 464 | hallOfFame[i].moment = QDateTime(); |
465 | hallOfFame[i].name = "???"; | 465 | hallOfFame[i].name = "???"; |
466 | } | 466 | } |
467 | // write(); | 467 | // write(); |
468 | } | 468 | } |
469 | 469 | ||
470 | for (int i = 0; i < 10; i++) | 470 | for (int i = 0; i < 10; i++) |
471 | for (uint j = 0; j < hallOfFame[i].name.length(); j++) | 471 | for (uint j = 0; j < hallOfFame[i].name.length(); j++) |
472 | if (hallOfFame[i].name.at(j) < bitfont->firstChar() || | 472 | if (hallOfFame[i].name.at(j) < bitfont->firstChar() || |
473 | hallOfFame[i].name.at(j) > bitfont->lastChar()) | 473 | hallOfFame[i].name.at(j) > bitfont->lastChar()) |
474 | hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); | 474 | hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); |
475 | 475 | ||
476 | HighScore = hallOfFame[0].points; | 476 | HighScore = hallOfFame[0].points; |
477 | } | 477 | } |
478 | 478 | ||
479 | void Score::write() | 479 | void Score::write() |
480 | { | 480 | { |
481 | #ifndef QWS | ||
482 | if (!highscoreFile.exists() && highscoreFile.name() == systemHighscoreFileInfo.filePath()) | ||
483 | KMessageBox::information(0, | ||
484 | tr("You're going to create the highscore-file\n" | ||
485 | "'%1'\n" | ||
486 | "for your maschine, that should be used systemwide.\n" | ||
487 | "\n" | ||
488 | "To grant access to the other users, set the appropriate rights (a+w)\n" | ||
489 | "on that file or ask your systemadministator for that favor.\n" | ||
490 | "\n" | ||
491 | "To use a different directory or filename for the highscores," | ||
492 | "specify them in the configfile (kpacmanrc:highscoreFilePath)." | ||
493 | ).arg(systemHighscoreFileInfo.filePath())); | ||
494 | |||
495 | if (highscoreFile.name() == privateHighscoreFileInfo.filePath()) | ||
496 | KMessageBox::information(0, | ||
497 | tr("You're using a private highscore-file, that's mostly because of\n" | ||
498 | "missing write-access to the systemwide file\n" | ||
499 | "'%1' .\n" | ||
500 | "\n" | ||
501 | "Ask your systemadministrator for granting you access to that file,\n" | ||
502 | "by setting the appropriate rights (a+w) on it.\n" | ||
503 | "\n" | ||
504 | "To use a different directory or filename for the highscores," | ||
505 | "specify them in the configfile (kpacmanrc:highscoreFilePath)." | ||
506 | ).arg(systemHighscoreFileInfo.filePath()), | ||
507 | QString::null, "PrivateHighscore"); | ||
508 | #endif | ||
509 | if (highscoreFile.open(IO_WriteOnly)) { | 481 | if (highscoreFile.open(IO_WriteOnly)) { |
510 | QDataStream s(&highscoreFile); | 482 | QDataStream s(&highscoreFile); |
511 | for (int i = 0; i < 10; i++) | 483 | for (int i = 0; i < 10; i++) |
512 | s << hallOfFame[i].points << hallOfFame[i].levels << hallOfFame[i].duration << | 484 | s << hallOfFame[i].points << hallOfFame[i].levels << hallOfFame[i].duration << |
513 | hallOfFame[i].moment << hallOfFame[i].name.latin1(); | 485 | hallOfFame[i].moment << hallOfFame[i].name.latin1(); |
514 | highscoreFile.close(); | 486 | highscoreFile.close(); |
515 | } | 487 | } |
516 | } | 488 | } |
517 | 489 | ||
518 | void Score::setPause(bool Paused) | 490 | void Score::setPause(bool Paused) |
519 | { | 491 | { |
520 | paused = Paused; | 492 | paused = Paused; |
521 | 493 | ||
522 | QRect r = bitfont->rect(tr("PAUSED")); | 494 | QRect r = bitfont->rect(tr("PAUSED")); |
523 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); | 495 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); |
524 | repaint(r, TRUE); | 496 | repaint(r, TRUE); |
525 | 497 | ||
526 | // repaint 1UP or 2UP | 498 | // repaint 1UP or 2UP |
527 | repaint(FALSE); | 499 | repaint(FALSE); |
528 | } | 500 | } |
529 | 501 | ||
530 | void Score::end() | 502 | void Score::end() |
531 | { | 503 | { |
532 | if (paused) { | 504 | if (paused) { |
533 | QTimer::singleShot(afterPauseMS, this, SLOT(end())); | 505 | QTimer::singleShot(afterPauseMS, this, SLOT(end())); |
534 | return; | 506 | return; |
535 | } | 507 | } |
536 | 508 | ||
537 | // repaint 1UP or 2UP | 509 | // repaint 1UP or 2UP |
538 | lastPlayer = -1; | 510 | lastPlayer = -1; |
539 | repaint(FALSE); | 511 | repaint(FALSE); |
540 | 512 | ||
541 | emit forcedHallOfFame(FALSE); | 513 | emit forcedHallOfFame(FALSE); |
542 | } | 514 | } |
543 | 515 | ||
544 | /* | 516 | /* |
545 | * Return the date in a formatted QString. The format can be changed using internationalization | 517 | * Return the date in a formatted QString. The format can be changed using internationalization |
546 | * of the string "YY/MM/DD". Invalid QDate's where returned as "00/00/00". | 518 | * of the string "YY/MM/DD". Invalid QDate's where returned as "00/00/00". |
547 | */ | 519 | */ |
548 | QString Score::formatDate(QDate date) | 520 | QString Score::formatDate(QDate date) |
549 | { | 521 | { |
550 | QString s = tr("@YY@/@MM@/@DD@"); | 522 | QString s = tr("@YY@/@MM@/@DD@"); |
551 | 523 | ||
552 | QString dd; | 524 | QString dd; |
553 | dd.sprintf("%02d", date.isValid() ? date.year() % 100 : 0); | 525 | dd.sprintf("%02d", date.isValid() ? date.year() % 100 : 0); |
554 | s.replace(QRegExp("@YY@"), dd); | 526 | s.replace(QRegExp("@YY@"), dd); |
555 | dd.sprintf("%02d", date.isValid() ? date.month() : 0); | 527 | dd.sprintf("%02d", date.isValid() ? date.month() : 0); |
556 | s.replace(QRegExp("@MM@"), dd); | 528 | s.replace(QRegExp("@MM@"), dd); |
557 | dd.sprintf("%02d", date.isValid() ? date.day() : 0); | 529 | dd.sprintf("%02d", date.isValid() ? date.day() : 0); |
558 | s.replace(QRegExp("@DD@"), dd); | 530 | s.replace(QRegExp("@DD@"), dd); |
559 | 531 | ||
560 | return s; | 532 | return s; |
561 | } | 533 | } |
562 | 534 | ||
563 | QRect Score::rect(int col, float row, QString str, int align) | 535 | QRect Score::rect(int col, float row, QString str, int align) |
564 | { | 536 | { |
565 | QRect r = bitfont->rect(str); | 537 | QRect r = bitfont->rect(str); |
566 | r.moveBy(x(col), y(row)); | 538 | r.moveBy(x(col), y(row)); |
567 | 539 | ||
568 | int dx = 0; | 540 | int dx = 0; |
569 | int dy = 0; | 541 | int dy = 0; |
570 | 542 | ||
571 | if (align & AlignLeft || align & AlignRight) { | 543 | if (align & AlignLeft || align & AlignRight) { |
572 | dx = (str.length()-1) * (bitfont->width()/2); | 544 | dx = (str.length()-1) * (bitfont->width()/2); |
573 | if (align & AlignRight) | 545 | if (align & AlignRight) |
574 | dx *= -1; | 546 | dx *= -1; |
575 | } | 547 | } |
576 | 548 | ||
577 | if (align & AlignTop || align & AlignBottom) { | 549 | if (align & AlignTop || align & AlignBottom) { |
578 | dy = bitfont->height()/2; | 550 | dy = bitfont->height()/2; |
579 | if (align & AlignBottom) | 551 | if (align & AlignBottom) |
580 | dy *= -1; | 552 | dy *= -1; |
581 | } | 553 | } |
582 | 554 | ||
583 | if (dx != 0 || dy != 0) | 555 | if (dx != 0 || dy != 0) |
584 | r.moveBy(dx, dy); | 556 | r.moveBy(dx, dy); |
585 | 557 | ||
586 | return r; | 558 | return r; |
587 | } | 559 | } |
588 | 560 | ||
589 | int Score::x(int col) | 561 | int Score::x(int col) |
590 | { | 562 | { |
591 | return col*bitfont->width(); | 563 | return col*bitfont->width(); |
592 | } | 564 | } |
593 | 565 | ||
594 | int Score::y(float row) | 566 | int Score::y(float row) |
595 | { | 567 | { |
596 | return (int) (row*(bitfont->height()+bitfont->height()/4)); | 568 | return (int) (row*(bitfont->height()+bitfont->height()/4)); |
597 | } | 569 | } |
598 | 570 | ||
599 | /** | 571 | /** |
600 | * Ermittelt die zu benutzende "highscore"-Datei, in die auch geschrieben werden kann. | 572 | * Ermittelt die zu benutzende "highscore"-Datei, in die auch geschrieben werden kann. |
601 | * Über den "highscoreFilePath"-KConfig-Eintrag, kann abweichend von der Standardlokation | 573 | * Über den "highscoreFilePath"-KConfig-Eintrag, kann abweichend von der Standardlokation |
602 | * der Standort der "highscore"-Datei spezifiziert werden. | 574 | * der Standort der "highscore"-Datei spezifiziert werden. |
603 | * Wenn die systemweite "highscore"-Datei nicht beschrieben werden kann, wird mit einer | 575 | * Wenn die systemweite "highscore"-Datei nicht beschrieben werden kann, wird mit einer |
604 | * privaten Datei gearbeitet. | 576 | * privaten Datei gearbeitet. |
605 | */ | 577 | */ |
606 | QFileInfo Score::locateHighscoreFilePath() | 578 | QFileInfo Score::locateHighscoreFilePath() |
607 | { | 579 | { |
608 | #ifndef QWS | ||
609 | QFileInfo systemHighscoreDirPath; | ||
610 | QStringList systemHighscoreDirs; | ||
611 | |||
612 | // Schreibfähige "private" highscore-Datei ermitteln für den fallback. | ||
613 | privateHighscoreFileInfo.setFile(KGlobal::dirs()->saveLocation("appdata")+highscoreName); | ||
614 | |||
615 | // FilePath aus der Konfigurationsdatei benutzen | ||
616 | systemHighscoreFileInfo.setFile(cfg->readEntry("HighscoreFilePath")); | ||
617 | |||
618 | // Kein Wert aus der Konfiguration erhalten, dann die "system"-Datei suchen. | ||
619 | if (systemHighscoreFileInfo.filePath().isEmpty()) | ||
620 | systemHighscoreDirs = KGlobal::dirs()->resourceDirs("appdata"); | ||
621 | else | ||
622 | systemHighscoreDirs = QStringList(systemHighscoreFileInfo.filePath()); | ||
623 | |||
624 | for (QStringList::Iterator i = systemHighscoreDirs.begin(); i != systemHighscoreDirs.end(); ++i) { | ||
625 | |||
626 | systemHighscoreFileInfo.setFile(*i); | ||
627 | if (systemHighscoreFileInfo.fileName().isEmpty()) | ||
628 | systemHighscoreFileInfo.setFile(systemHighscoreFileInfo.dirPath()+"/"+highscoreName); | ||
629 | |||
630 | // privateHighscoreFileInfo für die "system" Suche ignorieren | ||
631 | if (systemHighscoreFileInfo.filePath() != privateHighscoreFileInfo.filePath()) | ||
632 | if (!systemHighscoreFileInfo.exists()) { | ||
633 | systemHighscoreDirPath.setFile(systemHighscoreFileInfo.dirPath()); | ||
634 | if (systemHighscoreDirPath.exists() && systemHighscoreDirPath.isWritable()) | ||
635 | return systemHighscoreFileInfo; | ||
636 | } else | ||
637 | if (systemHighscoreFileInfo.isWritable()) | ||
638 | return systemHighscoreFileInfo; | ||
639 | } | ||
640 | #endif | ||
641 | return privateHighscoreFileInfo; | 580 | return privateHighscoreFileInfo; |
642 | } | 581 | } |