-rw-r--r-- | noncore/games/kpacman/score.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/games/kpacman/score.cpp b/noncore/games/kpacman/score.cpp index b3ff3d9..e91771b 100644 --- a/noncore/games/kpacman/score.cpp +++ b/noncore/games/kpacman/score.cpp | |||
@@ -1,581 +1,581 @@ | |||
1 | 1 | ||
2 | #include "portable.h" | 2 | #include "portable.h" |
3 | 3 | ||
4 | #if defined( KDE2_PORT ) | 4 | #if defined( KDE2_PORT ) |
5 | #include <score.h> | 5 | #include <score.h> |
6 | #include <score.moc> | 6 | #include <score.moc> |
7 | 7 | ||
8 | #include <kaccel.h> | 8 | #include <kaccel.h> |
9 | #include <kapp.h> | 9 | #include <kapp.h> |
10 | #include <kconfig.h> | 10 | #include <kconfig.h> |
11 | #include <kstddirs.h> | 11 | #include <kstddirs.h> |
12 | #include <kmessagebox.h> | 12 | #include <kmessagebox.h> |
13 | #elif defined( QPE_PORT ) | 13 | #elif defined( QPE_PORT ) |
14 | #include <qaccel.h> | 14 | #include <qaccel.h> |
15 | #include "config.h" | 15 | #include <qpe/config.h> |
16 | #include "score.h" | 16 | #include "score.h" |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include <ctype.h> | 20 | #include <ctype.h> |
21 | 21 | ||
22 | #include <qpixmap.h> | 22 | #include <qpixmap.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qdstream.h> | 24 | #include <qdstream.h> |
25 | #include <qkeycode.h> | 25 | #include <qkeycode.h> |
26 | #include <qtimer.h> | 26 | #include <qtimer.h> |
27 | #include <qfileinfo.h> | 27 | #include <qfileinfo.h> |
28 | 28 | ||
29 | #include "bitfont.h" | 29 | #include "bitfont.h" |
30 | 30 | ||
31 | Score::Score(QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) : QWidget(parent, name) | 31 | Score::Score(QWidget *parent, const char *name, int Scheme, int Mode, Bitfont *font) : QWidget(parent, name) |
32 | { | 32 | { |
33 | setFocusPolicy(QWidget::StrongFocus); | 33 | setFocusPolicy(QWidget::StrongFocus); |
34 | 34 | ||
35 | paused = FALSE; | 35 | paused = FALSE; |
36 | 36 | ||
37 | lastScore = -1; | 37 | lastScore = -1; |
38 | lastPlayer = -1; | 38 | lastPlayer = -1; |
39 | 39 | ||
40 | cursorBlinkTimer = 0; | 40 | cursorBlinkTimer = 0; |
41 | cursorBlinkMS = -1; | 41 | cursorBlinkMS = -1; |
42 | cursor.x = -1; | 42 | cursor.x = -1; |
43 | cursor.y = -1; | 43 | cursor.y = -1; |
44 | cursor.on = FALSE; | 44 | cursor.on = FALSE; |
45 | cursor.chr = QChar('?'); | 45 | cursor.chr = QChar('?'); |
46 | 46 | ||
47 | initKeys(); | 47 | initKeys(); |
48 | 48 | ||
49 | scheme = Scheme; | 49 | scheme = Scheme; |
50 | mode = Mode; | 50 | mode = Mode; |
51 | confScheme(); | 51 | confScheme(); |
52 | 52 | ||
53 | bitfont = font; | 53 | bitfont = font; |
54 | 54 | ||
55 | highscoreFile.setName(locateHighscoreFilePath().filePath()); | 55 | highscoreFile.setName(locateHighscoreFilePath().filePath()); |
56 | read(); | 56 | read(); |
57 | 57 | ||
58 | for (int p = 0; p < maxPlayer; p++) { | 58 | for (int p = 0; p < maxPlayer; p++) { |
59 | playerScore[p] = 0; | 59 | playerScore[p] = 0; |
60 | playerName[p] = getenv("LOGNAME"); | 60 | playerName[p] = getenv("LOGNAME"); |
61 | if (playerName[p].length() < minPlayerNameLength) | 61 | if (playerName[p].length() < minPlayerNameLength) |
62 | playerName[p].setExpand(minPlayerNameLength-1, ' '); | 62 | playerName[p].setExpand(minPlayerNameLength-1, ' '); |
63 | 63 | ||
64 | for (uint i = 0; i < playerName[p].length(); i++) | 64 | for (uint i = 0; i < playerName[p].length(); i++) |
65 | if (playerName[p].at(i) < bitfont->firstChar() || | 65 | if (playerName[p].at(i) < bitfont->firstChar() || |
66 | playerName[p].at(i) > bitfont->lastChar()) | 66 | playerName[p].at(i) > bitfont->lastChar()) |
67 | playerName[p].at(i) = playerName[p].at(i).upper(); | 67 | playerName[p].at(i) = playerName[p].at(i).upper(); |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | Score::~Score() | 71 | Score::~Score() |
72 | { | 72 | { |
73 | // write(); | 73 | // write(); |
74 | } | 74 | } |
75 | 75 | ||
76 | void Score::paintEvent( QPaintEvent *e) | 76 | void Score::paintEvent( QPaintEvent *e) |
77 | { | 77 | { |
78 | if (rect(1, 0, tr(" 1UP ")).intersects(e->rect())) { | 78 | if (rect(1, 0, tr(" 1UP ")).intersects(e->rect())) { |
79 | QPixmap pix; | 79 | QPixmap pix; |
80 | QColor fg = BLACK; | 80 | QColor fg = BLACK; |
81 | if (cursor.on || paused || lastPlayer != 0) | 81 | if (cursor.on || paused || lastPlayer != 0) |
82 | fg = WHITE; | 82 | fg = WHITE; |
83 | pix = bitfont->text(tr(" 1UP "), fg, BLACK); | 83 | pix = bitfont->text(tr(" 1UP "), fg, BLACK); |
84 | bitBlt(this, x(1), y(0), &pix); | 84 | bitBlt(this, x(1), y(0), &pix); |
85 | } | 85 | } |
86 | 86 | ||
87 | if (rect(8, 0, tr(" HIGH SCORE ")).intersects(e->rect())) { | 87 | if (rect(8, 0, tr(" HIGH SCORE ")).intersects(e->rect())) { |
88 | QPixmap pix = bitfont->text(tr(" HIGH SCORE "), WHITE, BLACK); | 88 | QPixmap pix = bitfont->text(tr(" HIGH SCORE "), WHITE, BLACK); |
89 | bitBlt(this, x(8), y(0), &pix); | 89 | bitBlt(this, x(8), y(0), &pix); |
90 | } | 90 | } |
91 | 91 | ||
92 | if (maxPlayer > 1 && rect(21, 0, tr(" 2UP ")).intersects(e->rect())) { | 92 | if (maxPlayer > 1 && rect(21, 0, tr(" 2UP ")).intersects(e->rect())) { |
93 | QPixmap pix; | 93 | QPixmap pix; |
94 | QColor fg = BLACK; | 94 | QColor fg = BLACK; |
95 | if (cursor.on || paused || lastPlayer != 1) | 95 | if (cursor.on || paused || lastPlayer != 1) |
96 | fg = WHITE; | 96 | fg = WHITE; |
97 | pix = bitfont->text(tr(" 2UP "), fg, BLACK); | 97 | pix = bitfont->text(tr(" 2UP "), fg, BLACK); |
98 | bitBlt(this, x(21), y(0), &pix); | 98 | bitBlt(this, x(21), y(0), &pix); |
99 | } | 99 | } |
100 | 100 | ||
101 | QString s; | 101 | QString s; |
102 | 102 | ||
103 | s.sprintf("%6d0", playerScore[0]/10); | 103 | s.sprintf("%6d0", playerScore[0]/10); |
104 | if (rect(0, 1, s).intersects(e->rect())) { | 104 | if (rect(0, 1, s).intersects(e->rect())) { |
105 | QPixmap pix = bitfont->text(s, WHITE, BLACK); | 105 | QPixmap pix = bitfont->text(s, WHITE, BLACK); |
106 | bitBlt(this, x(0), y(1), &pix); | 106 | bitBlt(this, x(0), y(1), &pix); |
107 | } | 107 | } |
108 | 108 | ||
109 | s.sprintf("%8d0", HighScore/10); | 109 | s.sprintf("%8d0", HighScore/10); |
110 | if (rect(8, 1, s).intersects(e->rect())) { | 110 | if (rect(8, 1, s).intersects(e->rect())) { |
111 | QPixmap pix = bitfont->text(s, WHITE, BLACK); | 111 | QPixmap pix = bitfont->text(s, WHITE, BLACK); |
112 | bitBlt(this, x(8), y(1), &pix); | 112 | bitBlt(this, x(8), y(1), &pix); |
113 | } | 113 | } |
114 | 114 | ||
115 | if (lastScore >= 0) { | 115 | if (lastScore >= 0) { |
116 | if (rect(1, 4*1.25, tr(" CONGRATULATIONS ")).intersects(e->rect())) { | 116 | if (rect(1, 4*1.25, tr(" CONGRATULATIONS ")).intersects(e->rect())) { |
117 | QPixmap pix = bitfont->text(tr(" CONGRATULATIONS "), YELLOW, BLACK); | 117 | QPixmap pix = bitfont->text(tr(" CONGRATULATIONS "), YELLOW, BLACK); |
118 | bitBlt(this, x(1), y(4*1.25), &pix); | 118 | bitBlt(this, x(1), y(4*1.25), &pix); |
119 | } | 119 | } |
120 | if (rect(1, 6*1.25, tr(" YOU HAVE ARCHIEVED ")).intersects(e->rect())) { | 120 | if (rect(1, 6*1.25, tr(" YOU HAVE ARCHIEVED ")).intersects(e->rect())) { |
121 | QPixmap pix = bitfont->text(tr(" YOU HAVE ARCHIEVED "), CYAN, BLACK); | 121 | QPixmap pix = bitfont->text(tr(" YOU HAVE ARCHIEVED "), CYAN, BLACK); |
122 | bitBlt(this, x(1), y(6*1.25), &pix); | 122 | bitBlt(this, x(1), y(6*1.25), &pix); |
123 | } | 123 | } |
124 | if (rect(1, 7*1.25, tr(" A SCORE IN THE TOP 10. ")).intersects(e->rect())) { | 124 | if (rect(1, 7*1.25, tr(" A SCORE IN THE TOP 10. ")).intersects(e->rect())) { |
125 | QPixmap pix = bitfont->text(tr(" A SCORE IN THE TOP 10. "), CYAN, BLACK); | 125 | QPixmap pix = bitfont->text(tr(" A SCORE IN THE TOP 10. "), CYAN, BLACK); |
126 | bitBlt(this, x(1), y(7*1.25), &pix); | 126 | bitBlt(this, x(1), y(7*1.25), &pix); |
127 | } | 127 | } |
128 | if (rect(1, 8*1.25, tr(" ")).intersects(e->rect())) { | 128 | if (rect(1, 8*1.25, tr(" ")).intersects(e->rect())) { |
129 | QPixmap pix = bitfont->text(tr(" "), CYAN, BLACK); | 129 | QPixmap pix = bitfont->text(tr(" "), CYAN, BLACK); |
130 | bitBlt(this, x(1), y(8*1.25), &pix); | 130 | bitBlt(this, x(1), y(8*1.25), &pix); |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | if (rect(1, 9.5*1.25, tr("RNK SCORE NAME DATE")).intersects(e->rect())) { | 134 | if (rect(1, 9.5*1.25, tr("RNK SCORE NAME DATE")).intersects(e->rect())) { |
135 | QPixmap pix = bitfont->text(tr("RNK SCORE NAME DATE"), WHITE, BLACK); | 135 | QPixmap pix = bitfont->text(tr("RNK SCORE NAME DATE"), WHITE, BLACK); |
136 | bitBlt(this, x(1), y(9.5*1.25), &pix); | 136 | bitBlt(this, x(1), y(9.5*1.25), &pix); |
137 | } | 137 | } |
138 | 138 | ||
139 | for (int i = 0; i < 10; i++) { | 139 | for (int i = 0; i < 10; i++) { |
140 | s.sprintf("%2d%9d %-3.3s %-8.8s", | 140 | s.sprintf("%2d%9d %-3.3s %-8.8s", |
141 | i+1, hallOfFame[i].points, hallOfFame[i].name.utf8().data(), | 141 | i+1, hallOfFame[i].points, hallOfFame[i].name.utf8().data(), |
142 | formatDate(hallOfFame[i].moment.date()).data()); | 142 | formatDate(hallOfFame[i].moment.date()).data()); |
143 | if (rect(1, (11+i)*1.25, s).intersects(e->rect())) { | 143 | if (rect(1, (11+i)*1.25, s).intersects(e->rect())) { |
144 | QPixmap pix = bitfont->text(s, (i == lastScore) ? YELLOW : WHITE, BLACK); | 144 | QPixmap pix = bitfont->text(s, (i == lastScore) ? YELLOW : WHITE, BLACK); |
145 | bitBlt(this, x(1), y((11+i)*1.25), &pix); | 145 | bitBlt(this, x(1), y((11+i)*1.25), &pix); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | if (cursor.x != -1 && cursor.y != -1 && cursor.on) { | 149 | if (cursor.x != -1 && cursor.y != -1 && cursor.on) { |
150 | if (rect(cursor.x, (cursor.y*1.25), cursor.chr).intersects(e->rect())) { | 150 | if (rect(cursor.x, (cursor.y*1.25), cursor.chr).intersects(e->rect())) { |
151 | QPixmap pix = bitfont->text(cursor.chr, BLACK, YELLOW); | 151 | QPixmap pix = bitfont->text(cursor.chr, BLACK, YELLOW); |
152 | bitBlt(this, x(cursor.x), y(cursor.y*1.25), &pix); | 152 | bitBlt(this, x(cursor.x), y(cursor.y*1.25), &pix); |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | if (paused) { | 156 | if (paused) { |
157 | 157 | ||
158 | QPixmap pix = bitfont->text(tr("PAUSED"), RED, BLACK); | 158 | QPixmap pix = bitfont->text(tr("PAUSED"), RED, BLACK); |
159 | QRect r = bitfont->rect(tr("PAUSED")); | 159 | QRect r = bitfont->rect(tr("PAUSED")); |
160 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); | 160 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); |
161 | 161 | ||
162 | bitBlt(this, r.x(), r.y(), &pix); | 162 | bitBlt(this, r.x(), r.y(), &pix); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | void Score::timerEvent(QTimerEvent*) | 166 | void Score::timerEvent(QTimerEvent*) |
167 | { | 167 | { |
168 | cursor.on = !cursor.on; | 168 | cursor.on = !cursor.on; |
169 | 169 | ||
170 | if (paused) | 170 | if (paused) |
171 | return; | 171 | return; |
172 | 172 | ||
173 | if (cursor.x != -1 && cursor.y != -1) | 173 | if (cursor.x != -1 && cursor.y != -1) |
174 | repaint(rect(cursor.x, cursor.y*1.25, cursor.chr), FALSE); | 174 | repaint(rect(cursor.x, cursor.y*1.25, cursor.chr), FALSE); |
175 | scrollRepeat = FALSE; | 175 | scrollRepeat = FALSE; |
176 | 176 | ||
177 | if (lastPlayer == 0) | 177 | if (lastPlayer == 0) |
178 | repaint(rect(1, 0, tr(" 1UP ")), FALSE); | 178 | repaint(rect(1, 0, tr(" 1UP ")), FALSE); |
179 | 179 | ||
180 | if (lastPlayer == 1) | 180 | if (lastPlayer == 1) |
181 | repaint(rect(21, 0, tr(" 2UP ")), FALSE); | 181 | repaint(rect(21, 0, tr(" 2UP ")), FALSE); |
182 | } | 182 | } |
183 | 183 | ||
184 | void Score::keyPressEvent(QKeyEvent *k) | 184 | void Score::keyPressEvent(QKeyEvent *k) |
185 | { | 185 | { |
186 | if (lastScore < 0 || lastPlayer < 0 || lastPlayer >= maxPlayer || paused) { | 186 | if (lastScore < 0 || lastPlayer < 0 || lastPlayer >= maxPlayer || paused) { |
187 | k->ignore(); | 187 | k->ignore(); |
188 | return; | 188 | return; |
189 | } | 189 | } |
190 | 190 | ||
191 | int x = cursor.x; | 191 | int x = cursor.x; |
192 | int y = cursor.y; | 192 | int y = cursor.y; |
193 | 193 | ||
194 | uint key = k->key(); | 194 | uint key = k->key(); |
195 | 195 | ||
196 | if (scrollRepeat && (key == UpKey || key == Key_Up || key == DownKey || key == Key_Down)) { | 196 | if (scrollRepeat && (key == UpKey || key == Key_Up || key == DownKey || key == Key_Down)) { |
197 | k->ignore(); | 197 | k->ignore(); |
198 | return; | 198 | return; |
199 | } | 199 | } |
200 | 200 | ||
201 | if (key != Key_Return) { | 201 | if (key != Key_Return) { |
202 | if (key == RightKey || key == Key_Right) | 202 | if (key == RightKey || key == Key_Right) |
203 | if (++cursor.x > 16) | 203 | if (++cursor.x > 16) |
204 | cursor.x = 14; | 204 | cursor.x = 14; |
205 | if (key == LeftKey || key == Key_Left) | 205 | if (key == LeftKey || key == Key_Left) |
206 | if (--cursor.x < 14) | 206 | if (--cursor.x < 14) |
207 | cursor.x = 16; | 207 | cursor.x = 16; |
208 | if (key == UpKey || key == Key_Up) | 208 | if (key == UpKey || key == Key_Up) |
209 | if (cursor.chr.unicode() < bitfont->lastChar()) | 209 | if (cursor.chr.unicode() < bitfont->lastChar()) |
210 | cursor.chr = cursor.chr.unicode()+1; | 210 | cursor.chr = cursor.chr.unicode()+1; |
211 | else | 211 | else |
212 | cursor.chr = bitfont->firstChar(); | 212 | cursor.chr = bitfont->firstChar(); |
213 | if (key == DownKey || key == Key_Down) | 213 | if (key == DownKey || key == Key_Down) |
214 | if (cursor.chr.unicode() > bitfont->firstChar()) | 214 | if (cursor.chr.unicode() > bitfont->firstChar()) |
215 | cursor.chr = cursor.chr.unicode()-1; | 215 | cursor.chr = cursor.chr.unicode()-1; |
216 | else | 216 | else |
217 | cursor.chr = bitfont->lastChar(); | 217 | cursor.chr = bitfont->lastChar(); |
218 | 218 | ||
219 | if (cursor.x == x && cursor.y == y && | 219 | if (cursor.x == x && cursor.y == y && |
220 | cursor.chr == hallOfFame[lastScore].name.at(cursor.x-14)) { | 220 | cursor.chr == hallOfFame[lastScore].name.at(cursor.x-14)) { |
221 | uint ascii = k->ascii(); | 221 | uint ascii = k->ascii(); |
222 | 222 | ||
223 | if (ascii < bitfont->firstChar() || ascii > bitfont->lastChar()) | 223 | if (ascii < bitfont->firstChar() || ascii > bitfont->lastChar()) |
224 | ascii = toupper(ascii); | 224 | ascii = toupper(ascii); |
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 | if (highscoreFile.open(IO_WriteOnly)) { | 481 | if (highscoreFile.open(IO_WriteOnly)) { |
482 | QDataStream s(&highscoreFile); | 482 | QDataStream s(&highscoreFile); |
483 | for (int i = 0; i < 10; i++) | 483 | for (int i = 0; i < 10; i++) |
484 | s << hallOfFame[i].points << hallOfFame[i].levels << hallOfFame[i].duration << | 484 | s << hallOfFame[i].points << hallOfFame[i].levels << hallOfFame[i].duration << |
485 | hallOfFame[i].moment << hallOfFame[i].name.latin1(); | 485 | hallOfFame[i].moment << hallOfFame[i].name.latin1(); |
486 | highscoreFile.close(); | 486 | highscoreFile.close(); |
487 | } | 487 | } |
488 | } | 488 | } |
489 | 489 | ||
490 | void Score::setPause(bool Paused) | 490 | void Score::setPause(bool Paused) |
491 | { | 491 | { |
492 | paused = Paused; | 492 | paused = Paused; |
493 | 493 | ||
494 | QRect r = bitfont->rect(tr("PAUSED")); | 494 | QRect r = bitfont->rect(tr("PAUSED")); |
495 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); | 495 | r.moveCenter(QPoint(this->width()/2, this->height()/2)); |
496 | repaint(r, TRUE); | 496 | repaint(r, TRUE); |
497 | 497 | ||
498 | // repaint 1UP or 2UP | 498 | // repaint 1UP or 2UP |
499 | repaint(FALSE); | 499 | repaint(FALSE); |
500 | } | 500 | } |
501 | 501 | ||
502 | void Score::end() | 502 | void Score::end() |
503 | { | 503 | { |
504 | if (paused) { | 504 | if (paused) { |
505 | QTimer::singleShot(afterPauseMS, this, SLOT(end())); | 505 | QTimer::singleShot(afterPauseMS, this, SLOT(end())); |
506 | return; | 506 | return; |
507 | } | 507 | } |
508 | 508 | ||
509 | // repaint 1UP or 2UP | 509 | // repaint 1UP or 2UP |
510 | lastPlayer = -1; | 510 | lastPlayer = -1; |
511 | repaint(FALSE); | 511 | repaint(FALSE); |
512 | 512 | ||
513 | emit forcedHallOfFame(FALSE); | 513 | emit forcedHallOfFame(FALSE); |
514 | } | 514 | } |
515 | 515 | ||
516 | /* | 516 | /* |
517 | * 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 |
518 | * 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". |
519 | */ | 519 | */ |
520 | QString Score::formatDate(QDate date) | 520 | QString Score::formatDate(QDate date) |
521 | { | 521 | { |
522 | QString s = tr("@YY@/@MM@/@DD@"); | 522 | QString s = tr("@YY@/@MM@/@DD@"); |
523 | 523 | ||
524 | QString dd; | 524 | QString dd; |
525 | dd.sprintf("%02d", date.isValid() ? date.year() % 100 : 0); | 525 | dd.sprintf("%02d", date.isValid() ? date.year() % 100 : 0); |
526 | s.replace(QRegExp("@YY@"), dd); | 526 | s.replace(QRegExp("@YY@"), dd); |
527 | dd.sprintf("%02d", date.isValid() ? date.month() : 0); | 527 | dd.sprintf("%02d", date.isValid() ? date.month() : 0); |
528 | s.replace(QRegExp("@MM@"), dd); | 528 | s.replace(QRegExp("@MM@"), dd); |
529 | dd.sprintf("%02d", date.isValid() ? date.day() : 0); | 529 | dd.sprintf("%02d", date.isValid() ? date.day() : 0); |
530 | s.replace(QRegExp("@DD@"), dd); | 530 | s.replace(QRegExp("@DD@"), dd); |
531 | 531 | ||
532 | return s; | 532 | return s; |
533 | } | 533 | } |
534 | 534 | ||
535 | QRect Score::rect(int col, float row, QString str, int align) | 535 | QRect Score::rect(int col, float row, QString str, int align) |
536 | { | 536 | { |
537 | QRect r = bitfont->rect(str); | 537 | QRect r = bitfont->rect(str); |
538 | r.moveBy(x(col), y(row)); | 538 | r.moveBy(x(col), y(row)); |
539 | 539 | ||
540 | int dx = 0; | 540 | int dx = 0; |
541 | int dy = 0; | 541 | int dy = 0; |
542 | 542 | ||
543 | if (align & AlignLeft || align & AlignRight) { | 543 | if (align & AlignLeft || align & AlignRight) { |
544 | dx = (str.length()-1) * (bitfont->width()/2); | 544 | dx = (str.length()-1) * (bitfont->width()/2); |
545 | if (align & AlignRight) | 545 | if (align & AlignRight) |
546 | dx *= -1; | 546 | dx *= -1; |
547 | } | 547 | } |
548 | 548 | ||
549 | if (align & AlignTop || align & AlignBottom) { | 549 | if (align & AlignTop || align & AlignBottom) { |
550 | dy = bitfont->height()/2; | 550 | dy = bitfont->height()/2; |
551 | if (align & AlignBottom) | 551 | if (align & AlignBottom) |
552 | dy *= -1; | 552 | dy *= -1; |
553 | } | 553 | } |
554 | 554 | ||
555 | if (dx != 0 || dy != 0) | 555 | if (dx != 0 || dy != 0) |
556 | r.moveBy(dx, dy); | 556 | r.moveBy(dx, dy); |
557 | 557 | ||
558 | return r; | 558 | return r; |
559 | } | 559 | } |
560 | 560 | ||
561 | int Score::x(int col) | 561 | int Score::x(int col) |
562 | { | 562 | { |
563 | return col*bitfont->width(); | 563 | return col*bitfont->width(); |
564 | } | 564 | } |
565 | 565 | ||
566 | int Score::y(float row) | 566 | int Score::y(float row) |
567 | { | 567 | { |
568 | return (int) (row*(bitfont->height()+bitfont->height()/4)); | 568 | return (int) (row*(bitfont->height()+bitfont->height()/4)); |
569 | } | 569 | } |
570 | 570 | ||
571 | /** | 571 | /** |
572 | * 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. |
573 | * Über den "highscoreFilePath"-KConfig-Eintrag, kann abweichend von der Standardlokation | 573 | * Über den "highscoreFilePath"-KConfig-Eintrag, kann abweichend von der Standardlokation |
574 | * der Standort der "highscore"-Datei spezifiziert werden. | 574 | * der Standort der "highscore"-Datei spezifiziert werden. |
575 | * 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 |
576 | * privaten Datei gearbeitet. | 576 | * privaten Datei gearbeitet. |
577 | */ | 577 | */ |
578 | QFileInfo Score::locateHighscoreFilePath() | 578 | QFileInfo Score::locateHighscoreFilePath() |
579 | { | 579 | { |
580 | return privateHighscoreFileInfo; | 580 | return privateHighscoreFileInfo; |
581 | } | 581 | } |