-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,207 +1,207 @@ | |||
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; |