diff --git a/apps/plugins/bitmaps/native/SOURCES b/apps/plugins/bitmaps/native/SOURCES index 357480a..08250eb 100644 --- a/apps/plugins/bitmaps/native/SOURCES +++ b/apps/plugins/bitmaps/native/SOURCES @@ -329,62 +329,40 @@ minesweeper_tiles.8x8x1.bmp #ifdef HAVE_LCD_COLOR /* currently only LCD_WIDTH is important, e.g. Nano and e200 use the same set */ #if LCD_WIDTH >= 320 -pegbox_menu_top.320x68x16.bmp -pegbox_menu_items.120x32x16.bmp pegbox_pieces.24x24x16.bmp pegbox_header.320x40x16.bmp #elif LCD_WIDTH >= 240 -pegbox_menu_top.240x80x16.bmp -pegbox_menu_items.120x32x16.bmp pegbox_pieces.16x16x16.bmp pegbox_header.240x40x16.bmp #elif LCD_WIDTH >= 220 -pegbox_menu_top.220x60x16.bmp -pegbox_menu_items.70x20x16.bmp pegbox_pieces.16x16x16.bmp pegbox_header.220x40x16.bmp #elif LCD_WIDTH >= 176 -pegbox_menu_top.176x46x16.bmp -pegbox_menu_items.60x17x16.bmp pegbox_pieces.12x12x16.bmp pegbox_header.176x28x16.bmp #elif LCD_WIDTH >= 160 -pegbox_menu_top.160x42x16.bmp -pegbox_menu_items.60x17x16.bmp pegbox_pieces.12x12x16.bmp pegbox_header.160x24x16.bmp #elif LCD_WIDTH >= 132 -pegbox_menu_top.132x17x16.bmp -pegbox_menu_items.60x13x16.bmp pegbox_pieces.9x9x16.bmp pegbox_header.22x80x16.bmp #elif LCD_WIDTH >= 128 -pegbox_menu_top.128x42x16.bmp -pegbox_menu_items.60x17x16.bmp pegbox_pieces.10x10x16.bmp pegbox_header.128x42x16.bmp #endif /* different colour displays */ #elif LCD_DEPTH > 1 #if LCD_WIDTH >= 160 -pegbox_menu_top.160x42x2.bmp -pegbox_menu_items.60x17x2.bmp pegbox_pieces.12x12x2.bmp pegbox_header.160x24x2.bmp #elif LCD_WIDTH >= 138 -pegbox_menu_top.138x31x2.bmp -pegbox_menu_items.60x17x2.bmp pegbox_pieces.10x10x2.bmp pegbox_header.138x26x2.bmp #elif LCD_WIDTH >= 128 -pegbox_menu_top.128x27x2.bmp -pegbox_menu_items.60x15x2.bmp pegbox_pieces.10x10x2.bmp pegbox_header.128x16x2.bmp #endif /* different greyscale displays */ #else /* mono */ #if LCD_WIDTH >= 160 -pegbox_menu_top.160x42x1.bmp -pegbox_menu_items.60x17x1.bmp pegbox_pieces.12x12x1.bmp pegbox_header.160x24x1.bmp #elif LCD_WIDTH >= 112 diff --git a/apps/plugins/pegbox.c b/apps/plugins/pegbox.c index 514b92e..8176bd3 100644 --- a/apps/plugins/pegbox.c +++ b/apps/plugins/pegbox.c @@ -23,15 +23,6 @@ #include "pluginbitmaps/pegbox_header.h" #include "pluginbitmaps/pegbox_pieces.h" -#if LCD_HEIGHT >= 80 /* enough space for a graphical menu */ -#include "pluginbitmaps/pegbox_menu_top.h" -#include "pluginbitmaps/pegbox_menu_items.h" -#define MENU_X (LCD_WIDTH-BMPWIDTH_pegbox_menu_items)/2 -#define MENU_Y BMPHEIGHT_pegbox_menu_top -#define ITEM_WIDTH BMPWIDTH_pegbox_menu_items -#define ITEM_HEIGHT (BMPHEIGHT_pegbox_menu_items/9) -#endif - PLUGIN_HEADER /* final game return status */ @@ -523,29 +514,9 @@ PLUGIN_HEADER #define TEXT_BG LCD_RGBPACK(189,189,189) #endif - #ifdef HAVE_TOUCHSCREEN #include "lib/touchscreen.h" -static struct ts_mapping main_menu_items[5] = -{ -{MENU_X, MENU_Y, ITEM_WIDTH, ITEM_HEIGHT}, -{MENU_X, MENU_Y+ITEM_HEIGHT, ITEM_WIDTH, ITEM_HEIGHT}, -{MENU_X, MENU_Y+ITEM_HEIGHT*2, ITEM_WIDTH, ITEM_HEIGHT}, -{MENU_X, MENU_Y+ITEM_HEIGHT*3, ITEM_WIDTH, ITEM_HEIGHT}, -{ -#if (LCD_WIDTH >= 138) && (LCD_HEIGHT > 110) -0, MENU_Y+4*ITEM_HEIGHT+8, SYSFONT_WIDTH*28, SYSFONT_HEIGHT -#elif LCD_WIDTH > 112 -0, LCD_HEIGHT - 8, SYSFONT_WIDTH*28, SYSFONT_HEIGHT -#else -#error "Touchscreen isn't supported on non-bitmap screens!" -#endif -} - -}; -static struct ts_mappings main_menu = {main_menu_items, 5}; - static struct ts_raster pegbox_raster = { BOARD_X, BOARD_Y, COLS*PIECE_WIDTH, ROWS*PIECE_HEIGHT, PIECE_WIDTH, PIECE_HEIGHT }; @@ -1114,217 +1085,93 @@ static void pegbox_savedata(struct game_context* pb) { rb->close(fd); } -/***************************************************************************** -* pegbox_callback() is the default event handler callback which is called -* on usb connect and shutdown. -******************************************************************************/ -static void pegbox_callback(void* param) { - struct game_context* pb = (struct game_context*) param; - rb->splash(HZ, "Saving data..."); - pegbox_savedata(pb); -} +enum menu_items { + PB_MENU_START, + PB_MENU_RESUME, + PB_MENU_HELP, + PB_MENU_QUIT +}; + +MENUITEM_STRINGLIST (main_menu, "Pegbox", NULL, + "Start", + "Resume", + "Help", + "Quit"); + /***************************************************************************** * pegbox_menu() is the initial menu at the start of the game. ******************************************************************************/ static unsigned int pegbox_menu(struct game_context* pb) { - int button; - char str[30]; - unsigned int startlevel = 1, loc = 0; bool breakout = false, can_resume = false; - + if (pb->num_left > 0 || pb->save_exist) can_resume = true; + + int selection = 0; while(!breakout){ -#if LCD_HEIGHT >= 80 - rb->lcd_clear_display(); - rb->lcd_bitmap(pegbox_menu_top,0,0,LCD_WIDTH, BMPHEIGHT_pegbox_menu_top); - - /* menu bitmaps */ - if (loc == 0) { - rb->lcd_bitmap_part(pegbox_menu_items, 0, ITEM_HEIGHT, ITEM_WIDTH, - MENU_X, MENU_Y, ITEM_WIDTH, ITEM_HEIGHT); - } - else { - rb->lcd_bitmap_part(pegbox_menu_items, 0, 0, ITEM_WIDTH, - MENU_X, MENU_Y, ITEM_WIDTH, ITEM_HEIGHT); - } - if (can_resume) { - if (loc == 1) { - rb->lcd_bitmap_part(pegbox_menu_items, 0, ITEM_HEIGHT*3, ITEM_WIDTH, - MENU_X, MENU_Y+ITEM_HEIGHT, ITEM_WIDTH, ITEM_HEIGHT); - } - else { - rb->lcd_bitmap_part(pegbox_menu_items, 0, ITEM_HEIGHT*2, ITEM_WIDTH, - MENU_X, MENU_Y+ITEM_HEIGHT, ITEM_WIDTH, ITEM_HEIGHT); - } - } - else { - rb->lcd_bitmap_part(pegbox_menu_items, 0, ITEM_HEIGHT*4, ITEM_WIDTH, - MENU_X, MENU_Y+ITEM_HEIGHT, ITEM_WIDTH, ITEM_HEIGHT); - } - - if (loc==2) { - rb->lcd_bitmap_part(pegbox_menu_items, 0, ITEM_HEIGHT*6, ITEM_WIDTH, - MENU_X, MENU_Y+ITEM_HEIGHT*2, ITEM_WIDTH, ITEM_HEIGHT); - } - else { - rb->lcd_bitmap_part(pegbox_menu_items, 0, ITEM_HEIGHT*5, ITEM_WIDTH, - MENU_X, MENU_Y+ITEM_HEIGHT*2, ITEM_WIDTH, ITEM_HEIGHT); - } - - if (loc==3) { - rb->lcd_bitmap_part(pegbox_menu_items, 0, ITEM_HEIGHT*8, ITEM_WIDTH, - MENU_X, MENU_Y+ITEM_HEIGHT*3, ITEM_WIDTH, ITEM_HEIGHT); - } - else { - rb->lcd_bitmap_part(pegbox_menu_items, 0, ITEM_HEIGHT*7, ITEM_WIDTH, - MENU_X, MENU_Y+ITEM_HEIGHT*3, ITEM_WIDTH, ITEM_HEIGHT); - } -#else - unsigned int w,h; - rb->lcd_clear_display(); - rb->lcd_getstringsize("PegBox", &w, &h); - rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, "PegBox"); - rb->lcd_putsxy((LCD_WIDTH)/4, 16, "New Game"); - rb->lcd_putsxy((LCD_WIDTH)/4, 24, "Resume"); - rb->lcd_putsxy((LCD_WIDTH)/4, 32, "Help"); - rb->lcd_putsxy((LCD_WIDTH)/4, 40, "Quit"); - - if(!can_resume) - rb->lcd_hline((LCD_WIDTH)/4, (LCD_WIDTH)/4+30, 28); - - rb->lcd_putsxy((LCD_WIDTH)/4-8, loc*8+16, "*"); - + selection = rb->do_menu(&main_menu, &selection, NULL, false); -#endif - rb->snprintf(str, 28, "Start on level %d of %d", startlevel, - pb->highlevel); -#if LCD_HEIGHT > 110 - rb->lcd_putsxy(0, MENU_Y+4*ITEM_HEIGHT+8, str); -#elif LCD_HEIGHT > 64 - rb->lcd_putsxy(0, LCD_HEIGHT - 8, str); -#else - rb->lcd_puts_scroll(0, 7, str); -#endif - rb->lcd_update(); - - /* handle menu button presses */ - button = rb->button_get(true); + switch(selection) { + case PB_MENU_START: + rb->set_int("Starting Level", "", UNIT_INT, &pb->level, + NULL, 1, 1, pb->highlevel, NULL); + breakout = true; + load_level(pb); + break; -#ifdef HAVE_TOUCHSCREEN - if(button & BUTTON_TOUCHSCREEN) - { - unsigned int result = touchscreen_map(&main_menu, - rb->button_get_data() >> 16, - rb->button_get_data() & 0xffff); - if(result != (unsigned)-1 && button & BUTTON_REL) - { - if(result == 4) - button = PEGBOX_LVL_UP; - else - { - if(loc == result) - button = PEGBOX_RIGHT; - loc = result; - } - } - } -#endif + case GO_TO_ROOT: + case GO_TO_PREVIOUS: + /* resume if we can (by falling through), otherwise exit */ + if (!can_resume) + return PB_QUIT; - switch(button) { - case PEGBOX_SAVE: /* start playing */ - case PEGBOX_RIGHT: - if (loc == 0) { - breakout = true; - pb->level = startlevel; - load_level(pb); - } - else if (loc == 1 && can_resume) { - if(pb->save_exist) - { + case PB_MENU_RESUME: + if (can_resume) { + if (pb->save_exist) { rb->remove(SAVE_FILE); pb->save_exist = false; } breakout = true; - } - else if (loc == 2) - display_text("How to Play\nTo beat each level, you must " - "destroy all of the pegs. If two like pegs are " - "pushed into each other they disappear except " - "for triangles which form a solid block and " - "crosses which allow you to choose a " - "replacement block.\n\n" - "Controls\n" -#if LCD_HEIGHT > 64 - RESTART_TEXT " to restart level\n" - LVL_UP_TEXT " to go up a level\n" - LVL_DOWN_TEXT " to go down a level\n" - SAVE_TEXT " to select/save\n" - QUIT_TEXT " to quit\n",true); -#else - RESTART_TEXT ": restart\n" - LVL_UP_TEXT ": level up\n" - LVL_DOWN_TEXT " level down\n" - SAVE_TEXT " select/save\n" - QUIT_TEXT " quit\n",true); -#endif - else if (loc == 3) - return PB_QUIT; - break; - - case PEGBOX_QUIT: /* quit program */ - return PB_QUIT; - - case (PEGBOX_UP|BUTTON_REPEAT): - case PEGBOX_UP: - if (loc <= 0) - loc = 3; - else - loc--; - if (!can_resume && loc == 1) { - loc = 0; } - break; - + else + rb->splash(HZ, "Nothing to resume!"); - case (PEGBOX_DOWN|BUTTON_REPEAT): - case PEGBOX_DOWN: - if (loc >= 3) - loc = 0; - else - loc++; - if (!can_resume && loc == 1) { - loc = 2; - } break; - case (PEGBOX_LVL_UP|BUTTON_REPEAT): - case PEGBOX_LVL_UP: /* increase starting level */ - if(startlevel >= pb->highlevel) { - startlevel = 1; - } else { - startlevel++; - } + case PB_MENU_HELP: + display_text("How to Play\nTo beat each level, you must " + "destroy all of the pegs. If two like pegs are " + "pushed into each other they disappear except " + "for triangles which form a solid block and " + "crosses which allow you to choose a " + "replacement block.\n\n" + "Controls\n" +#if LCD_HEIGHT > 64 + RESTART_TEXT " to restart level\n" + LVL_UP_TEXT " to go up a level\n" + LVL_DOWN_TEXT " to go down a level\n" + SAVE_TEXT " to select/save\n" + QUIT_TEXT " to quit\n" +#else + RESTART_TEXT ": restart\n" + LVL_UP_TEXT ": level up\n" + LVL_DOWN_TEXT " level down\n" + SAVE_TEXT " select/save\n" + QUIT_TEXT " quit\n" +#endif + , true); break; -/* only for targets with enough buttons */ -#ifdef PEGBOX_LVL_DOWN - case (PEGBOX_LVL_DOWN|BUTTON_REPEAT): - case PEGBOX_LVL_DOWN: /* decrease starting level */ - if(startlevel <= 1) { - startlevel = pb->highlevel; - } else { - startlevel--; - } - break; -#endif + case MENU_ATTACHED_USB: + rb->splash(0, "Saving data..."); + pegbox_savedata(pb); + return PB_USB; + + case PB_MENU_QUIT: default: - if(rb->default_event_handler_ex(button, pegbox_callback, - (void*) pb) == SYS_USB_CONNECTED) - return PB_USB; - break; + return PB_QUIT; } }