summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2010-02-22 13:45:24 +0000
committerTeruaki Kawashima <teru@rockbox.org>2010-02-22 13:45:24 +0000
commitc1bb06c3af4c5277e4a08c0084da86a69bc9d127 (patch)
tree28b3e52221e064c4f08a2229a2f7df2e4fe17263 /apps
parentadf5bbdc46529785ae988944f005863823b26722 (diff)
downloadrockbox-c1bb06c3af4c5277e4a08c0084da86a69bc9d127.tar.gz
rockbox-c1bb06c3af4c5277e4a08c0084da86a69bc9d127.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/lib/highscore.c48
-rw-r--r--apps/plugins/lib/highscore.h6
-rw-r--r--apps/plugins/rockblox.c13
3 files changed, 49 insertions, 18 deletions
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c
index 20e472f9dc..9ada06e8fe 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,
120} 120}
121 121
122#ifdef HAVE_LCD_BITMAP 122#ifdef HAVE_LCD_BITMAP
123void highscore_show(int position, struct highscore *scores, int num_scores, bool show_level) 123#define MARGIN 5
124void highscore_show(int position, struct highscore *scores, int num_scores,
125 bool show_level)
124{ 126{
125 int i, w, h; 127 int i, w, h;
126 char str[30]; 128 char str[30];
127#define MARGIN 5
128#ifdef HAVE_LCD_COLOR 129#ifdef HAVE_LCD_COLOR
130 unsigned bgcolor = rb->lcd_get_background();
131 unsigned fgcolor = rb->lcd_get_foreground();
129 rb->lcd_set_background(LCD_BLACK); 132 rb->lcd_set_background(LCD_BLACK);
130 rb->lcd_set_foreground(LCD_WHITE); 133 rb->lcd_set_foreground(LCD_WHITE);
131#endif 134#endif
@@ -141,7 +144,6 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool
141 rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); 144 rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores");
142 rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); 145 rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score");
143 146
144 /* Decide whether to display the level column or not */
145 if(show_level) { 147 if(show_level) {
146 rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); 148 rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level");
147 } 149 }
@@ -158,7 +160,6 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool
158 rb->snprintf (str, sizeof (str), "%d", scores[i].score); 160 rb->snprintf (str, sizeof (str), "%d", scores[i].score);
159 rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); 161 rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
160 162
161 /* Decide whether to display the level column or not */
162 if(show_level) { 163 if(show_level) {
163 rb->snprintf (str, sizeof (str), "%d", scores[i].level); 164 rb->snprintf (str, sizeof (str), "%d", scores[i].level);
164 rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); 165 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
168#ifdef HAVE_LCD_COLOR 169#ifdef HAVE_LCD_COLOR
169 rb->lcd_set_foreground(LCD_WHITE); 170 rb->lcd_set_foreground(LCD_WHITE);
170#else 171#else
171 rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)); 172 rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN*2, 3*h + h*(i+1) - 1);
172#endif 173#endif
173 } 174 }
174 } 175 }
@@ -177,5 +178,42 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool
177 rb->button_clear_queue(); 178 rb->button_clear_queue();
178 rb->button_get(true); 179 rb->button_get(true);
179 rb->lcd_setfont(FONT_SYSFIXED); 180 rb->lcd_setfont(FONT_SYSFIXED);
181#ifdef HAVE_LCD_COLOR
182 rb->lcd_set_background(bgcolor);
183 rb->lcd_set_foreground(fgcolor);
184#endif
185}
186#else
187struct scoreinfo {
188 struct highscore *scores;
189 int position;
190 bool show_level;
191};
192static const char* get_score(int selected, void * data,
193 char * buffer, size_t buffer_len)
194{
195 struct scoreinfo *scoreinfo = (struct scoreinfo *) data;
196 int len;
197 len = rb->snprintf(buffer, buffer_len, "%c%d) %4d",
198 (scoreinfo->position == selected?'*':' '),
199 selected+1, scoreinfo->scores[selected].score);
200
201 if (scoreinfo->show_level)
202 rb->snprintf(buffer + len, buffer_len - len, " %d",
203 scoreinfo->scores[selected].level);
204 return buffer;
205}
206
207void highscore_show(int position, struct highscore *scores, int num_scores,
208 bool show_level)
209{
210 struct simplelist_info info;
211 struct scoreinfo scoreinfo = {scores, position, show_level};
212 rb->simplelist_info_init(&info, "High Scores", num_scores, &scoreinfo);
213 if (position >= 0)
214 info.selection = position;
215 info.hide_selection = true;
216 info.get_name = get_score;
217 rb->simplelist_show_list(&info);
180} 218}
181#endif /* HAVE_LCD_BITMAP */ 219#endif /* HAVE_LCD_BITMAP */
diff --git a/apps/plugins/lib/highscore.h b/apps/plugins/lib/highscore.h
index 18c14a7662..b1b6a040ac 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,
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 85/* 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 86 * the highscore table doesn't fit on the the display size it uses
88 * FONT_SYSFIXED. 87 * FONT_SYSFIXED.
@@ -90,7 +89,8 @@ bool highscore_would_update(int score, struct highscore *scores,
90 * - position : highlight position line 89 * - position : highlight position line
91 * - scores : the array of existing scores 90 * - scores : the array of existing scores
92 * - num_scores: number of elements in 'scores' 91 * - num_scores: number of elements in 'scores'
92 * - show_level: whether to display the level column or not
93 */ 93 */
94void highscore_show(int position, struct highscore *scores, int num_scores, bool show_level); 94void highscore_show(int position, struct highscore *scores, int num_scores,
95#endif 95 bool show_level);
96#endif 96#endif
diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c
index 6bff1ea5a2..d1dea6cd28 100644
--- a/apps/plugins/rockblox.c
+++ b/apps/plugins/rockblox.c
@@ -1282,11 +1282,7 @@ static int rockblox_menu(void)
1282 return 1; 1282 return 1;
1283 break; 1283 break;
1284 case 3: 1284 case 3:
1285#ifdef HAVE_LCD_BITMAP
1286 highscore_show(MAX_HIGH_SCORES, highest, MAX_HIGH_SCORES, true); 1285 highscore_show(MAX_HIGH_SCORES, highest, MAX_HIGH_SCORES, true);
1287#else
1288 rb->splashf(2*HZ, "High Score: %d", highest[0].score);
1289#endif
1290 break; 1286 break;
1291 case 4: 1287 case 4:
1292 if (playback_control(NULL)) 1288 if (playback_control(NULL))
@@ -1511,17 +1507,14 @@ enum plugin_status plugin_start (const void *parameter)
1511 resume_file = resume; 1507 resume_file = resume;
1512 while(!rockblox_loop()) { 1508 while(!rockblox_loop()) {
1513 if(!resume) { 1509 if(!resume) {
1514 int position = highscore_update(rockblox_status.score, rockblox_status.level, "", highest, 1510 int position = highscore_update(rockblox_status.score,
1515 MAX_HIGH_SCORES); 1511 rockblox_status.level, "",
1512 highest, MAX_HIGH_SCORES);
1516 if (position == 0) { 1513 if (position == 0) {
1517 rb->splash(HZ*2, "New High Score"); 1514 rb->splash(HZ*2, "New High Score");
1518 } 1515 }
1519 if (position != -1) { 1516 if (position != -1) {
1520#ifdef HAVE_LCD_BITMAP
1521 highscore_show(position, highest, MAX_HIGH_SCORES, true); 1517 highscore_show(position, highest, MAX_HIGH_SCORES, true);
1522#else
1523 rb->splashf(2*HZ, "High Score: %d", highest[position].score);
1524#endif
1525 } 1518 }
1526 } 1519 }
1527 } 1520 }