forked from len0rd/rockbox
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
This commit is contained in:
parent
03cb2b83ae
commit
99f5299996
6 changed files with 100 additions and 210 deletions
|
@ -1235,7 +1235,6 @@ struct tile {
|
||||||
* elapsedshot is the shot elapsed time in 1/100s of seconds
|
* elapsedshot is the shot elapsed time in 1/100s of seconds
|
||||||
* startedshot is when the current shot began
|
* startedshot is when the current shot began
|
||||||
* resume denotes whether to resume the currently loaded game
|
* resume denotes whether to resume the currently loaded game
|
||||||
* dirty denotes whether the high scores are out of sync with the saved file
|
|
||||||
* playboard is the game playing board
|
* playboard is the game playing board
|
||||||
*/
|
*/
|
||||||
struct game_context {
|
struct game_context {
|
||||||
|
@ -1254,7 +1253,6 @@ struct game_context {
|
||||||
long elapsedshot;
|
long elapsedshot;
|
||||||
long startedshot;
|
long startedshot;
|
||||||
bool resume;
|
bool resume;
|
||||||
bool dirty;
|
|
||||||
struct tile playboard[BB_HEIGHT][BB_WIDTH];
|
struct tile playboard[BB_HEIGHT][BB_WIDTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1272,7 +1270,6 @@ static void bubbles_anchored(struct game_context* bb, int row, int col);
|
||||||
static int bubbles_fall(struct game_context* bb);
|
static int bubbles_fall(struct game_context* bb);
|
||||||
static int bubbles_checklevel(struct game_context* bb);
|
static int bubbles_checklevel(struct game_context* bb);
|
||||||
static void bubbles_recordscore(struct game_context* bb);
|
static void bubbles_recordscore(struct game_context* bb);
|
||||||
static void bubbles_displayscores(struct game_context* bb, int position);
|
|
||||||
static void bubbles_savescores(struct game_context* bb);
|
static void bubbles_savescores(struct game_context* bb);
|
||||||
static bool bubbles_loadgame(struct game_context* bb);
|
static bool bubbles_loadgame(struct game_context* bb);
|
||||||
static void bubbles_savegame(struct game_context* bb);
|
static void bubbles_savegame(struct game_context* bb);
|
||||||
|
@ -1286,6 +1283,7 @@ static int bubbles(struct game_context* bb);
|
||||||
* bubbles_init() initializes bubbles data structures.
|
* bubbles_init() initializes bubbles data structures.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
static void bubbles_init(struct game_context* bb) {
|
static void bubbles_init(struct game_context* bb) {
|
||||||
|
bubbles_setcolors();
|
||||||
/* seed the rand generator */
|
/* seed the rand generator */
|
||||||
rb->srand(*rb->current_tick);
|
rb->srand(*rb->current_tick);
|
||||||
|
|
||||||
|
@ -2113,15 +2111,12 @@ static void bubbles_recordscore(struct game_context* bb) {
|
||||||
|
|
||||||
int position;
|
int position;
|
||||||
|
|
||||||
if (highscore_would_update(bb->score, bb->highscores, NUM_SCORES)) {
|
position = highscore_update(bb->score, bb->level, "",
|
||||||
bb->dirty = true;
|
bb->highscores, NUM_SCORES);
|
||||||
position = highscore_update(bb->score, bb->level, "",
|
if (position==0)
|
||||||
bb->highscores, NUM_SCORES);
|
rb->splash(HZ*2, "New High Score");
|
||||||
if (position==0) {
|
if (position != -1)
|
||||||
rb->splash(HZ*2, "New High Score");
|
highscore_show(position, bb->highscores, NUM_SCORES);
|
||||||
}
|
|
||||||
bubbles_displayscores(bb, position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -2129,8 +2124,6 @@ static void bubbles_recordscore(struct game_context* bb) {
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
static void bubbles_loadscores(struct game_context* bb) {
|
static void bubbles_loadscores(struct game_context* bb) {
|
||||||
|
|
||||||
bb->dirty = false;
|
|
||||||
|
|
||||||
/* highlevel and highscores */
|
/* highlevel and highscores */
|
||||||
highscore_load(SCORE_FILE, &bb->highlevel, NUM_SCORES+1);
|
highscore_load(SCORE_FILE, &bb->highlevel, NUM_SCORES+1);
|
||||||
|
|
||||||
|
@ -2145,60 +2138,6 @@ static void bubbles_savescores(struct game_context* bb) {
|
||||||
|
|
||||||
/* highlevel and highscores */
|
/* highlevel and highscores */
|
||||||
highscore_save(SCORE_FILE, &bb->highlevel, NUM_SCORES+1);
|
highscore_save(SCORE_FILE, &bb->highlevel, NUM_SCORES+1);
|
||||||
bb->dirty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* bubbles_displayscores() displays the high scores
|
|
||||||
******************************************************************************/
|
|
||||||
#define MARGIN 5
|
|
||||||
static void bubbles_displayscores(struct game_context* bb, int position) {
|
|
||||||
int i, w, h;
|
|
||||||
char str[30];
|
|
||||||
|
|
||||||
#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", bb->highscores[i].score);
|
|
||||||
rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
|
|
||||||
rb->snprintf (str, sizeof (str), "%d", bb->highscores[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)-1);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rb->lcd_update();
|
|
||||||
rb->button_get(true);
|
|
||||||
rb->lcd_setfont(FONT_SYSFIXED);
|
|
||||||
bubbles_setcolors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -2277,10 +2216,7 @@ static inline void bubbles_setcolors(void) {
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
static void bubbles_callback(void* param) {
|
static void bubbles_callback(void* param) {
|
||||||
struct game_context* bb = (struct game_context*) param;
|
struct game_context* bb = (struct game_context*) param;
|
||||||
if(bb->dirty) {
|
bubbles_savescores(bb);
|
||||||
rb->splash(HZ/2, "Saving high scores...");
|
|
||||||
bubbles_savescores(bb);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -2376,8 +2312,6 @@ static int bubbles(struct game_context* bb) {
|
||||||
bool startgame = false;
|
bool startgame = false;
|
||||||
long timeout;
|
long timeout;
|
||||||
|
|
||||||
bubbles_setcolors();
|
|
||||||
|
|
||||||
/* don't resume by default */
|
/* don't resume by default */
|
||||||
bb->resume = false;
|
bb->resume = false;
|
||||||
|
|
||||||
|
@ -2409,7 +2343,7 @@ static int bubbles(struct game_context* bb) {
|
||||||
startlevel--;
|
startlevel--;
|
||||||
break;
|
break;
|
||||||
case 3: /* High scores */
|
case 3: /* High scores */
|
||||||
bubbles_displayscores(bb, 0);
|
highscore_show(NUM_SCORES, bb->highscores, NUM_SCORES);
|
||||||
break;
|
break;
|
||||||
case 4: /* Playback Control */
|
case 4: /* Playback Control */
|
||||||
playback_control(NULL);
|
playback_control(NULL);
|
||||||
|
@ -2494,7 +2428,6 @@ enum plugin_status plugin_start(const void* parameter) {
|
||||||
/* record high level */
|
/* record high level */
|
||||||
if( NUM_LEVELS-1 > bb.highlevel.level) {
|
if( NUM_LEVELS-1 > bb.highlevel.level) {
|
||||||
bb.highlevel.level = NUM_LEVELS-1;
|
bb.highlevel.level = NUM_LEVELS-1;
|
||||||
bb.dirty = true;
|
|
||||||
}
|
}
|
||||||
/* record high score */
|
/* record high score */
|
||||||
bubbles_recordscore(&bb);
|
bubbles_recordscore(&bb);
|
||||||
|
@ -2508,8 +2441,8 @@ enum plugin_status plugin_start(const void* parameter) {
|
||||||
if(!bb.resume) {
|
if(!bb.resume) {
|
||||||
/* record high level */
|
/* record high level */
|
||||||
if((int)bb.level-1 > bb.highlevel.level) {
|
if((int)bb.level-1 > bb.highlevel.level) {
|
||||||
bb.highlevel.level = bb.level-1;
|
bb.highlevel.score = -1;
|
||||||
bb.dirty = true;
|
highscore_update(0, bb.level-1, "", &bb.highlevel, 1);
|
||||||
}
|
}
|
||||||
/* record high score */
|
/* record high score */
|
||||||
bubbles_recordscore(&bb);
|
bubbles_recordscore(&bb);
|
||||||
|
@ -2521,10 +2454,7 @@ enum plugin_status plugin_start(const void* parameter) {
|
||||||
return PLUGIN_USB_CONNECTED;
|
return PLUGIN_USB_CONNECTED;
|
||||||
|
|
||||||
case BB_QUIT:
|
case BB_QUIT:
|
||||||
if(bb.dirty) {
|
bubbles_savescores(&bb);
|
||||||
rb->splash(HZ/2, "Saving high scores...");
|
|
||||||
bubbles_savescores(&bb);
|
|
||||||
}
|
|
||||||
exit = true;
|
exit = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -242,56 +242,6 @@ enum {
|
||||||
CC_DARK_GREEN
|
CC_DARK_GREEN
|
||||||
};
|
};
|
||||||
|
|
||||||
/* display the highscore list and highlight the last one */
|
|
||||||
static void clix_show_highscores(int position)
|
|
||||||
{
|
|
||||||
int i, w, h;
|
|
||||||
char str[30];
|
|
||||||
|
|
||||||
#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", highest[i].score);
|
|
||||||
rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
|
|
||||||
rb->snprintf (str, sizeof (str), "%d", highest[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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* recursive function to check if a neighbour cell is of the same color
|
/* recursive function to check if a neighbour cell is of the same color
|
||||||
if so call the function with the neighbours position
|
if so call the function with the neighbours position
|
||||||
*/
|
*/
|
||||||
|
@ -671,7 +621,7 @@ static int clix_menu(struct clix_game_state_t* state, bool ingame)
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
clix_show_highscores(NUM_SCORES);
|
highscore_show(NUM_SCORES, highest, NUM_SCORES);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
playback_control(NULL);
|
playback_control(NULL);
|
||||||
|
@ -827,16 +777,14 @@ static int clix_handle_game(struct clix_game_state_t* state)
|
||||||
clix_draw( state);
|
clix_draw( state);
|
||||||
rb->splash(HZ*2, "Game Over!");
|
rb->splash(HZ*2, "Game Over!");
|
||||||
rb->lcd_clear_display();
|
rb->lcd_clear_display();
|
||||||
if (highscore_would_update(state->score,
|
position=highscore_update(state->score,
|
||||||
highest, NUM_SCORES)) {
|
state->level, "",
|
||||||
position=highscore_update(state->score,
|
highest,NUM_SCORES);
|
||||||
state->level, "",
|
if (position == 0)
|
||||||
highest,NUM_SCORES);
|
rb->splash(HZ*2, "New High Score");
|
||||||
if (position == 0) {
|
if (position != -1)
|
||||||
rb->splash(HZ*2, "New High Score");
|
highscore_show(position, highest,
|
||||||
}
|
NUM_SCORES);
|
||||||
clix_show_highscores(position);
|
|
||||||
}
|
|
||||||
if (clix_menu(state, 0))
|
if (clix_menu(state, 0))
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1723,8 +1723,7 @@ enum plugin_status plugin_start(UNUSED const void* parameter)
|
||||||
rb->splash(HZ * 2, "Game Over");
|
rb->splash(HZ * 2, "Game Over");
|
||||||
if (score > hiscore.score) {
|
if (score > hiscore.score) {
|
||||||
/* Save new hiscore */
|
/* Save new hiscore */
|
||||||
hiscore.score = score;
|
highscore_update(score, level, "Invader", &hiscore, 1);
|
||||||
hiscore.level = level;
|
|
||||||
highscore_save(HISCOREFILE, &hiscore, 1);
|
highscore_save(HISCOREFILE, &hiscore, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -408,7 +408,6 @@ struct puzzle_level puzzle_levels[NUM_PUZZLE_LEVELS] = {
|
||||||
|
|
||||||
#define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score"
|
#define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score"
|
||||||
struct highscore highest[NUM_SCORES];
|
struct highscore highest[NUM_SCORES];
|
||||||
bool highest_updated = false;
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -1249,55 +1248,6 @@ static void jewels_nextlevel(struct game_context* bj) {
|
||||||
bj->score += points;
|
bj->score += points;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void jewels_show_highscores(int position)
|
|
||||||
{
|
|
||||||
int i, w, h;
|
|
||||||
char str[30];
|
|
||||||
|
|
||||||
#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", highest[i].score);
|
|
||||||
rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str);
|
|
||||||
rb->snprintf (str, sizeof (str), "%d", highest[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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool jewels_help(void)
|
static bool jewels_help(void)
|
||||||
{
|
{
|
||||||
rb->lcd_setfont(FONT_UI);
|
rb->lcd_setfont(FONT_UI);
|
||||||
|
@ -1395,7 +1345,7 @@ static int jewels_game_menu(struct game_context* bj, bool ingame)
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
jewels_show_highscores(NUM_SCORES);
|
highscore_show(NUM_SCORES, highest, NUM_SCORES);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
playback_control(NULL);
|
playback_control(NULL);
|
||||||
|
@ -1560,17 +1510,12 @@ static int jewels_main(struct game_context* bj) {
|
||||||
rb->splash(HZ*2, "Game Over!");
|
rb->splash(HZ*2, "Game Over!");
|
||||||
rb->lcd_clear_display();
|
rb->lcd_clear_display();
|
||||||
bj->score += (bj->level-1)*LEVEL_PTS;
|
bj->score += (bj->level-1)*LEVEL_PTS;
|
||||||
if (highscore_would_update(bj->score, highest,
|
position=highscore_update(bj->score, bj->level, "",
|
||||||
NUM_SCORES)) {
|
highest, NUM_SCORES);
|
||||||
position=highscore_update(bj->score,
|
if (position == 0)
|
||||||
bj->level, "",
|
rb->splash(HZ*2, "New High Score");
|
||||||
highest,NUM_SCORES);
|
if (position != -1)
|
||||||
highest_updated = true;
|
highscore_show(position, highest, NUM_SCORES);
|
||||||
if (position == 0) {
|
|
||||||
rb->splash(HZ*2, "New High Score");
|
|
||||||
}
|
|
||||||
jewels_show_highscores(position);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case GAME_TYPE_PUZZLE:
|
case GAME_TYPE_PUZZLE:
|
||||||
rb->splash(2*HZ, "Game Over");
|
rb->splash(2*HZ, "Game Over");
|
||||||
|
@ -1590,7 +1535,6 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
|
|
||||||
/* load high scores */
|
/* load high scores */
|
||||||
highscore_load(HIGH_SCORE,highest,NUM_SCORES);
|
highscore_load(HIGH_SCORE,highest,NUM_SCORES);
|
||||||
highest_updated = false;
|
|
||||||
|
|
||||||
rb->lcd_setfont(FONT_SYSFIXED);
|
rb->lcd_setfont(FONT_SYSFIXED);
|
||||||
#if LCD_DEPTH > 1
|
#if LCD_DEPTH > 1
|
||||||
|
@ -1600,8 +1544,7 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
struct game_context bj;
|
struct game_context bj;
|
||||||
bj.tmp_type = GAME_TYPE_NORMAL;
|
bj.tmp_type = GAME_TYPE_NORMAL;
|
||||||
jewels_main(&bj);
|
jewels_main(&bj);
|
||||||
if(highest_updated)
|
highscore_save(HIGH_SCORE,highest,NUM_SCORES);
|
||||||
highscore_save(HIGH_SCORE,highest,NUM_SCORES);
|
|
||||||
rb->lcd_setfont(FONT_UI);
|
rb->lcd_setfont(FONT_UI);
|
||||||
|
|
||||||
return PLUGIN_OK;
|
return PLUGIN_OK;
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "highscore.h"
|
#include "highscore.h"
|
||||||
|
|
||||||
|
static bool highscore_updated = false;
|
||||||
|
|
||||||
int highscore_save(char *filename, struct highscore *scores, int num_scores)
|
int highscore_save(char *filename, struct highscore *scores, int num_scores)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -28,6 +30,9 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores)
|
||||||
int rc;
|
int rc;
|
||||||
char buf[80];
|
char buf[80];
|
||||||
|
|
||||||
|
if(!highscore_updated)
|
||||||
|
return 1;
|
||||||
|
|
||||||
fd = rb->open(filename, O_WRONLY|O_CREAT);
|
fd = rb->open(filename, O_WRONLY|O_CREAT);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -44,6 +49,7 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb->close(fd);
|
rb->close(fd);
|
||||||
|
highscore_updated = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +82,7 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
rb->close(fd);
|
rb->close(fd);
|
||||||
|
highscore_updated = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +109,7 @@ int highscore_update(int score, int level, const char *name,
|
||||||
entry->level = level;
|
entry->level = level;
|
||||||
rb->strlcpy(entry->name, name, sizeof(entry->name));
|
rb->strlcpy(entry->name, name, sizeof(entry->name));
|
||||||
|
|
||||||
|
highscore_updated = true;
|
||||||
return pos;
|
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);
|
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 */
|
||||||
|
|
|
@ -82,4 +82,15 @@ int highscore_update(int score, int level, const char *name,
|
||||||
bool highscore_would_update(int score, struct highscore *scores,
|
bool highscore_would_update(int score, struct highscore *scores,
|
||||||
int num_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
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue