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
This commit is contained in:
parent
adf5bbdc46
commit
c1bb06c3af
3 changed files with 49 additions and 18 deletions
|
@ -120,12 +120,15 @@ bool highscore_would_update(int score, struct highscore *scores,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#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;
|
int i, w, h;
|
||||||
char str[30];
|
char str[30];
|
||||||
#define MARGIN 5
|
|
||||||
#ifdef HAVE_LCD_COLOR
|
#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_background(LCD_BLACK);
|
||||||
rb->lcd_set_foreground(LCD_WHITE);
|
rb->lcd_set_foreground(LCD_WHITE);
|
||||||
#endif
|
#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/2-w/2, MARGIN, "High Scores");
|
||||||
rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score");
|
rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score");
|
||||||
|
|
||||||
/* Decide whether to display the level column or not */
|
|
||||||
if(show_level) {
|
if(show_level) {
|
||||||
rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "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->snprintf (str, sizeof (str), "%d", scores[i].score);
|
||||||
rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
|
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) {
|
if(show_level) {
|
||||||
rb->snprintf (str, sizeof (str), "%d", scores[i].level);
|
rb->snprintf (str, sizeof (str), "%d", scores[i].level);
|
||||||
rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str);
|
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
|
#ifdef HAVE_LCD_COLOR
|
||||||
rb->lcd_set_foreground(LCD_WHITE);
|
rb->lcd_set_foreground(LCD_WHITE);
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,5 +178,42 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool
|
||||||
rb->button_clear_queue();
|
rb->button_clear_queue();
|
||||||
rb->button_get(true);
|
rb->button_get(true);
|
||||||
rb->lcd_setfont(FONT_SYSFIXED);
|
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 */
|
#endif /* HAVE_LCD_BITMAP */
|
||||||
|
|
|
@ -82,7 +82,6 @@ int highscore_update(int score, int level, const char *name,
|
||||||
bool highscore_would_update(int score, struct highscore *scores,
|
bool highscore_would_update(int score, struct highscore *scores,
|
||||||
int num_scores);
|
int num_scores);
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
|
||||||
/* Displays a nice highscore table. In general the font is FONT_UI, but if
|
/* 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
|
* the highscore table doesn't fit on the the display size it uses
|
||||||
* FONT_SYSFIXED.
|
* FONT_SYSFIXED.
|
||||||
|
@ -90,7 +89,8 @@ bool highscore_would_update(int score, struct highscore *scores,
|
||||||
* - position : highlight position line
|
* - position : highlight position line
|
||||||
* - scores : the array of existing scores
|
* - scores : the array of existing scores
|
||||||
* - num_scores: number of elements in '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);
|
void highscore_show(int position, struct highscore *scores, int num_scores,
|
||||||
#endif
|
bool show_level);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1282,11 +1282,7 @@ static int rockblox_menu(void)
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
#ifdef HAVE_LCD_BITMAP
|
|
||||||
highscore_show(MAX_HIGH_SCORES, highest, MAX_HIGH_SCORES, true);
|
highscore_show(MAX_HIGH_SCORES, highest, MAX_HIGH_SCORES, true);
|
||||||
#else
|
|
||||||
rb->splashf(2*HZ, "High Score: %d", highest[0].score);
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (playback_control(NULL))
|
if (playback_control(NULL))
|
||||||
|
@ -1511,17 +1507,14 @@ enum plugin_status plugin_start (const void *parameter)
|
||||||
resume_file = resume;
|
resume_file = resume;
|
||||||
while(!rockblox_loop()) {
|
while(!rockblox_loop()) {
|
||||||
if(!resume) {
|
if(!resume) {
|
||||||
int position = highscore_update(rockblox_status.score, rockblox_status.level, "", highest,
|
int position = highscore_update(rockblox_status.score,
|
||||||
MAX_HIGH_SCORES);
|
rockblox_status.level, "",
|
||||||
|
highest, MAX_HIGH_SCORES);
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
rb->splash(HZ*2, "New High Score");
|
rb->splash(HZ*2, "New High Score");
|
||||||
}
|
}
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
#ifdef HAVE_LCD_BITMAP
|
|
||||||
highscore_show(position, highest, MAX_HIGH_SCORES, true);
|
highscore_show(position, highest, MAX_HIGH_SCORES, true);
|
||||||
#else
|
|
||||||
rb->splashf(2*HZ, "High Score: %d", highest[position].score);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue