diff options
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r-- | apps/plugins/lib/highscore.c | 48 | ||||
-rw-r--r-- | apps/plugins/lib/highscore.h | 6 |
2 files changed, 46 insertions, 8 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 |
123 | void highscore_show(int position, struct highscore *scores, int num_scores, bool show_level) | 123 | #define MARGIN 5 |
124 | void 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 | ||
187 | struct scoreinfo { | ||
188 | struct highscore *scores; | ||
189 | int position; | ||
190 | bool show_level; | ||
191 | }; | ||
192 | static 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 | |||
207 | void 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, | |||
82 | bool highscore_would_update(int score, struct highscore *scores, | 82 | bool 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 | */ |
94 | void highscore_show(int position, struct highscore *scores, int num_scores, bool show_level); | 94 | void highscore_show(int position, struct highscore *scores, int num_scores, |
95 | #endif | 95 | bool show_level); |
96 | #endif | 96 | #endif |