1
0
Fork 0
forked from len0rd/rockbox

codebuster: save settings only if they are changed.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24082 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2009-12-20 14:00:38 +00:00
parent 0cbf210d76
commit ed1acf037c

View file

@ -64,31 +64,38 @@ struct mm_line {
}; };
const int colors[MAX_COLORS_COUNT] = { const int colors[MAX_COLORS_COUNT] = {
LCD_RGBPACK(252, 233, 79), LCD_RGBPACK(252, 233, 79),
LCD_RGBPACK(206, 92, 0), LCD_RGBPACK(206, 92, 0),
LCD_RGBPACK(143, 89, 2), LCD_RGBPACK(143, 89, 2),
LCD_RGBPACK( 78, 154, 6), LCD_RGBPACK( 78, 154, 6),
/* LCD_RGBPACK( 32, 74, 135), */ /* LCD_RGBPACK( 32, 74, 135), */
LCD_RGBPACK( 52, 101, 164), LCD_RGBPACK( 52, 101, 164),
/* LCD_RGBPACK(114, 159, 207), */ /* LCD_RGBPACK(114, 159, 207), */
LCD_RGBPACK(117, 80, 123), LCD_RGBPACK(117, 80, 123),
/* LCD_RGBPACK(173, 127, 168), */ /* LCD_RGBPACK(173, 127, 168), */
LCD_RGBPACK(164, 0, 0), LCD_RGBPACK(164, 0, 0),
LCD_RGBPACK(238, 238, 236), LCD_RGBPACK(238, 238, 236),
}; };
/* Flags */ /* Flags */
static bool quit, leave, usb; static bool quit, leave, usb;
static bool found, game_ended; static bool found, game_ended;
/* Settings */ /* Settings */
struct settings {
int pieces;
int colors;
int guesses;
bool labeling;
bool framing;
};
static struct settings settings = {
5, 7, 10, false, false,
};
static struct settings old_settings;
static int pieces_count; static int pieces_count;
static int colors_count; static int colors_count;
static int guesses_count; static int guesses_count;
static int pieces_tmp = 5;
static int colors_tmp = 7;
static int guesses_tmp = 10;
static bool labeling = false, framing = false;
/* Display */ /* Display */
#define ALUMINIUM LCD_RGBPACK(136, 138, 133) #define ALUMINIUM LCD_RGBPACK(136, 138, 133)
@ -102,13 +109,12 @@ static bool labeling = false, framing = false;
#define CONFIG_FILE_NAME "codebuster.cfg" #define CONFIG_FILE_NAME "codebuster.cfg"
static struct configdata config[] = { static struct configdata config[] = {
{TYPE_INT, 0, MAX_PIECES_COUNT, { .int_p = &pieces_tmp }, "pieces", NULL}, {TYPE_INT, 0, MAX_PIECES_COUNT, { .int_p = &settings.pieces }, "pieces", NULL},
{TYPE_INT, 0, MAX_COLORS_COUNT, { .int_p = &colors_tmp }, "colors", NULL}, {TYPE_INT, 0, MAX_COLORS_COUNT, { .int_p = &settings.colors }, "colors", NULL},
{TYPE_INT, 0, MAX_GUESSES_COUNT, { .int_p = &guesses_tmp }, "guesses", NULL}, {TYPE_INT, 0, MAX_GUESSES_COUNT, { .int_p = &settings.guesses }, "guesses", NULL},
{TYPE_BOOL, 0, 1, { .bool_p = &labeling }, "labeling", NULL}, {TYPE_BOOL, 0, 1, { .bool_p = &settings.labeling }, "labeling", NULL},
{TYPE_BOOL, 0, 1, { .bool_p = &framing }, "framing", NULL}, {TYPE_BOOL, 0, 1, { .bool_p = &settings.framing }, "framing", NULL},
}; };
static bool settings_changed = false;
static int line_h; static int line_h;
static int piece_w, tick_w; static int piece_w, tick_w;
@ -158,10 +164,10 @@ static void draw_piece(int x, int y, int w, int h, int color_id, bool emph) {
else else
fill_color_rect(x, y, w, h, color); fill_color_rect(x, y, w, h, color);
if (!emph && framing) if (!emph && settings.framing)
rb->lcd_drawrect(x, y, w, h); rb->lcd_drawrect(x, y, w, h);
if (labeling && color_id >= 0) { if (settings.labeling && color_id >= 0) {
char text[2]; char text[2];
rb->snprintf(text, 2, "%d", color_id); rb->snprintf(text, 2, "%d", color_id);
@ -172,8 +178,8 @@ static void draw_piece(int x, int y, int w, int h, int color_id, bool emph) {
/* Compute the score for a given guess (expressed in ticks) */ /* Compute the score for a given guess (expressed in ticks) */
static void validate_guess(struct mm_line* guess) { static void validate_guess(struct mm_line* guess) {
bool solution_match[pieces_count]; bool solution_match[MAX_PIECES_COUNT];
bool guess_match[pieces_count]; bool guess_match[MAX_PIECES_COUNT];
guess->score.misplaced = 0; guess->score.misplaced = 0;
guess->score.correct = 0; guess->score.correct = 0;
@ -290,9 +296,9 @@ static void init_vars(void) {
static void init_board(void) { static void init_board(void) {
pieces_count = pieces_tmp; pieces_count = settings.pieces;
colors_count = colors_tmp; colors_count = settings.colors;
guesses_count = guesses_tmp; guesses_count = settings.guesses;
line_h = GAME_H / (2 * (guesses_count + 2) - 1); line_h = GAME_H / (2 * (guesses_count + 2) - 1);
@ -316,31 +322,31 @@ static void randomize_solution(void) {
static void settings_menu(void) { static void settings_menu(void) {
MENUITEM_STRINGLIST(settings_menu, "Settings", NULL, MENUITEM_STRINGLIST(settings_menu, "Settings", NULL,
"Number of colours", "Number of pegs", "Number of colours", "Number of pegs",
"Number of guesses", "Labels", "Frames"); "Number of guesses",
"Display labels", "Display frames");
int cur_item =0; int cur_item = 0;
bool menu_quit = false; bool menu_quit = false;
while(!menu_quit) { while(!menu_quit) {
switch(rb->do_menu(&settings_menu, &cur_item, NULL, false)) { switch(rb->do_menu(&settings_menu, &cur_item, NULL, false)) {
case 0: case 0:
rb->set_int("Number of colours", "", UNIT_INT, &colors_tmp, rb->set_int("Number of colours", "", UNIT_INT, &settings.colors,
NULL, -1, MAX_COLORS_COUNT, 1, NULL); NULL, -1, MAX_COLORS_COUNT, 1, NULL);
break; break;
case 1: case 1:
rb->set_int("Number of pegs", "", UNIT_INT, &pieces_tmp, rb->set_int("Number of pegs", "", UNIT_INT, &settings.pieces,
NULL, -1, MAX_PIECES_COUNT, 1, NULL); NULL, -1, MAX_PIECES_COUNT, 1, NULL);
break; break;
case 2: case 2:
rb->set_int("Number of guesses", "", UNIT_INT, &guesses_tmp, rb->set_int("Number of guesses", "", UNIT_INT, &settings.guesses,
NULL, -1, MAX_GUESSES_COUNT, 1, NULL); NULL, -1, MAX_GUESSES_COUNT, 1, NULL);
break; break;
case 3: case 3:
rb->set_bool("Display labels", &labeling); rb->set_bool("Display labels", &settings.labeling);
break; break;
case 4: case 4:
rb->set_bool("Display frames", &framing); rb->set_bool("Display frames", &settings.framing);
break; break;
case GO_TO_PREVIOUS: case GO_TO_PREVIOUS:
menu_quit = true; menu_quit = true;
@ -364,10 +370,9 @@ static void main_menu(void) {
MENUITEM_STRINGLIST(main_menu, "Codebuster Menu", menu_cb, MENUITEM_STRINGLIST(main_menu, "Codebuster Menu", menu_cb,
"Resume Game", "Start New Game", "Settings", "Resume Game", "Start New Game", "Settings",
"Playback Control", "Quit"); "Playback Control", "Quit");
int cur_item = 0;
int cur_item =0;
bool menu_quit = false; bool menu_quit = false;
while(!menu_quit) { while(!menu_quit) {
switch(rb->do_menu(&main_menu, &cur_item, NULL, false)) { switch(rb->do_menu(&main_menu, &cur_item, NULL, false)) {
@ -381,7 +386,6 @@ static void main_menu(void) {
break; break;
case 2: case 2:
settings_menu(); settings_menu();
settings_changed = true;
break; break;
case 3: case 3:
playback_control(NULL); playback_control(NULL);
@ -407,7 +411,8 @@ enum plugin_status plugin_start(const void* parameter) {
rb->lcd_set_foreground(LCD_WHITE); rb->lcd_set_foreground(LCD_WHITE);
rb->lcd_set_background(LCD_BLACK); rb->lcd_set_background(LCD_BLACK);
configfile_load(CONFIG_FILE_NAME,config,5,0); configfile_load(CONFIG_FILE_NAME, config, ARRAYLEN(config), 0);
rb->memcpy(&old_settings, &settings, sizeof(settings));
main_menu(); main_menu();
while (!quit) { while (!quit) {
@ -491,18 +496,18 @@ enum plugin_status plugin_start(const void* parameter) {
rb->splash(HZ, "Well done :)"); rb->splash(HZ, "Well done :)");
else else
rb->splash(HZ, "Wooops :("); rb->splash(HZ, "Wooops :(");
do { do {
button = rb->button_get(true); button = rb->button_get(true);
if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
quit = usb = true; quit = usb = true;
} }
} while( ( button == BUTTON_NONE ) } while( ( button == BUTTON_NONE )
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
main_menu(); main_menu();
} }
} }
if (settings_changed) if (rb->memcmp(&old_settings, &settings, sizeof(settings)))
configfile_save(CONFIG_FILE_NAME,config,5,0); configfile_save(CONFIG_FILE_NAME, config, ARRAYLEN(config), 0);
rb->lcd_setfont(FONT_UI); rb->lcd_setfont(FONT_UI);
return (usb) ? PLUGIN_USB_CONNECTED : PLUGIN_OK; return (usb) ? PLUGIN_USB_CONNECTED : PLUGIN_OK;