diff options
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r-- | apps/plugins/lib/highscore.c | 59 | ||||
-rw-r--r-- | apps/plugins/lib/highscore.h | 11 |
2 files changed, 70 insertions, 0 deletions
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c index 15ebb05f4d..909c3a89ef 100644 --- a/apps/plugins/lib/highscore.c +++ b/apps/plugins/lib/highscore.c | |||
@@ -21,6 +21,8 @@ | |||
21 | #include "plugin.h" | 21 | #include "plugin.h" |
22 | #include "highscore.h" | 22 | #include "highscore.h" |
23 | 23 | ||
24 | static bool highscore_updated = false; | ||
25 | |||
24 | int highscore_save(char *filename, struct highscore *scores, int num_scores) | 26 | int highscore_save(char *filename, struct highscore *scores, int num_scores) |
25 | { | 27 | { |
26 | int i; | 28 | int i; |
@@ -28,6 +30,9 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores) | |||
28 | int rc; | 30 | int rc; |
29 | char buf[80]; | 31 | char buf[80]; |
30 | 32 | ||
33 | if(!highscore_updated) | ||
34 | return 1; | ||
35 | |||
31 | fd = rb->open(filename, O_WRONLY|O_CREAT); | 36 | fd = rb->open(filename, O_WRONLY|O_CREAT); |
32 | if(fd < 0) | 37 | if(fd < 0) |
33 | return -1; | 38 | return -1; |
@@ -44,6 +49,7 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores) | |||
44 | } | 49 | } |
45 | } | 50 | } |
46 | rb->close(fd); | 51 | rb->close(fd); |
52 | highscore_updated = false; | ||
47 | return 0; | 53 | return 0; |
48 | } | 54 | } |
49 | 55 | ||
@@ -76,6 +82,7 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores) | |||
76 | i++; | 82 | i++; |
77 | } | 83 | } |
78 | rb->close(fd); | 84 | rb->close(fd); |
85 | highscore_updated = false; | ||
79 | return 0; | 86 | return 0; |
80 | } | 87 | } |
81 | 88 | ||
@@ -102,6 +109,7 @@ int highscore_update(int score, int level, const char *name, | |||
102 | entry->level = level; | 109 | entry->level = level; |
103 | rb->strlcpy(entry->name, name, sizeof(entry->name)); | 110 | rb->strlcpy(entry->name, name, sizeof(entry->name)); |
104 | 111 | ||
112 | highscore_updated = true; | ||
105 | return pos; | 113 | return pos; |
106 | } | 114 | } |
107 | 115 | ||
@@ -110,3 +118,54 @@ bool highscore_would_update(int score, struct highscore *scores, | |||
110 | { | 118 | { |
111 | return (num_scores > 0) && (score > scores[num_scores-1].score); | 119 | return (num_scores > 0) && (score > scores[num_scores-1].score); |
112 | } | 120 | } |
121 | |||
122 | #ifdef HAVE_LCD_BITMAP | ||
123 | void highscore_show(int position, struct highscore *scores, int num_scores) | ||
124 | { | ||
125 | int i, w, h; | ||
126 | char str[30]; | ||
127 | #define MARGIN 5 | ||
128 | #ifdef HAVE_LCD_COLOR | ||
129 | rb->lcd_set_background(LCD_BLACK); | ||
130 | rb->lcd_set_foreground(LCD_WHITE); | ||
131 | #endif | ||
132 | rb->button_clear_queue(); | ||
133 | rb->lcd_clear_display(); | ||
134 | |||
135 | rb->lcd_setfont(FONT_UI); | ||
136 | rb->lcd_getstringsize("High Scores", &w, &h); | ||
137 | /* check wether it fits on screen */ | ||
138 | if ((4*h + h*(num_scores-1) + MARGIN) > LCD_HEIGHT) { | ||
139 | rb->lcd_setfont(FONT_SYSFIXED); | ||
140 | rb->lcd_getstringsize("High Scores", &w, &h); | ||
141 | } | ||
142 | rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); | ||
143 | rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); | ||
144 | rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); | ||
145 | |||
146 | for (i = 0; i<num_scores; i++) | ||
147 | { | ||
148 | #ifdef HAVE_LCD_COLOR | ||
149 | if (i == position) { | ||
150 | rb->lcd_set_foreground(LCD_RGBPACK(245,0,0)); | ||
151 | } | ||
152 | #endif | ||
153 | rb->snprintf (str, sizeof (str), "%d)", i+1); | ||
154 | rb->lcd_putsxy (MARGIN,3*h + h*i, str); | ||
155 | rb->snprintf (str, sizeof (str), "%d", scores[i].score); | ||
156 | rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); | ||
157 | rb->snprintf (str, sizeof (str), "%d", scores[i].level); | ||
158 | rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); | ||
159 | if(i == position) { | ||
160 | #ifdef HAVE_LCD_COLOR | ||
161 | rb->lcd_set_foreground(LCD_WHITE); | ||
162 | #else | ||
163 | rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)); | ||
164 | #endif | ||
165 | } | ||
166 | } | ||
167 | rb->lcd_update(); | ||
168 | rb->button_get(true); | ||
169 | rb->lcd_setfont(FONT_SYSFIXED); | ||
170 | } | ||
171 | #endif /* HAVE_LCD_BITMAP */ | ||
diff --git a/apps/plugins/lib/highscore.h b/apps/plugins/lib/highscore.h index a38a6f7bf3..173e389b9b 100644 --- a/apps/plugins/lib/highscore.h +++ b/apps/plugins/lib/highscore.h | |||
@@ -82,4 +82,15 @@ 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 | ||
87 | * the highscore table doesn't fit on the the display size it uses | ||
88 | * FONT_SYSFIXED. | ||
89 | * | ||
90 | * - position : highlight position line | ||
91 | * - scores : the array of existing scores | ||
92 | * - num_scores: number of elements in 'scores' | ||
93 | */ | ||
94 | void highscore_show(int position, struct highscore *scores, int num_scores); | ||
95 | #endif | ||
85 | #endif | 96 | #endif |