1
0
Fork 0
forked from len0rd/rockbox

Fix bug #5298 - hard-code the background color in Sokoban to prevent everything else from being potentially unreadable (if the user has set a dark background color).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9894 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Zakk Roberts 2006-05-09 05:36:46 +00:00
parent a0308f8c0a
commit 67faac4368

View file

@ -99,12 +99,13 @@ PLUGIN_HEADER
#endif #endif
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
#define WALL_COLOR LCD_RGBPACK(16,20,180) /* Color of the walls */ #define WALL_COLOR LCD_RGBPACK(16,20,180) /* Color of the walls */
#define FREE_TARGET_COLOR LCD_RGBPACK(251,158,25) /* Color of a 'target' without a block on top */ #define FREE_TARGET_COLOR LCD_RGBPACK(251,158,25) /* Color of a 'target' without a block on top */
#define USED_TARGET_COLOR LCD_RGBPACK(255,255,255) /* Color of a 'target' with a block on top */ #define USED_TARGET_COLOR LCD_RGBPACK(255,255,255) /* Color of a 'target' with a block on top */
#define FREE_BLOCK_COLOR LCD_RGBPACK(22,130,53) /* Color of a block when it's not on a 'target' */ #define FREE_BLOCK_COLOR LCD_RGBPACK(22,130,53) /* Color of a block when it's not on a 'target' */
#define USED_BLOCK_COLOR LCD_RGBPACK(22,130,53) /* Color of a block when it is on a 'target' */ #define USED_BLOCK_COLOR LCD_RGBPACK(22,130,53) /* Color of a block when it is on a 'target' */
#define CHAR_COLOR LCD_BLACK /* Color of the 'character' */ #define CHAR_COLOR LCD_BLACK /* Color of the 'character' */
#define BG_COLOR LCD_RGBPACK(181,199,231) /* Background color. Default Rockbox light blue. */
#elif LCD_DEPTH > 1 #elif LCD_DEPTH > 1
#define MEDIUM_GRAY LCD_BRIGHTNESS(127) #define MEDIUM_GRAY LCD_BRIGHTNESS(127)
@ -122,8 +123,8 @@ static void init_boards(void);
static void update_screen(void); static void update_screen(void);
static bool sokoban_loop(void); static bool sokoban_loop(void);
/* The Location, Undo and LevelInfo structs are OO-flavored. /* The Location, Undo and LevelInfo structs are OO-flavored.
* (oooh!-flavored as Schnueff puts it.) It makes more you have to know, * (oooh!-flavored as Schnueff puts it.) It makes more you have to know,
* but the overall data layout becomes more manageable. */ * but the overall data layout becomes more manageable. */
/* We use the same three values in 2 structs. Makeing them a struct /* We use the same three values in 2 structs. Makeing them a struct
@ -193,7 +194,7 @@ static void undo(void)
/* Update board info */ /* Update board info */
undo = &undo_info.history[undo_info.current]; undo = &undo_info.history[undo_info.current];
rb->memcpy(&current_info.level, &undo->level, sizeof(undo->level)); rb->memcpy(&current_info.level, &undo->level, sizeof(undo->level));
rb->memcpy(&current_info.player, &undo->location[0], sizeof(undo->location[0])); rb->memcpy(&current_info.player, &undo->location[0], sizeof(undo->location[0]));
@ -218,7 +219,7 @@ static void undo(void)
} else { } else {
undo_info.current--; undo_info.current--;
} }
undo_info.count--; undo_info.count--;
return; return;
@ -235,7 +236,7 @@ static void add_undo(int button)
return; return;
if (undo_info.count != 0) { if (undo_info.count != 0) {
if (undo_info.current < (MAX_UNDOS - 1)) if (undo_info.current < (MAX_UNDOS - 1))
undo_info.current++; undo_info.current++;
else else
undo_info.current = 0; undo_info.current = 0;
@ -250,8 +251,8 @@ static void add_undo(int button)
/* Store our player info */ /* Store our player info */
rb->memcpy(&undo->location[0], &current_info.player, sizeof(undo->location[0])); rb->memcpy(&undo->location[0], &current_info.player, sizeof(undo->location[0]));
/* Now we need to store upto 2 blocks that may be affected. /* Now we need to store upto 2 blocks that may be affected.
* If player.spot is NULL, then there is no info stored * If player.spot is NULL, then there is no info stored
* for that block */ * for that block */
row = current_info.player.row; row = current_info.player.row;
@ -264,13 +265,13 @@ static void add_undo(int button)
switch (button) { switch (button) {
case BUTTON_LEFT: case BUTTON_LEFT:
col--; col--;
if (col < 0) if (col < 0)
storable = false; storable = false;
break; break;
case BUTTON_RIGHT: case BUTTON_RIGHT:
col++; col++;
if (col >= COLS) if (col >= COLS)
storable = false; storable = false;
break; break;
@ -279,7 +280,7 @@ static void add_undo(int button)
if (row < 0) if (row < 0)
storable = false; storable = false;
break; break;
case SOKOBAN_DOWN: case SOKOBAN_DOWN:
row++; row++;
if (row >= ROWS) if (row >= ROWS)
@ -299,7 +300,7 @@ static void add_undo(int button)
} }
} }
if (undo_info.count < MAX_UNDOS) if (undo_info.count < MAX_UNDOS)
undo_info.count++; undo_info.count++;
} }
@ -313,13 +314,13 @@ static void init_boards(void)
current_info.player.spot = ' '; current_info.player.spot = ' ';
current_info.max_level = 0; current_info.max_level = 0;
current_info.loaded_level = 0; current_info.loaded_level = 0;
buffered_boards.low = 0; buffered_boards.low = 0;
init_undo(); init_undo();
} }
static int read_levels(int initialize_count) static int read_levels(int initialize_count)
{ {
int fd = 0; int fd = 0;
int len; int len;
@ -333,15 +334,15 @@ static int read_levels(int initialize_count)
endpoint = current_info.level.level - MAX_BUFFERED_BOARDS; endpoint = current_info.level.level - MAX_BUFFERED_BOARDS;
if (endpoint < 0) endpoint = 0; if (endpoint < 0) endpoint = 0;
buffered_boards.low = endpoint; buffered_boards.low = endpoint;
endpoint += MAX_BUFFERED_BOARDS; endpoint += MAX_BUFFERED_BOARDS;
if ((fd = rb->open(LEVELS_FILE, O_RDONLY)) < 0) { if ((fd = rb->open(LEVELS_FILE, O_RDONLY)) < 0) {
rb->splash(0, true, "Unable to open %s", LEVELS_FILE); rb->splash(0, true, "Unable to open %s", LEVELS_FILE);
return -1; return -1;
} }
do { do {
len = rb->read_line(fd, buffer, sizeof(buffer)); len = rb->read_line(fd, buffer, sizeof(buffer));
if (len >= 3) { if (len >= 3) {
@ -380,7 +381,7 @@ static int read_levels(int initialize_count)
} }
return 0; return 0;
} }
/* return non-zero on error */ /* return non-zero on error */
static void load_level(void) static void load_level(void)
{ {
@ -388,7 +389,7 @@ static void load_level(void)
int r = 0; int r = 0;
int index = current_info.level.level - buffered_boards.low - 1; int index = current_info.level.level - buffered_boards.low - 1;
struct Board *level; struct Board *level;
if (index < 0 || index >= MAX_BUFFERED_BOARDS) { if (index < 0 || index >= MAX_BUFFERED_BOARDS) {
read_levels(false); read_levels(false);
index=index<0?MAX_BUFFERED_BOARDS-1:0; index=index<0?MAX_BUFFERED_BOARDS-1:0;
@ -403,7 +404,7 @@ static void load_level(void)
for (r = 0; r < ROWS; r++) { for (r = 0; r < ROWS; r++) {
for (c = 0; c < COLS; c++) { for (c = 0; c < COLS; c++) {
current_info.board[r][c] = level->spaces[r][c]; current_info.board[r][c] = level->spaces[r][c];
if (current_info.board[r][c] == '.') if (current_info.board[r][c] == '.')
current_info.level.boxes_to_go++; current_info.level.boxes_to_go++;
@ -416,7 +417,7 @@ static void load_level(void)
} }
#define STAT_WIDTH (LCD_WIDTH-(COLS * magnify)) #define STAT_WIDTH (LCD_WIDTH-(COLS * magnify))
static void update_screen(void) static void update_screen(void)
{ {
int b = 0, c = 0; int b = 0, c = 0;
int rows = 0, cols = 0; int rows = 0, cols = 0;
@ -429,7 +430,7 @@ static void update_screen(void)
#else #else
int magnify = 4; int magnify = 4;
#endif #endif
/* load the board to the screen */ /* load the board to the screen */
for (rows=0 ; rows < ROWS ; rows++) { for (rows=0 ; rows < ROWS ; rows++) {
for (cols = 0 ; cols < COLS ; cols++) { for (cols = 0 ; cols < COLS ; cols++) {
@ -488,16 +489,16 @@ static void update_screen(void)
#endif #endif
rb->lcd_drawline(c, b+middle, c+max, b+middle); rb->lcd_drawline(c, b+middle, c+max, b+middle);
rb->lcd_drawline(c+middle, b, c+middle, b+max-ldelta); rb->lcd_drawline(c+middle, b, c+middle, b+max-ldelta);
rb->lcd_drawline(c+max-middle, b, rb->lcd_drawline(c+max-middle, b,
c+max-middle, b+max-ldelta); c+max-middle, b+max-ldelta);
rb->lcd_drawline(c+middle, b+max-ldelta, rb->lcd_drawline(c+middle, b+max-ldelta,
c+middle-ldelta, b+max); c+middle-ldelta, b+max);
rb->lcd_drawline(c+max-middle, b+max-ldelta, rb->lcd_drawline(c+max-middle, b+max-ldelta,
c+max-middle+ldelta, b+max); c+max-middle+ldelta, b+max);
} }
break; break;
case '%': /* this is a box on a home spot */ case '%': /* this is a box on a home spot */
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
rb->lcd_set_foreground(USED_BLOCK_COLOR); rb->lcd_set_foreground(USED_BLOCK_COLOR);
@ -549,7 +550,7 @@ static bool sokoban_loop(void)
current_info.level.level = 1; current_info.level.level = 1;
load_level(); load_level();
update_screen(); update_screen();
while (1) { while (1) {
moved = true; moved = true;
@ -561,10 +562,13 @@ static bool sokoban_loop(void)
add_undo(button); add_undo(button);
switch(button) switch(button)
{ {
case SOKOBAN_QUIT: case SOKOBAN_QUIT:
/* get out of here */ /* get out of here */
#ifdef HAVE_LCD_COLOR /* reset background color */
rb->lcd_set_background(rb->global_settings->bg_color);
#endif
return PLUGIN_OK; return PLUGIN_OK;
case SOKOBAN_UNDO: case SOKOBAN_UNDO:
@ -877,7 +881,7 @@ static bool sokoban_loop(void)
moved = false; moved = false;
break; break;
} }
if (button != BUTTON_NONE) if (button != BUTTON_NONE)
lastbutton = button; lastbutton = button;
@ -898,7 +902,7 @@ static bool sokoban_loop(void)
if (current_info.level.level > current_info.max_level) { if (current_info.level.level > current_info.max_level) {
/* Center "You WIN!!" on all screen sizes */ /* Center "You WIN!!" on all screen sizes */
rb->lcd_putsxy(LCD_WIDTH/2 - 27,(LCD_HEIGHT/2) - 4 , rb->lcd_putsxy(LCD_WIDTH/2 - 27,(LCD_HEIGHT/2) - 4 ,
"You WIN!!"); "You WIN!!");
rb->lcd_set_drawmode(DRMODE_COMPLEMENT); rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
@ -934,10 +938,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
(void)(parameter); (void)(parameter);
rb = api; rb = api;
rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_setfont(FONT_SYSFIXED);
rb->lcd_getstringsize(SOKOBAN_TITLE, &w, &h); rb->lcd_getstringsize(SOKOBAN_TITLE, &w, &h);
#ifdef HAVE_LCD_COLOR
rb->lcd_set_background(BG_COLOR);
#endif
/* Get horizontel centering for text */ /* Get horizontel centering for text */
len = w; len = w;
if (len%2 != 0) if (len%2 != 0)