diff --git a/apps/plugins/flipit.c b/apps/plugins/flipit.c index ae0b1db..a63b358 100644 --- a/apps/plugins/flipit.c +++ b/apps/plugins/flipit.c @@ -19,6 +19,7 @@ * ****************************************************************************/ #include "plugin.h" +#include "lib/playback_control.h" PLUGIN_HEADER @@ -506,18 +507,28 @@ static void move_cursor(int x, int y) rb->lcd_update(); } +static void draw_board(void) +{ + int i; + + rb->lcd_clear_display(); + for (i=0; i<20; i++) { + draw_spot(i); + } + rb->lcd_update(); +} + /* initialize the board */ static void flipit_init(void) { int i; - rb->lcd_clear_display(); for (i=0; i<20; i++) { spots[i]=1; toggle[i]=1; - draw_spot(i); } - rb->lcd_update(); + + draw_board(); for (i=0; i<20; i++) { cursor_pos = (rb->rand() % 20); @@ -546,8 +557,23 @@ static bool flipit_loop(void) case FLIPIT_RC_QUIT: #endif case FLIPIT_QUIT: - /* get out of here */ - return PLUGIN_OK; + switch (playback_control_or_quit (NULL)) + { + case PBC_OR_QUIT_QUIT: + return PLUGIN_OK; + + case PBC_OR_QUIT_USB_CONNECTED: + return PLUGIN_USB_CONNECTED; + + default: + case PBC_OR_QUIT_RESUME: + break; + } + draw_board(); + draw_cursor(); + draw_info_panel(); + rb->lcd_update(); + break; case FLIPIT_SHUFFLE: /* mix up the pieces */ diff --git a/apps/plugins/maze.c b/apps/plugins/maze.c index 881d804..73ce595 100644 --- a/apps/plugins/maze.c +++ b/apps/plugins/maze.c @@ -32,6 +32,7 @@ #include "plugin.h" #include "lib/helper.h" +#include "lib/playback_control.h" PLUGIN_HEADER @@ -573,7 +574,22 @@ enum plugin_status plugin_start(const void* parameter) break; case MAZE_QUIT: /* quit plugin */ - quit=1; + switch (playback_control_or_quit(NULL)) + { + case PBC_OR_QUIT_QUIT: + quit = 1; + break; + case PBC_OR_QUIT_USB_CONNECTED: + quit = 2; + break; + default: + case PBC_OR_QUIT_RESUME: + FOR_NB_SCREENS(i) + maze_draw(&maze, rb->screens[i]); + + break; + } + break; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c index 5d55bb4..85c7b03 100644 --- a/apps/plugins/oscilloscope.c +++ b/apps/plugins/oscilloscope.c @@ -23,6 +23,7 @@ #include "plugin.h" #include "lib/helper.h" +#include "lib/playback_control.h" #ifdef HAVE_LCD_BITMAP #include "lib/xlcd.h" @@ -763,7 +764,24 @@ enum plugin_status plugin_start(const void* parameter) case OSCILLOSCOPE_RC_QUIT: #endif case OSCILLOSCOPE_QUIT: - exit = true; + switch (playback_control_or_quit (NULL)) + { + case PBC_OR_QUIT_QUIT: + exit = true; + break; + + case PBC_OR_QUIT_USB_CONNECTED: + return PLUGIN_USB_CONNECTED; + + default: + case PBC_OR_QUIT_RESUME: + rb->lcd_clear_display(); + rb->lcd_update(); + last_pos = 0; + last_tick = 0; + break; + } + break; case OSCILLOSCOPE_ADVMODE: diff --git a/apps/plugins/robotfindskitten.c b/apps/plugins/robotfindskitten.c index 7ae5721..8f00f1b 100644 --- a/apps/plugins/robotfindskitten.c +++ b/apps/plugins/robotfindskitten.c @@ -30,6 +30,7 @@ #include "plugin.h" #include "lib/pluginlib_actions.h" +#include "lib/playback_control.h" /* This macros must always be included. Should be placed at the top by convention, although the actual position doesn't matter */ @@ -668,8 +669,25 @@ static void play_game() const struct button_mapping *plugin_contexts[] = {generic_directions, generic_actions}; #endif - while (input != RFK_QUIT && exit_rfk == false) + while (exit_rfk == false) { + if (input == RFK_QUIT) + { + switch (playback_control_or_quit (NULL)) + { + case PBC_OR_QUIT_QUIT: + case PBC_OR_QUIT_USB_CONNECTED: + exit_rfk = true; + continue; + + default: + case PBC_OR_QUIT_RESUME: + break; + } + + initialize_screen(); + } + process_input(input); /*Redraw robot, where applicable. We're your station, robot.*/ diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c index 11fd118..35762b8 100644 --- a/apps/plugins/rockblox.c +++ b/apps/plugins/rockblox.c @@ -24,6 +24,7 @@ #include "lib/highscore.h" #include "lib/playergfx.h" #include "lib/helper.h" +#include "lib/playback_control.h" PLUGIN_HEADER @@ -751,16 +752,8 @@ static void show_highscores (void) } #endif -static void init_rockblox (void) +static void draw_background (void) { - highscore_update(score, level, Highest, MAX_HIGH_SCORES); - - level = 1; - lines = 0; - score = 0; - gameover = false; - nf = t_rand (BLOCKS_NUM); - init_board (); #ifdef HAVE_LCD_BITMAP rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT); #else /* HAVE_LCD_CHARCELLS */ @@ -778,6 +771,19 @@ static void init_rockblox (void) #endif } +static void init_rockblox (void) +{ + highscore_update(score, level, Highest, MAX_HIGH_SCORES); + + level = 1; + lines = 0; + score = 0; + gameover = false; + nf = t_rand (BLOCKS_NUM); + init_board (); + draw_background (); +} + static inline int level_speed(int level) { #if BOARD_HEIGHT == 20 @@ -1101,7 +1107,22 @@ static int rockblox_loop (void) case ROCKBLOX_RC_OFF: #endif case ROCKBLOX_OFF: - return PLUGIN_OK; + switch (playback_control_or_quit (NULL)) + { + case PBC_OR_QUIT_QUIT: + return PLUGIN_OK; + + case PBC_OR_QUIT_USB_CONNECTED: + return PLUGIN_USB_CONNECTED; + + default: + case PBC_OR_QUIT_RESUME: + break; + } + draw_background (); + refresh_board (); + draw_next_block (); + break; #if defined(ROCKBLOX_ROTATE) case ROCKBLOX_ROTATE: diff --git a/apps/plugins/rockblox1d.c b/apps/plugins/rockblox1d.c index d7779fa..df12929 100644 --- a/apps/plugins/rockblox1d.c +++ b/apps/plugins/rockblox1d.c @@ -21,6 +21,7 @@ ****************************************************************************/ #include "plugin.h" +#include "lib/playback_control.h" PLUGIN_HEADER @@ -166,43 +167,29 @@ void draw_brick(int pos, int length) { } } -enum plugin_status plugin_start(const void* parameter) -{ - int i; - int f_width, f_height; - int score_x; +int f_width, f_height; +int score_x; - bool quit = false; - int button; - - int cycletime = 300; - int end; +void draw_next_brick(int type_next_brick) { + int i; - int pos_cur_brick = 0; - int type_cur_brick = 0; - int type_next_brick = 0; - - unsigned long int score = 34126; - char score_buf[10]; - - (void)parameter; + rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); + rb->lcd_fillrect(NEXT_X, NEXT_Y, WIDTH, WIDTH * 4 + 4); + rb->lcd_set_drawmode(DRMODE_SOLID); -#if LCD_DEPTH > 1 - rb->lcd_set_backdrop(NULL); - rb->lcd_set_background(LCD_BLACK); - rb->lcd_set_foreground(LCD_WHITE); -#endif + for (i = 0; i < type_next_brick; ++i) { + rb->lcd_fillrect(NEXT_X, + NEXT_Y + ((type_next_brick % 2) ? (int)(WIDTH/2) : + ((type_next_brick == 2) ? (WIDTH+1) : 0)) + (WIDTH*i) + i, + WIDTH, WIDTH); + } +} - rb->lcd_setfont(FONT_SYSFIXED); - +void draw_background(void) { rb->lcd_getstringsize("100000000", &f_width, &f_height); - + rb->lcd_clear_display(); - - /*********** - ** Draw EVERYTHING - */ - + /* Playing filed box */ rb->lcd_vline(CENTER_X-2, CENTER_Y, CENTER_Y + (WIDTH*TILES+TILES)); rb->lcd_vline(CENTER_X + WIDTH + 1, CENTER_Y, @@ -219,7 +206,7 @@ enum plugin_status plugin_start(const void* parameter) rb->lcd_putsxy(2, SCORE_Y-6-f_height, "score"); #endif score_x = SCORE_X; - + /* Next box */ rb->lcd_getstringsize("next", &f_width, NULL); #if (LCD_WIDTH > LCD_HEIGHT) && !(LCD_WIDTH > 132) @@ -229,6 +216,34 @@ enum plugin_status plugin_start(const void* parameter) rb->lcd_drawrect(NEXT_X-5, NEXT_Y-5, WIDTH+10, NEXT_H+10); rb->lcd_putsxy(NEXT_X-5, NEXT_Y-5-f_height-1, "next"); #endif +} + +enum plugin_status plugin_start(const void* parameter) +{ + bool quit = false; + int button; + + int cycletime = 300; + int end; + + int pos_cur_brick = 0; + int type_cur_brick = 0; + int type_next_brick = 0; + + unsigned long int score = 34126; + char score_buf[10]; + + (void)parameter; + +#if LCD_DEPTH > 1 + rb->lcd_set_backdrop(NULL); + rb->lcd_set_background(LCD_BLACK); + rb->lcd_set_foreground(LCD_WHITE); +#endif + + rb->lcd_setfont(FONT_SYSFIXED); + + draw_background(); /*********** ** GAMELOOP @@ -243,16 +258,7 @@ enum plugin_status plugin_start(const void* parameter) draw_brick(pos_cur_brick, type_cur_brick); - /* Draw next brick */ - rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); - rb->lcd_fillrect(NEXT_X, NEXT_Y, WIDTH, WIDTH * 4 + 4); - rb->lcd_set_drawmode(DRMODE_SOLID); - - for (i = 0; i < type_next_brick; ++i) { - rb->lcd_fillrect(NEXT_X, - NEXT_Y + ((type_next_brick % 2) ? (int)(WIDTH/2) : ((type_next_brick == 2) ? (WIDTH+1) : 0)) + (WIDTH*i) + i, - WIDTH, WIDTH); - } + draw_next_brick(type_next_brick); /* Score box */ rb->snprintf(score_buf, sizeof(score_buf), "%8ld0", score); @@ -268,7 +274,21 @@ enum plugin_status plugin_start(const void* parameter) cycletime = 100; break; case ONEDROCKBLOX_QUIT: - quit = true; + rb->button_clear_queue(); + switch (playback_control_or_quit (NULL)) + { + case PBC_OR_QUIT_QUIT: + case PBC_OR_QUIT_USB_CONNECTED: + quit = true; + break; + default: + case PBC_OR_QUIT_RESUME: + cycletime = 300; + break; + } + draw_background(); + draw_brick(pos_cur_brick, type_cur_brick); + draw_next_brick(type_next_brick); break; default: cycletime = 300; diff --git a/apps/plugins/rocklife.c b/apps/plugins/rocklife.c index 2d162fc..8fd31fe 100644 --- a/apps/plugins/rocklife.c +++ b/apps/plugins/rocklife.c @@ -63,6 +63,7 @@ #include "plugin.h" #include "lib/pluginlib_actions.h" #include "lib/helper.h" +#include "lib/playback_control.h" PLUGIN_HEADER @@ -397,7 +398,6 @@ static void next_generation(char *pgrid, char *pnext_grid){ enum plugin_status plugin_start(const void* parameter) { int button = 0; - int quit = 0; int stop = 0; int pattern = 0; char *pgrid; @@ -424,7 +424,7 @@ enum plugin_status plugin_start(const void* parameter) setup_grid(pgrid, pattern++); show_grid(pgrid); - while(!quit) { + while(1) { button = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts, 2); switch(button) { case ROCKLIFE_NEXT: @@ -474,9 +474,18 @@ enum plugin_status plugin_start(const void* parameter) show_grid(pgrid); break; case ROCKLIFE_QUIT: - /* quit plugin */ - quit=true; - return PLUGIN_OK; + switch (playback_control_or_quit (NULL)) { + case PBC_OR_QUIT_QUIT: + backlight_use_settings(); + return PLUGIN_OK; + case PBC_OR_QUIT_USB_CONNECTED: + backlight_use_settings(); + return PLUGIN_USB_CONNECTED; + default: + case PBC_OR_QUIT_RESUME: + break; + } + show_grid(pgrid); break; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { @@ -486,9 +495,5 @@ enum plugin_status plugin_start(const void* parameter) } rb->yield(); } - - backlight_use_settings(); /* backlight control in lib/helper.c */ - return PLUGIN_OK; } - diff --git a/apps/plugins/sliding_puzzle.c b/apps/plugins/sliding_puzzle.c index c5c8c67..e0f23f2 100644 --- a/apps/plugins/sliding_puzzle.c +++ b/apps/plugins/sliding_puzzle.c @@ -19,6 +19,7 @@ * ****************************************************************************/ #include "plugin.h" +#include "lib/playback_control.h" #ifdef HAVE_LCD_BITMAP PLUGIN_HEADER @@ -564,8 +565,20 @@ static int puzzle_loop(void) case PUZZLE_RC_QUIT: #endif case PUZZLE_QUIT: - /* get out of here */ - return PLUGIN_OK; + switch (playback_control_or_quit (NULL)) + { + case PBC_OR_QUIT_QUIT: + return PLUGIN_OK; + + case PBC_OR_QUIT_USB_CONNECTED: + return PLUGIN_USB_CONNECTED; + + default: + case PBC_OR_QUIT_RESUME: + break; + } + draw_playfield(); + break; case PUZZLE_SHUFFLE: #ifdef PUZZLE_SHUFFLE_PICTURE_PRE diff --git a/apps/plugins/snake.c b/apps/plugins/snake.c index a80aaa0..2de988e 100644 --- a/apps/plugins/snake.c +++ b/apps/plugins/snake.c @@ -33,6 +33,7 @@ dir is the current direction of the snake - 0=up, 1=right, 2=down, 3=left; */ #include "plugin.h" +#include "lib/playback_control.h" #ifdef HAVE_LCD_BITMAP PLUGIN_HEADER @@ -316,35 +317,39 @@ void redraw (void) } void game_pause (void) { - int button; - rb->lcd_clear_display(); - rb->lcd_putsxy(3,12,"Game Paused"); -#if CONFIG_KEYPAD == RECORDER_PAD - rb->lcd_putsxy(3,22,"[Play] to resume"); -#elif CONFIG_KEYPAD == ONDIO_PAD - rb->lcd_putsxy(3,22,"[Mode] to resume"); -#endif - rb->lcd_putsxy(3,32,"[Off] to quit"); - rb->lcd_update(); + int selection = 0; + MENUITEM_STRINGLIST (paused_menu, "Game Paused", NULL, + "Resume", + "Playback Control", + "Quit"); + + rb->button_clear_queue(); + while (1) { - button=rb->button_get(true); - switch (button) { -#ifdef SNAKE_RC_QUIT - case SNAKE_RC_QUIT: -#endif - case SNAKE_QUIT: - dead=1; - return; - case SNAKE_PLAYPAUSE: + selection = rb->do_menu(&paused_menu, &selection, NULL, false); + switch (selection) { + case GO_TO_ROOT: + case GO_TO_PREVIOUS: + case 0: redraw(); rb->sleep(HZ/2); return; - default: - if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { + + case 1: + /* if USB is attached in playback control, quit. */ + if (playback_control(NULL)) { dead=2; return; } break; + + case 2: + dead=1; + return; + + case MENU_ATTACHED_USB: + dead=2; + return; } } } diff --git a/apps/plugins/snake2.c b/apps/plugins/snake2.c index d5ffc9f..048f962 100644 --- a/apps/plugins/snake2.c +++ b/apps/plugins/snake2.c @@ -30,6 +30,7 @@ Head and Tail are stored */ #include "plugin.h" +#include "lib/playback_control.h" #ifdef HAVE_LCD_BITMAP PLUGIN_HEADER @@ -1196,40 +1197,44 @@ void frame (void) void game_pause (void) { - int button; - - rb->lcd_clear_display(); - rb->lcd_getstringsize("Paused",&strwdt,&strhgt); - rb->lcd_putsxy((LCD_WIDTH - strwdt)/2,LCD_HEIGHT/2,"Paused"); - - rb->lcd_update(); - while (1) - { - button = rb->button_get(true); - switch (button) - { - case SNAKE2_PLAYPAUSE: + int selection = 0; + MENUITEM_STRINGLIST (paused_menu, "Game Paused", NULL, + "Resume", + "Playback Control", + "Quit"); + + rb->button_clear_queue(); + + while (1) { + selection = rb->do_menu(&paused_menu, &selection, NULL, false); + switch (selection) { + case GO_TO_ROOT: + case GO_TO_PREVIOUS: + case 0: rb->lcd_clear_display(); redraw(); rb->lcd_update(); rb->sleep(HZ/2); return; -#ifdef SNAKE2_RC_QUIT - case SNAKE2_RC_QUIT: -#endif - case SNAKE2_QUIT: - dead = 1; - quit = 1; - return; - - default: - if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { - dead = 1; - quit = 2; + case 1: + /* if USB is attached in playback control, quit. */ + if (playback_control(NULL)) { + dead=1; + quit=2; return; } break; + + case 2: + dead=1; + quit=1; + return; + + case MENU_ATTACHED_USB: + dead=1; + quit=2; + return; } } } diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c index 0891906..34f86f7 100644 --- a/apps/plugins/spacerocks.c +++ b/apps/plugins/spacerocks.c @@ -21,6 +21,7 @@ #include "plugin.h" #include "lib/helper.h" +#include "lib/playback_control.h" PLUGIN_HEADER @@ -1980,14 +1981,59 @@ enum plugin_status start_game(void) game_state = PAUSE_MODE; #endif + int selection = 0; + bool pause_menu_done = false; + MENUITEM_STRINGLIST (paused_menu, "Game Paused", NULL, + "Resume", + "Playback Control", + "Quit"); + switch(button) { case(AST_PAUSE): - if(game_state == PLAY_MODE) - game_state = PAUSE_MODE; - else if(game_state == PAUSE_MODE) + if (game_state == PAUSE_MODE) + { game_state = PLAY_MODE; - break; + break; + } + else if (game_state != PLAY_MODE) + break; + + while (!pause_menu_done) { + selection = rb->do_menu(&paused_menu, &selection, + NULL, false); + switch (selection) { + case GO_TO_ROOT: + case GO_TO_PREVIOUS: + case 0: + rb->lcd_clear_display(); + drawstars(); + draw_and_move_missiles(); + draw_lives(); + draw_and_move_ship(); + pause_menu_done = true; + break; + + case 1: + /* if USB is attached in playback control, + * quit. */ + if (playback_control(NULL)) + return PLUGIN_USB_CONNECTED; + break; + + case 2: + pause_menu_done = true; + break; + + case MENU_ATTACHED_USB: + return PLUGIN_USB_CONNECTED; + } + } + /* purposely fall through from case 2 of the pause menu + * to AST_QUIT + */ + if (selection == 0) + break; #ifdef AST_RC_QUIT case AST_RC_QUIT: diff --git a/apps/plugins/star.c b/apps/plugins/star.c index c4251cd..03df9bd 100644 --- a/apps/plugins/star.c +++ b/apps/plugins/star.c @@ -19,6 +19,7 @@ * ****************************************************************************/ #include "plugin.h" +#include "lib/playback_control.h" #ifdef HAVE_LCD_BITMAP PLUGIN_HEADER @@ -742,33 +743,20 @@ static void star_display_board_info(int current_level) MAX(TILE_HEIGHT, char_height)); } - /** - * Load a level into board array. + * Draw the board. Returns the number of stars. */ -static int star_load_level(int current_level) +static int star_display_board(void) { int x, y; - char *ptr_tab; - - if (current_level < 0) - current_level = 0; - else if (current_level > STAR_LEVEL_COUNT-1) - current_level = STAR_LEVEL_COUNT-1; - - - ptr_tab = levels + current_level * STAR_LEVEL_SIZE; - control = STAR_CONTROL_BALL; - star_count = 0; - - rb->lcd_clear_display(); + int star_count = 0; for (y = 0 ; y < STAR_HEIGHT ; y++) { for (x = 0 ; x < STAR_WIDTH ; x++) { - board[y][x] = *ptr_tab; - switch (*ptr_tab) + + switch (board[y][x]) { # define DRAW_TILE( a ) \ rb->lcd_bitmap_part( star_tiles, 0, \ @@ -802,10 +790,42 @@ static int star_load_level(int current_level) DRAW_TILE( BLOCK ); break; } + } + } + + return star_count; +} + +/** + * Load a level into board array. + */ +static int star_load_level(int current_level) +{ + int x, y; + char *ptr_tab; + + if (current_level < 0) + current_level = 0; + else if (current_level > STAR_LEVEL_COUNT-1) + current_level = STAR_LEVEL_COUNT-1; + + + ptr_tab = levels + current_level * STAR_LEVEL_SIZE; + control = STAR_CONTROL_BALL; + + rb->lcd_clear_display(); + + for (y = 0 ; y < STAR_HEIGHT ; y++) + { + for (x = 0 ; x < STAR_WIDTH ; x++) + { + board[y][x] = *ptr_tab; ptr_tab++; } ptr_tab++; } + + star_count = star_display_board(); star_display_board_info(current_level); star_transition_update(); return 1; @@ -875,7 +895,22 @@ static int star_run_game(int current_level) case STAR_RC_QUIT: #endif case STAR_QUIT: - return -1; + switch (playback_control_or_quit (NULL)) + { + case PBC_OR_QUIT_QUIT: + return -1; + case PBC_OR_QUIT_USB_CONNECTED: + usb_detected = true; + return 0; + default: + case PBC_OR_QUIT_RESUME: + break; + } + rb->lcd_clear_display(); + star_display_board(); + rb->lcd_update(); + star_display_board_info(current_level); + break; case STAR_LEFT: move_x = -1; diff --git a/apps/plugins/stopwatch.c b/apps/plugins/stopwatch.c index 4cba167..93788cd 100644 --- a/apps/plugins/stopwatch.c +++ b/apps/plugins/stopwatch.c @@ -20,6 +20,7 @@ ****************************************************************************/ #include "plugin.h" +#include "lib/playback_control.h" PLUGIN_HEADER @@ -427,8 +428,20 @@ enum plugin_status plugin_start(const void* parameter) case STOPWATCH_RC_QUIT: #endif case STOPWATCH_QUIT: - save_stopwatch(); - done = true; + switch (playback_control_or_quit (NULL)) + { + case PBC_OR_QUIT_QUIT: + case PBC_OR_QUIT_USB_CONNECTED: + save_stopwatch(); + done = true; + break; + default: + case PBC_OR_QUIT_RESUME: + rb->lcd_clear_display(); + update_lap = true; + break; + } + break; /* Stop/Start toggle */