From 0bdb01179ec84327c406de069affa2d7738eb395 Mon Sep 17 00:00:00 2001 From: teru Date: Mon, 22 Feb 2010 13:45:24 +0000 Subject: [PATCH] plugin: implement highscore_show for player and use it in rockblox. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24861 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/lib/highscore.c | 48 +++++++++++++++++++++++++++++++++++++++----- apps/plugins/lib/highscore.h | 6 +++--- apps/plugins/rockblox.c | 13 +++--------- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c index 20e472f9d..9ada06e8f 100644 --- a/apps/plugins/lib/highscore.c +++ b/apps/plugins/lib/highscore.c @@ -120,12 +120,15 @@ bool highscore_would_update(int score, struct highscore *scores, } #ifdef HAVE_LCD_BITMAP -void highscore_show(int position, struct highscore *scores, int num_scores, bool show_level) +#define MARGIN 5 +void highscore_show(int position, struct highscore *scores, int num_scores, + bool show_level) { int i, w, h; char str[30]; -#define MARGIN 5 #ifdef HAVE_LCD_COLOR + unsigned bgcolor = rb->lcd_get_background(); + unsigned fgcolor = rb->lcd_get_foreground(); rb->lcd_set_background(LCD_BLACK); rb->lcd_set_foreground(LCD_WHITE); #endif @@ -141,7 +144,6 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); - /* Decide whether to display the level column or not */ if(show_level) { rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); } @@ -158,7 +160,6 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool rb->snprintf (str, sizeof (str), "%d", scores[i].score); rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); - /* Decide whether to display the level column or not */ if(show_level) { rb->snprintf (str, sizeof (str), "%d", scores[i].level); rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); @@ -168,7 +169,7 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool #ifdef HAVE_LCD_COLOR rb->lcd_set_foreground(LCD_WHITE); #else - rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)); + rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN*2, 3*h + h*(i+1) - 1); #endif } } @@ -177,5 +178,42 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool rb->button_clear_queue(); rb->button_get(true); rb->lcd_setfont(FONT_SYSFIXED); +#ifdef HAVE_LCD_COLOR + rb->lcd_set_background(bgcolor); + rb->lcd_set_foreground(fgcolor); +#endif +} +#else +struct scoreinfo { + struct highscore *scores; + int position; + bool show_level; +}; +static const char* get_score(int selected, void * data, + char * buffer, size_t buffer_len) +{ + struct scoreinfo *scoreinfo = (struct scoreinfo *) data; + int len; + len = rb->snprintf(buffer, buffer_len, "%c%d) %4d", + (scoreinfo->position == selected?'*':' '), + selected+1, scoreinfo->scores[selected].score); + + if (scoreinfo->show_level) + rb->snprintf(buffer + len, buffer_len - len, " %d", + scoreinfo->scores[selected].level); + return buffer; +} + +void highscore_show(int position, struct highscore *scores, int num_scores, + bool show_level) +{ + struct simplelist_info info; + struct scoreinfo scoreinfo = {scores, position, show_level}; + rb->simplelist_info_init(&info, "High Scores", num_scores, &scoreinfo); + if (position >= 0) + info.selection = position; + info.hide_selection = true; + info.get_name = get_score; + rb->simplelist_show_list(&info); } #endif /* HAVE_LCD_BITMAP */ diff --git a/apps/plugins/lib/highscore.h b/apps/plugins/lib/highscore.h index 18c14a766..b1b6a040a 100644 --- a/apps/plugins/lib/highscore.h +++ b/apps/plugins/lib/highscore.h @@ -82,7 +82,6 @@ int highscore_update(int score, int level, const char *name, bool highscore_would_update(int score, struct highscore *scores, int num_scores); -#ifdef HAVE_LCD_BITMAP /* 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. @@ -90,7 +89,8 @@ bool highscore_would_update(int score, struct highscore *scores, * - position : highlight position line * - scores : the array of existing scores * - num_scores: number of elements in 'scores' + * - show_level: whether to display the level column or not */ -void highscore_show(int position, struct highscore *scores, int num_scores, bool show_level); -#endif +void highscore_show(int position, struct highscore *scores, int num_scores, + bool show_level); #endif diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c index 6bff1ea5a..d1dea6cd2 100644 --- a/apps/plugins/rockblox.c +++ b/apps/plugins/rockblox.c @@ -1282,11 +1282,7 @@ static int rockblox_menu(void) return 1; break; case 3: -#ifdef HAVE_LCD_BITMAP highscore_show(MAX_HIGH_SCORES, highest, MAX_HIGH_SCORES, true); -#else - rb->splashf(2*HZ, "High Score: %d", highest[0].score); -#endif break; case 4: if (playback_control(NULL)) @@ -1511,17 +1507,14 @@ enum plugin_status plugin_start (const void *parameter) resume_file = resume; while(!rockblox_loop()) { if(!resume) { - int position = highscore_update(rockblox_status.score, rockblox_status.level, "", highest, - MAX_HIGH_SCORES); + int position = highscore_update(rockblox_status.score, + rockblox_status.level, "", + highest, MAX_HIGH_SCORES); if (position == 0) { rb->splash(HZ*2, "New High Score"); } if (position != -1) { -#ifdef HAVE_LCD_BITMAP highscore_show(position, highest, MAX_HIGH_SCORES, true); -#else - rb->splashf(2*HZ, "High Score: %d", highest[position].score); -#endif } } } -- 2.11.4.GIT