summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJohannes Schwarz <ubuntuxer@rockbox.org>2009-07-18 15:16:24 +0000
committerJohannes Schwarz <ubuntuxer@rockbox.org>2009-07-18 15:16:24 +0000
commit99f52999968eb56e8fc9cabbf2ab4f65943ce678 (patch)
tree0e87625df1579f27b3f43141d8a2d20f7b8df248 /apps
parent03cb2b83ae17d9118ddee69908389fb4cd0484a6 (diff)
downloadrockbox-99f52999968eb56e8fc9cabbf2ab4f65943ce678.tar.gz
rockbox-99f52999968eb56e8fc9cabbf2ab4f65943ce678.zip
Commit FS#10350, prevents to save an unchanged highscore and move the function show_highscore to the lib
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21960 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/bubbles.c94
-rw-r--r--apps/plugins/clix.c70
-rw-r--r--apps/plugins/invadrox.c3
-rw-r--r--apps/plugins/jewels.c73
-rw-r--r--apps/plugins/lib/highscore.c59
-rw-r--r--apps/plugins/lib/highscore.h11
6 files changed, 100 insertions, 210 deletions
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c
index 17848dbcf3..4ed15bd124 100644
--- a/apps/plugins/bubbles.c
+++ b/apps/plugins/bubbles.c
@@ -1235,7 +1235,6 @@ struct tile {
1235 * elapsedshot is the shot elapsed time in 1/100s of seconds 1235 * elapsedshot is the shot elapsed time in 1/100s of seconds
1236 * startedshot is when the current shot began 1236 * startedshot is when the current shot began
1237 * resume denotes whether to resume the currently loaded game 1237 * resume denotes whether to resume the currently loaded game
1238 * dirty denotes whether the high scores are out of sync with the saved file
1239 * playboard is the game playing board 1238 * playboard is the game playing board
1240 */ 1239 */
1241struct game_context { 1240struct game_context {
@@ -1254,7 +1253,6 @@ struct game_context {
1254 long elapsedshot; 1253 long elapsedshot;
1255 long startedshot; 1254 long startedshot;
1256 bool resume; 1255 bool resume;
1257 bool dirty;
1258 struct tile playboard[BB_HEIGHT][BB_WIDTH]; 1256 struct tile playboard[BB_HEIGHT][BB_WIDTH];
1259}; 1257};
1260 1258
@@ -1272,7 +1270,6 @@ static void bubbles_anchored(struct game_context* bb, int row, int col);
1272static int bubbles_fall(struct game_context* bb); 1270static int bubbles_fall(struct game_context* bb);
1273static int bubbles_checklevel(struct game_context* bb); 1271static int bubbles_checklevel(struct game_context* bb);
1274static void bubbles_recordscore(struct game_context* bb); 1272static void bubbles_recordscore(struct game_context* bb);
1275static void bubbles_displayscores(struct game_context* bb, int position);
1276static void bubbles_savescores(struct game_context* bb); 1273static void bubbles_savescores(struct game_context* bb);
1277static bool bubbles_loadgame(struct game_context* bb); 1274static bool bubbles_loadgame(struct game_context* bb);
1278static void bubbles_savegame(struct game_context* bb); 1275static void bubbles_savegame(struct game_context* bb);
@@ -1286,6 +1283,7 @@ static int bubbles(struct game_context* bb);
1286* bubbles_init() initializes bubbles data structures. 1283* bubbles_init() initializes bubbles data structures.
1287******************************************************************************/ 1284******************************************************************************/
1288static void bubbles_init(struct game_context* bb) { 1285static void bubbles_init(struct game_context* bb) {
1286 bubbles_setcolors();
1289 /* seed the rand generator */ 1287 /* seed the rand generator */
1290 rb->srand(*rb->current_tick); 1288 rb->srand(*rb->current_tick);
1291 1289
@@ -2113,15 +2111,12 @@ static void bubbles_recordscore(struct game_context* bb) {
2113 2111
2114 int position; 2112 int position;
2115 2113
2116 if (highscore_would_update(bb->score, bb->highscores, NUM_SCORES)) { 2114 position = highscore_update(bb->score, bb->level, "",
2117 bb->dirty = true; 2115 bb->highscores, NUM_SCORES);
2118 position = highscore_update(bb->score, bb->level, "", 2116 if (position==0)
2119 bb->highscores, NUM_SCORES); 2117 rb->splash(HZ*2, "New High Score");
2120 if (position==0) { 2118 if (position != -1)
2121 rb->splash(HZ*2, "New High Score"); 2119 highscore_show(position, bb->highscores, NUM_SCORES);
2122 }
2123 bubbles_displayscores(bb, position);
2124 }
2125} 2120}
2126 2121
2127/***************************************************************************** 2122/*****************************************************************************
@@ -2129,8 +2124,6 @@ static void bubbles_recordscore(struct game_context* bb) {
2129******************************************************************************/ 2124******************************************************************************/
2130static void bubbles_loadscores(struct game_context* bb) { 2125static void bubbles_loadscores(struct game_context* bb) {
2131 2126
2132 bb->dirty = false;
2133
2134 /* highlevel and highscores */ 2127 /* highlevel and highscores */
2135 highscore_load(SCORE_FILE, &bb->highlevel, NUM_SCORES+1); 2128 highscore_load(SCORE_FILE, &bb->highlevel, NUM_SCORES+1);
2136 2129
@@ -2145,60 +2138,6 @@ static void bubbles_savescores(struct game_context* bb) {
2145 2138
2146 /* highlevel and highscores */ 2139 /* highlevel and highscores */
2147 highscore_save(SCORE_FILE, &bb->highlevel, NUM_SCORES+1); 2140 highscore_save(SCORE_FILE, &bb->highlevel, NUM_SCORES+1);
2148 bb->dirty = false;
2149}
2150
2151/*****************************************************************************
2152* bubbles_displayscores() displays the high scores
2153******************************************************************************/
2154#define MARGIN 5
2155static void bubbles_displayscores(struct game_context* bb, int position) {
2156 int i, w, h;
2157 char str[30];
2158
2159#ifdef HAVE_LCD_COLOR
2160 rb->lcd_set_background(LCD_BLACK);
2161 rb->lcd_set_foreground(LCD_WHITE);
2162#endif
2163 rb->button_clear_queue();
2164 rb->lcd_clear_display();
2165
2166 rb->lcd_setfont(FONT_UI);
2167 rb->lcd_getstringsize("High Scores", &w, &h);
2168 /* check wether it fits on screen */
2169 if ((4*h + h*(NUM_SCORES-1) + MARGIN) > LCD_HEIGHT) {
2170 rb->lcd_setfont(FONT_SYSFIXED);
2171 rb->lcd_getstringsize("High Scores", &w, &h);
2172 }
2173 rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores");
2174 rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score");
2175 rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level");
2176
2177 for (i = 0; i<NUM_SCORES; i++)
2178 {
2179#ifdef HAVE_LCD_COLOR
2180 if(i == position) {
2181 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
2182 }
2183#endif
2184 rb->snprintf (str, sizeof (str), "%d)", i+1);
2185 rb->lcd_putsxy (MARGIN,3*h + h*i, str);
2186 rb->snprintf (str, sizeof (str), "%d", bb->highscores[i].score);
2187 rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
2188 rb->snprintf (str, sizeof (str), "%d", bb->highscores[i].level);
2189 rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str);
2190 if(i == position) {
2191#ifdef HAVE_LCD_COLOR
2192 rb->lcd_set_foreground(LCD_WHITE);
2193#else
2194 rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)-1);
2195#endif
2196 }
2197 }
2198 rb->lcd_update();
2199 rb->button_get(true);
2200 rb->lcd_setfont(FONT_SYSFIXED);
2201 bubbles_setcolors();
2202} 2141}
2203 2142
2204/***************************************************************************** 2143/*****************************************************************************
@@ -2277,10 +2216,7 @@ static inline void bubbles_setcolors(void) {
2277******************************************************************************/ 2216******************************************************************************/
2278static void bubbles_callback(void* param) { 2217static void bubbles_callback(void* param) {
2279 struct game_context* bb = (struct game_context*) param; 2218 struct game_context* bb = (struct game_context*) param;
2280 if(bb->dirty) { 2219 bubbles_savescores(bb);
2281 rb->splash(HZ/2, "Saving high scores...");
2282 bubbles_savescores(bb);
2283 }
2284} 2220}
2285 2221
2286/***************************************************************************** 2222/*****************************************************************************
@@ -2376,8 +2312,6 @@ static int bubbles(struct game_context* bb) {
2376 bool startgame = false; 2312 bool startgame = false;
2377 long timeout; 2313 long timeout;
2378 2314
2379 bubbles_setcolors();
2380
2381 /* don't resume by default */ 2315 /* don't resume by default */
2382 bb->resume = false; 2316 bb->resume = false;
2383 2317
@@ -2409,7 +2343,7 @@ static int bubbles(struct game_context* bb) {
2409 startlevel--; 2343 startlevel--;
2410 break; 2344 break;
2411 case 3: /* High scores */ 2345 case 3: /* High scores */
2412 bubbles_displayscores(bb, 0); 2346 highscore_show(NUM_SCORES, bb->highscores, NUM_SCORES);
2413 break; 2347 break;
2414 case 4: /* Playback Control */ 2348 case 4: /* Playback Control */
2415 playback_control(NULL); 2349 playback_control(NULL);
@@ -2494,7 +2428,6 @@ enum plugin_status plugin_start(const void* parameter) {
2494 /* record high level */ 2428 /* record high level */
2495 if( NUM_LEVELS-1 > bb.highlevel.level) { 2429 if( NUM_LEVELS-1 > bb.highlevel.level) {
2496 bb.highlevel.level = NUM_LEVELS-1; 2430 bb.highlevel.level = NUM_LEVELS-1;
2497 bb.dirty = true;
2498 } 2431 }
2499 /* record high score */ 2432 /* record high score */
2500 bubbles_recordscore(&bb); 2433 bubbles_recordscore(&bb);
@@ -2508,8 +2441,8 @@ enum plugin_status plugin_start(const void* parameter) {
2508 if(!bb.resume) { 2441 if(!bb.resume) {
2509 /* record high level */ 2442 /* record high level */
2510 if((int)bb.level-1 > bb.highlevel.level) { 2443 if((int)bb.level-1 > bb.highlevel.level) {
2511 bb.highlevel.level = bb.level-1; 2444 bb.highlevel.score = -1;
2512 bb.dirty = true; 2445 highscore_update(0, bb.level-1, "", &bb.highlevel, 1);
2513 } 2446 }
2514 /* record high score */ 2447 /* record high score */
2515 bubbles_recordscore(&bb); 2448 bubbles_recordscore(&bb);
@@ -2521,10 +2454,7 @@ enum plugin_status plugin_start(const void* parameter) {
2521 return PLUGIN_USB_CONNECTED; 2454 return PLUGIN_USB_CONNECTED;
2522 2455
2523 case BB_QUIT: 2456 case BB_QUIT:
2524 if(bb.dirty) { 2457 bubbles_savescores(&bb);
2525 rb->splash(HZ/2, "Saving high scores...");
2526 bubbles_savescores(&bb);
2527 }
2528 exit = true; 2458 exit = true;
2529 break; 2459 break;
2530 2460
diff --git a/apps/plugins/clix.c b/apps/plugins/clix.c
index e0cf88bf08..5a4f683e84 100644
--- a/apps/plugins/clix.c
+++ b/apps/plugins/clix.c
@@ -242,56 +242,6 @@ enum {
242 CC_DARK_GREEN 242 CC_DARK_GREEN
243}; 243};
244 244
245/* display the highscore list and highlight the last one */
246static void clix_show_highscores(int position)
247{
248 int i, w, h;
249 char str[30];
250
251#ifdef HAVE_LCD_COLOR
252 rb->lcd_set_background(LCD_BLACK);
253 rb->lcd_set_foreground(LCD_WHITE);
254#endif
255 rb->button_clear_queue();
256 rb->lcd_clear_display();
257
258 rb->lcd_setfont(FONT_UI);
259 rb->lcd_getstringsize("High Scores", &w, &h);
260 /* check wether it fits on screen */
261 if ((4*h + h*(NUM_SCORES-1) + MARGIN) > LCD_HEIGHT) {
262 rb->lcd_setfont(FONT_SYSFIXED);
263 rb->lcd_getstringsize("High Scores", &w, &h);
264 }
265 rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores");
266 rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score");
267 rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level");
268
269 for (i = 0; i<NUM_SCORES; i++)
270 {
271#ifdef HAVE_LCD_COLOR
272 if (i == position) {
273 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
274 }
275#endif
276 rb->snprintf (str, sizeof (str), "%d)", i+1);
277 rb->lcd_putsxy (MARGIN,3*h + h*i, str);
278 rb->snprintf (str, sizeof (str), "%d", highest[i].score);
279 rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
280 rb->snprintf (str, sizeof (str), "%d", highest[i].level);
281 rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str);
282 if(i == position) {
283#ifdef HAVE_LCD_COLOR
284 rb->lcd_set_foreground(LCD_WHITE);
285#else
286 rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1));
287#endif
288 }
289 }
290 rb->lcd_update();
291 rb->button_get(true);
292 rb->lcd_setfont(FONT_SYSFIXED);
293}
294
295/* recursive function to check if a neighbour cell is of the same color 245/* recursive function to check if a neighbour cell is of the same color
296 if so call the function with the neighbours position 246 if so call the function with the neighbours position
297*/ 247*/
@@ -671,7 +621,7 @@ static int clix_menu(struct clix_game_state_t* state, bool ingame)
671 return 1; 621 return 1;
672 break; 622 break;
673 case 3: 623 case 3:
674 clix_show_highscores(NUM_SCORES); 624 highscore_show(NUM_SCORES, highest, NUM_SCORES);
675 break; 625 break;
676 case 4: 626 case 4:
677 playback_control(NULL); 627 playback_control(NULL);
@@ -827,16 +777,14 @@ static int clix_handle_game(struct clix_game_state_t* state)
827 clix_draw( state); 777 clix_draw( state);
828 rb->splash(HZ*2, "Game Over!"); 778 rb->splash(HZ*2, "Game Over!");
829 rb->lcd_clear_display(); 779 rb->lcd_clear_display();
830 if (highscore_would_update(state->score, 780 position=highscore_update(state->score,
831 highest, NUM_SCORES)) { 781 state->level, "",
832 position=highscore_update(state->score, 782 highest,NUM_SCORES);
833 state->level, "", 783 if (position == 0)
834 highest,NUM_SCORES); 784 rb->splash(HZ*2, "New High Score");
835 if (position == 0) { 785 if (position != -1)
836 rb->splash(HZ*2, "New High Score"); 786 highscore_show(position, highest,
837 } 787 NUM_SCORES);
838 clix_show_highscores(position);
839 }
840 if (clix_menu(state, 0)) 788 if (clix_menu(state, 0))
841 return 1; 789 return 1;
842 break; 790 break;
diff --git a/apps/plugins/invadrox.c b/apps/plugins/invadrox.c
index fa7cb81e02..d07bf2878b 100644
--- a/apps/plugins/invadrox.c
+++ b/apps/plugins/invadrox.c
@@ -1723,8 +1723,7 @@ enum plugin_status plugin_start(UNUSED const void* parameter)
1723 rb->splash(HZ * 2, "Game Over"); 1723 rb->splash(HZ * 2, "Game Over");
1724 if (score > hiscore.score) { 1724 if (score > hiscore.score) {
1725 /* Save new hiscore */ 1725 /* Save new hiscore */
1726 hiscore.score = score; 1726 highscore_update(score, level, "Invader", &hiscore, 1);
1727 hiscore.level = level;
1728 highscore_save(HISCOREFILE, &hiscore, 1); 1727 highscore_save(HISCOREFILE, &hiscore, 1);
1729 } 1728 }
1730 1729
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c
index efec63f2cc..77c4030f61 100644
--- a/apps/plugins/jewels.c
+++ b/apps/plugins/jewels.c
@@ -408,7 +408,6 @@ struct puzzle_level puzzle_levels[NUM_PUZZLE_LEVELS] = {
408 408
409#define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score" 409#define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score"
410struct highscore highest[NUM_SCORES]; 410struct highscore highest[NUM_SCORES];
411bool highest_updated = false;
412 411
413 412
414/***************************************************************************** 413/*****************************************************************************
@@ -1249,55 +1248,6 @@ static void jewels_nextlevel(struct game_context* bj) {
1249 bj->score += points; 1248 bj->score += points;
1250} 1249}
1251 1250
1252static void jewels_show_highscores(int position)
1253{
1254 int i, w, h;
1255 char str[30];
1256
1257#ifdef HAVE_LCD_COLOR
1258 rb->lcd_set_background(LCD_BLACK);
1259 rb->lcd_set_foreground(LCD_WHITE);
1260#endif
1261 rb->button_clear_queue();
1262 rb->lcd_clear_display();
1263
1264 rb->lcd_setfont(FONT_UI);
1265 rb->lcd_getstringsize("High Scores", &w, &h);
1266 /* check wether it fits on screen */
1267 if ((4*h + h*(NUM_SCORES-1) + MARGIN) > LCD_HEIGHT) {
1268 rb->lcd_setfont(FONT_SYSFIXED);
1269 rb->lcd_getstringsize("High Scores", &w, &h);
1270 }
1271 rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores");
1272 rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score");
1273 rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level");
1274
1275 for (i = 0; i<NUM_SCORES; i++)
1276 {
1277#ifdef HAVE_LCD_COLOR
1278 if (i == position) {
1279 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
1280 }
1281#endif
1282 rb->snprintf (str, sizeof (str), "%d)", i+1);
1283 rb->lcd_putsxy (MARGIN,3*h + h*i, str);
1284 rb->snprintf (str, sizeof (str), "%d", highest[i].score);
1285 rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
1286 rb->snprintf (str, sizeof (str), "%d", highest[i].level);
1287 rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str);
1288 if(i == position) {
1289#ifdef HAVE_LCD_COLOR
1290 rb->lcd_set_foreground(LCD_WHITE);
1291#else
1292 rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1));
1293#endif
1294 }
1295 }
1296 rb->lcd_update();
1297 rb->button_get(true);
1298 rb->lcd_setfont(FONT_SYSFIXED);
1299}
1300
1301static bool jewels_help(void) 1251static bool jewels_help(void)
1302{ 1252{
1303 rb->lcd_setfont(FONT_UI); 1253 rb->lcd_setfont(FONT_UI);
@@ -1395,7 +1345,7 @@ static int jewels_game_menu(struct game_context* bj, bool ingame)
1395 return 1; 1345 return 1;
1396 break; 1346 break;
1397 case 4: 1347 case 4:
1398 jewels_show_highscores(NUM_SCORES); 1348 highscore_show(NUM_SCORES, highest, NUM_SCORES);
1399 break; 1349 break;
1400 case 5: 1350 case 5:
1401 playback_control(NULL); 1351 playback_control(NULL);
@@ -1560,17 +1510,12 @@ static int jewels_main(struct game_context* bj) {
1560 rb->splash(HZ*2, "Game Over!"); 1510 rb->splash(HZ*2, "Game Over!");
1561 rb->lcd_clear_display(); 1511 rb->lcd_clear_display();
1562 bj->score += (bj->level-1)*LEVEL_PTS; 1512 bj->score += (bj->level-1)*LEVEL_PTS;
1563 if (highscore_would_update(bj->score, highest, 1513 position=highscore_update(bj->score, bj->level, "",
1564 NUM_SCORES)) { 1514 highest, NUM_SCORES);
1565 position=highscore_update(bj->score, 1515 if (position == 0)
1566 bj->level, "", 1516 rb->splash(HZ*2, "New High Score");
1567 highest,NUM_SCORES); 1517 if (position != -1)
1568 highest_updated = true; 1518 highscore_show(position, highest, NUM_SCORES);
1569 if (position == 0) {
1570 rb->splash(HZ*2, "New High Score");
1571 }
1572 jewels_show_highscores(position);
1573 }
1574 break; 1519 break;
1575 case GAME_TYPE_PUZZLE: 1520 case GAME_TYPE_PUZZLE:
1576 rb->splash(2*HZ, "Game Over"); 1521 rb->splash(2*HZ, "Game Over");
@@ -1590,7 +1535,6 @@ enum plugin_status plugin_start(const void* parameter)
1590 1535
1591 /* load high scores */ 1536 /* load high scores */
1592 highscore_load(HIGH_SCORE,highest,NUM_SCORES); 1537 highscore_load(HIGH_SCORE,highest,NUM_SCORES);
1593 highest_updated = false;
1594 1538
1595 rb->lcd_setfont(FONT_SYSFIXED); 1539 rb->lcd_setfont(FONT_SYSFIXED);
1596#if LCD_DEPTH > 1 1540#if LCD_DEPTH > 1
@@ -1600,8 +1544,7 @@ enum plugin_status plugin_start(const void* parameter)
1600 struct game_context bj; 1544 struct game_context bj;
1601 bj.tmp_type = GAME_TYPE_NORMAL; 1545 bj.tmp_type = GAME_TYPE_NORMAL;
1602 jewels_main(&bj); 1546 jewels_main(&bj);
1603 if(highest_updated) 1547 highscore_save(HIGH_SCORE,highest,NUM_SCORES);
1604 highscore_save(HIGH_SCORE,highest,NUM_SCORES);
1605 rb->lcd_setfont(FONT_UI); 1548 rb->lcd_setfont(FONT_UI);
1606 1549
1607 return PLUGIN_OK; 1550 return PLUGIN_OK;
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c
index 15ebb05f4d..909c3a89ef 100644
--- a/apps/plugins/lib/highscore.c
+++ b/apps/plugins/lib/highscore.c
@@ -21,6 +21,8 @@
21#include "plugin.h" 21#include "plugin.h"
22#include "highscore.h" 22#include "highscore.h"
23 23
24static bool highscore_updated = false;
25
24int highscore_save(char *filename, struct highscore *scores, int num_scores) 26int highscore_save(char *filename, struct highscore *scores, int num_scores)
25{ 27{
26 int i; 28 int i;
@@ -28,6 +30,9 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores)
28 int rc; 30 int rc;
29 char buf[80]; 31 char buf[80];
30 32
33 if(!highscore_updated)
34 return 1;
35
31 fd = rb->open(filename, O_WRONLY|O_CREAT); 36 fd = rb->open(filename, O_WRONLY|O_CREAT);
32 if(fd < 0) 37 if(fd < 0)
33 return -1; 38 return -1;
@@ -44,6 +49,7 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores)
44 } 49 }
45 } 50 }
46 rb->close(fd); 51 rb->close(fd);
52 highscore_updated = false;
47 return 0; 53 return 0;
48} 54}
49 55
@@ -76,6 +82,7 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores)
76 i++; 82 i++;
77 } 83 }
78 rb->close(fd); 84 rb->close(fd);
85 highscore_updated = false;
79 return 0; 86 return 0;
80} 87}
81 88
@@ -102,6 +109,7 @@ int highscore_update(int score, int level, const char *name,
102 entry->level = level; 109 entry->level = level;
103 rb->strlcpy(entry->name, name, sizeof(entry->name)); 110 rb->strlcpy(entry->name, name, sizeof(entry->name));
104 111
112 highscore_updated = true;
105 return pos; 113 return pos;
106} 114}
107 115
@@ -110,3 +118,54 @@ bool highscore_would_update(int score, struct highscore *scores,
110{ 118{
111 return (num_scores > 0) && (score > scores[num_scores-1].score); 119 return (num_scores > 0) && (score > scores[num_scores-1].score);
112} 120}
121
122#ifdef HAVE_LCD_BITMAP
123void highscore_show(int position, struct highscore *scores, int num_scores)
124{
125 int i, w, h;
126 char str[30];
127#define MARGIN 5
128#ifdef HAVE_LCD_COLOR
129 rb->lcd_set_background(LCD_BLACK);
130 rb->lcd_set_foreground(LCD_WHITE);
131#endif
132 rb->button_clear_queue();
133 rb->lcd_clear_display();
134
135 rb->lcd_setfont(FONT_UI);
136 rb->lcd_getstringsize("High Scores", &w, &h);
137 /* check wether it fits on screen */
138 if ((4*h + h*(num_scores-1) + MARGIN) > LCD_HEIGHT) {
139 rb->lcd_setfont(FONT_SYSFIXED);
140 rb->lcd_getstringsize("High Scores", &w, &h);
141 }
142 rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores");
143 rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score");
144 rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level");
145
146 for (i = 0; i<num_scores; i++)
147 {
148#ifdef HAVE_LCD_COLOR
149 if (i == position) {
150 rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
151 }
152#endif
153 rb->snprintf (str, sizeof (str), "%d)", i+1);
154 rb->lcd_putsxy (MARGIN,3*h + h*i, str);
155 rb->snprintf (str, sizeof (str), "%d", scores[i].score);
156 rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
157 rb->snprintf (str, sizeof (str), "%d", scores[i].level);
158 rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str);
159 if(i == position) {
160#ifdef HAVE_LCD_COLOR
161 rb->lcd_set_foreground(LCD_WHITE);
162#else
163 rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1));
164#endif
165 }
166 }
167 rb->lcd_update();
168 rb->button_get(true);
169 rb->lcd_setfont(FONT_SYSFIXED);
170}
171#endif /* HAVE_LCD_BITMAP */
diff --git a/apps/plugins/lib/highscore.h b/apps/plugins/lib/highscore.h
index a38a6f7bf3..173e389b9b 100644
--- a/apps/plugins/lib/highscore.h
+++ b/apps/plugins/lib/highscore.h
@@ -82,4 +82,15 @@ int highscore_update(int score, int level, const char *name,
82bool highscore_would_update(int score, struct highscore *scores, 82bool highscore_would_update(int score, struct highscore *scores,
83 int num_scores); 83 int num_scores);
84 84
85#ifdef HAVE_LCD_BITMAP
86/* Displays a nice highscore table. In general the font is FONT_UI, but if
87 * the highscore table doesn't fit on the the display size it uses
88 * FONT_SYSFIXED.
89 *
90 * - position : highlight position line
91 * - scores : the array of existing scores
92 * - num_scores: number of elements in 'scores'
93 */
94void highscore_show(int position, struct highscore *scores, int num_scores);
95#endif
85#endif 96#endif