summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/highscore.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/highscore.c')
-rw-r--r--apps/plugins/lib/highscore.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c
index 15ebb05..909c3a8 100644
--- a/apps/plugins/lib/highscore.c
+++ b/apps/plugins/lib/highscore.c
@@ -21,6 +21,8 @@
#include "plugin.h"
#include "highscore.h"
+static bool highscore_updated = false;
+
int highscore_save(char *filename, struct highscore *scores, int num_scores)
{
int i;
@@ -28,6 +30,9 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores)
int rc;
char buf[80];
+ if(!highscore_updated)
+ return 1;
+
fd = rb->open(filename, O_WRONLY|O_CREAT);
if(fd < 0)
return -1;
@@ -44,6 +49,7 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores)
}
}
rb->close(fd);
+ highscore_updated = false;
return 0;
}
@@ -76,6 +82,7 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores)
i++;
}
rb->close(fd);
+ highscore_updated = false;
return 0;
}
@@ -102,6 +109,7 @@ int highscore_update(int score, int level, const char *name,
entry->level = level;
rb->strlcpy(entry->name, name, sizeof(entry->name));
+ highscore_updated = true;
return pos;
}
@@ -110,3 +118,54 @@ bool highscore_would_update(int score, struct highscore *scores,
{
return (num_scores > 0) && (score > scores[num_scores-1].score);
}
+
+#ifdef HAVE_LCD_BITMAP
+void highscore_show(int position, struct highscore *scores, int num_scores)
+{
+ int i, w, h;
+ char str[30];
+#define MARGIN 5
+#ifdef HAVE_LCD_COLOR
+ rb->lcd_set_background(LCD_BLACK);
+ rb->lcd_set_foreground(LCD_WHITE);
+#endif
+ rb->button_clear_queue();
+ rb->lcd_clear_display();
+
+ rb->lcd_setfont(FONT_UI);
+ rb->lcd_getstringsize("High Scores", &w, &h);
+ /* check wether it fits on screen */
+ if ((4*h + h*(num_scores-1) + MARGIN) > LCD_HEIGHT) {
+ rb->lcd_setfont(FONT_SYSFIXED);
+ rb->lcd_getstringsize("High Scores", &w, &h);
+ }
+ 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*3/4-w/4,2*h, "Level");
+
+ for (i = 0; i<num_scores; i++)
+ {
+#ifdef HAVE_LCD_COLOR
+ if (i == position) {
+ rb->lcd_set_foreground(LCD_RGBPACK(245,0,0));
+ }
+#endif
+ rb->snprintf (str, sizeof (str), "%d)", i+1);
+ rb->lcd_putsxy (MARGIN,3*h + h*i, str);
+ rb->snprintf (str, sizeof (str), "%d", scores[i].score);
+ rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
+ rb->snprintf (str, sizeof (str), "%d", scores[i].level);
+ rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str);
+ if(i == position) {
+#ifdef HAVE_LCD_COLOR
+ rb->lcd_set_foreground(LCD_WHITE);
+#else
+ rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1));
+#endif
+ }
+ }
+ rb->lcd_update();
+ rb->button_get(true);
+ rb->lcd_setfont(FONT_SYSFIXED);
+}
+#endif /* HAVE_LCD_BITMAP */