summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorJohannes Schwarz <ubuntuxer@rockbox.org>2009-07-18 15:16:24 +0000
committerJohannes Schwarz <ubuntuxer@rockbox.org>2009-07-18 15:16:24 +0000
commit99f52999968eb56e8fc9cabbf2ab4f65943ce678 (patch)
tree0e87625df1579f27b3f43141d8a2d20f7b8df248 /apps/plugins/lib
parent03cb2b83ae17d9118ddee69908389fb4cd0484a6 (diff)
downloadrockbox-99f52999968eb56e8fc9cabbf2ab4f65943ce678.zip
rockbox-99f52999968eb56e8fc9cabbf2ab4f65943ce678.tar.gz
rockbox-99f52999968eb56e8fc9cabbf2ab4f65943ce678.tar.bz2
rockbox-99f52999968eb56e8fc9cabbf2ab4f65943ce678.tar.xz
Commit FS#10350, prevents to save an unchanged highscore and move the function show_highscore to the lib
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21960 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r--apps/plugins/lib/highscore.c59
-rw-r--r--apps/plugins/lib/highscore.h11
2 files changed, 70 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 */
diff --git a/apps/plugins/lib/highscore.h b/apps/plugins/lib/highscore.h
index a38a6f7..173e389 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,
bool highscore_would_update(int score, struct highscore *scores,
int num_scores);
+#ifdef HAVE_LCD_BITMAP
+/* 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
+ * FONT_SYSFIXED.
+ *
+ * - position : highlight position line
+ * - scores : the array of existing scores
+ * - num_scores: number of elements in 'scores'
+ */
+void highscore_show(int position, struct highscore *scores, int num_scores);
+#endif
#endif