Index: apps/plugins/lib/highscore.c =================================================================== --- apps/plugins/lib/highscore.c (Revision 21906) +++ apps/plugins/lib/highscore.c (Arbeitskopie) @@ -21,8 +21,13 @@ #include "plugin.h" #include "highscore.h" +static bool highest_updated = false; + int highscore_save(char *filename, struct highscore *scores, int num_scores) { + if (!highest_updated && num_scores > 1) + return 1; + int i; int fd; int rc; @@ -102,6 +107,7 @@ entry->level = level; rb->strlcpy(entry->name, name, sizeof(entry->name)); + highest_updated = true; return pos; } @@ -110,3 +116,52 @@ { return (num_scores > 0) && (score > scores[num_scores-1].score); } + +void show_highscores(int position, struct highscore *scores, int num_scores) +{ + int i, w, h; + char str[30]; +#define MARGIN 5 +#ifdef HAVE_LCD_COLOR + rb->lcd_set_background(LCD_BLACK); + rb->lcd_set_foreground(LCD_WHITE); +#endif + rb->button_clear_queue(); + rb->lcd_clear_display(); + + rb->lcd_setfont(FONT_UI); + rb->lcd_getstringsize("High Scores", &w, &h); + /* check wether it fits on screen */ + if ((4*h + h*(num_scores-1) + MARGIN) > LCD_HEIGHT) { + rb->lcd_setfont(FONT_SYSFIXED); + rb->lcd_getstringsize("High Scores", &w, &h); + } + rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); + rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); + rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); + + for (i = 0; ilcd_set_foreground(LCD_RGBPACK(245,0,0)); + } +#endif + rb->snprintf (str, sizeof (str), "%d)", i+1); + rb->lcd_putsxy (MARGIN,3*h + h*i, str); + rb->snprintf (str, sizeof (str), "%d", scores[i].score); + rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); + rb->snprintf (str, sizeof (str), "%d", scores[i].level); + rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); + if(i == position) { +#ifdef HAVE_LCD_COLOR + rb->lcd_set_foreground(LCD_WHITE); +#else + rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)); +#endif + } + } + rb->lcd_update(); + rb->button_get(true); + rb->lcd_setfont(FONT_SYSFIXED); +} Index: apps/plugins/lib/highscore.h =================================================================== --- apps/plugins/lib/highscore.h (Revision 21906) +++ apps/plugins/lib/highscore.h (Arbeitskopie) @@ -82,4 +82,13 @@ bool highscore_would_update(int score, struct highscore *scores, int num_scores); +/* Displays a nice highscore table. In general the font is FONT_UI, but if + * the highscore table doesn't fit on the the display size it uses + * FONT_SYSFIXED. + * + * - position : highlight position line + * - scores : the array of existing scores + * - num_scores: number of elements in 'scores' + */ +void show_highscores(int position, struct highscore *scores, int num_scores); #endif