From c72b23ad2e1b3a507a36b6223c0a35be9b746f0a Mon Sep 17 00:00:00 2001 From: Teruaki Kawashima Date: Tue, 14 Jul 2009 13:03:17 +0000 Subject: use lib display text to display help messages (FS#10099). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21861 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/brickmania.c | 284 ++++++++++++------------------------ apps/plugins/clix.c | 36 ++--- apps/plugins/jewels.c | 66 ++++++++- apps/plugins/lib/display_text.c | 5 - apps/plugins/pegbox.c | 176 +++++++--------------- apps/plugins/robotfindskitten.c | 49 ++----- apps/plugins/solitaire.c | 172 +++++----------------- apps/plugins/star.c | 314 +++++++++++++++++----------------------- apps/plugins/superdom.c | 53 ++----- 9 files changed, 409 insertions(+), 746 deletions(-) (limited to 'apps/plugins') diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c index 2f11cef24e..f0229b4f8b 100644 --- a/apps/plugins/brickmania.c +++ b/apps/plugins/brickmania.c @@ -22,6 +22,7 @@ #include "plugin.h" #include "lib/configfile.h" /* Part of libplugin */ #include "lib/helper.h" +#include "lib/display_text.h" PLUGIN_HEADER @@ -1130,154 +1131,84 @@ int game_menu(int when) } } -int help(int when) +int help(void) { - int w,h; int button; - int xoffset=0; - int yoffset=0; - /* set the maximum x and y in the helpscreen - dont forget to update, if you change text */ - int maxY=180; - int maxX=215; - - while(true) { -#ifdef HAVE_LCD_COLOR - rb->lcd_set_background(LCD_BLACK); - rb->lcd_clear_display(); - rb->lcd_set_background(LCD_BLACK); - rb->lcd_set_foreground(LCD_WHITE); -#else - rb->lcd_clear_display(); -#endif - - rb->lcd_getstringsize("BrickMania", &w, &h); - rb->lcd_putsxy(LCD_WIDTH/2-w/2+xoffset, 1+yoffset, "BrickMania"); - -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_RGBPACK(245,0,0)); - rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim"); - rb->lcd_set_foreground(LCD_WHITE); -#else - rb->lcd_putsxy(1+xoffset, 1*(h+2)+yoffset,"Aim"); -#endif - rb->lcd_putsxy(1+xoffset, 2*(h+2)+yoffset, - "destroy all the bricks by bouncing"); - rb->lcd_putsxy(1+xoffset, 3*(h+2)+yoffset, - "the ball of them using the paddle."); -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_RGBPACK(245,0,0)); - rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls"); - rb->lcd_set_foreground(LCD_WHITE); -#else - rb->lcd_putsxy(1+xoffset, 5*(h+2)+yoffset,"Controls"); -#endif - rb->lcd_putsxy(1+xoffset, 6*(h+2)+yoffset,"< & > Move the paddle"); +#define WORDS (sizeof help_text / sizeof (char*)) + static char* help_text[] = { + "BrickMania", "", "Aim", "", + "Destroy", "all", "the", "bricks", "by", "bouncing", + "the", "ball", "of", "them", "using", "the", "paddle.", "", "", + "Controls", "", + "< & >", "Move", "the", "paddle", "", #if CONFIG_KEYPAD == ONDIO_PAD - rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset, - "MENU Releases the ball/Fire!"); + "MENU", #elif (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == IAUDIO_M3_PAD) - rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset, - "PLAY Releases the ball/Fire!"); + "PLAY", #elif CONFIG_KEYPAD == IRIVER_H300_PAD - rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset, - "NAVI Releases the ball/Fire!"); + "NAVI", #else - rb->lcd_putsxy(1+xoffset, 7*(h+2)+yoffset, - "SELECT Releases the ball/Fire!"); + "SELECT", #endif + "Releases", "the", "ball/", "Fire!", "", #if CONFIG_KEYPAD == IAUDIO_M3_PAD - rb->lcd_putsxy(1+xoffset, 8*(h+2)+yoffset, "REC Opens menu/Quit"); + "REC", +#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \ + (CONFIG_KEYPAD == CREATIVEZVM_PAD) + "BACK", +#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ + (CONFIG_KEYPAD == IPOD_3G_PAD) || \ + (CONFIG_KEYPAD == IPOD_1G2G_PAD) + "MENU", +#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ + (CONFIG_KEYPAD == IRIVER_H300_PAD) || \ + (CONFIG_KEYPAD == ONDIO_PAD) || \ + (CONFIG_KEYPAD == RECORDER_PAD) || \ + (CONFIG_KEYPAD == ARCHOS_AV300_PAD) + "STOP", #else - rb->lcd_putsxy(1+xoffset, 8*(h+2)+yoffset, "STOP Opens menu/Quit"); + "POWER", #endif + "Opens", "menu/", "Quit", "", "", + "Specials", "", + "N", "Normal:", "returns", "paddle", "to", "normal", "", + "D", "DIE!:", "loses", "a", "life", "", + "L", "Life:", "gains", "a", "life/", "power", "up", "", + "F", "Fire:", "allows", "you", "to", "shoot", "bricks", "", + "G", "Glue:", "ball", "sticks", "to", "paddle", "", + "B", "Ball:", "generates", "another", "ball", "", + "FL", "Flip:", "flips", "left /", "right", "movement", + }; + static struct style_text formation[]={ + { 0, TEXT_CENTER|TEXT_UNDERLINE }, + { 2, C_RED }, + { 19, C_RED }, + { 38, C_RED }, + { 40, C_BLUE }, + { 47, C_RED }, + { 53, C_GREEN }, + { 61, C_ORANGE }, + { 69, C_GREEN }, + { 76, C_YELLOW }, + { 82, C_RED }, + { -1, 0 } + }; + #ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_RGBPACK(245,0,0)); - rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials"); - rb->lcd_set_foreground(LCD_WHITE); -#else - rb->lcd_putsxy(1+xoffset, 10*(h+2)+yoffset, "Specials"); + rb->lcd_set_background(LCD_BLACK); + rb->lcd_set_foreground(LCD_WHITE); #endif - rb->lcd_putsxy(1+xoffset, 11*(h+2)+yoffset, - "N Normal:returns paddle to normal"); - rb->lcd_putsxy(1+xoffset, 12*(h+2)+yoffset, "D DIE!:loses a life"); - rb->lcd_putsxy(1+xoffset, 13*(h+2)+yoffset, - "L Life:gains a life/power up"); - rb->lcd_putsxy(1+xoffset, 14*(h+2)+yoffset, - "F Fire:allows you to shoot bricks"); - rb->lcd_putsxy(1+xoffset, 15*(h+2)+yoffset, - "G Glue:ball sticks to paddle"); - rb->lcd_putsxy(1+xoffset, 16*(h+2)+yoffset, - "B Ball:generates another ball"); - rb->lcd_putsxy(1+xoffset, 17*(h+2)+yoffset, - "FL Flip:flips left / right movement"); - rb->lcd_update(); - button=rb->button_get(true); - switch (button) { -#ifdef RC_QUIT - case RC_QUIT: -#endif -#ifdef HAVE_TOUCHSCREEN - case BUTTON_TOUCHSCREEN: -#endif - case QUIT: - switch (game_menu(when)) { - case 0: - cur_level=0; - life=2; - int_game(1); - break; - case 1: - con_game=1; - break; - case 2: - if (help(when)==1) - return 1; - break; - case 3: - return 1; - break; - } - return 0; - break; - case LEFT: - case LEFT | BUTTON_REPEAT: -#ifdef ALTLEFT - case ALTLEFT: - case ALTLEFT | BUTTON_REPEAT: -#endif - if( xoffset<0) - xoffset+=2; - break; - case RIGHT: - case RIGHT | BUTTON_REPEAT: -#ifdef ALTRIGHT - case ALTRIGHT: - case ALTRIGHT | BUTTON_REPEAT: -#endif - if(xoffset+maxX > LCD_WIDTH) - xoffset-=2; - break; - case UP: - case UP | BUTTON_REPEAT: - if(yoffset <0) - yoffset+=2; - break; - case DOWN: - case DOWN | BUTTON_REPEAT: - if(yoffset+maxY > LCD_HEIGHT) - yoffset-=2; - break; - - default: - if(rb->default_event_handler(button) == SYS_USB_CONNECTED) - return 1; - break; - } - - rb->yield(); - } + rb->lcd_setfont(FONT_UI); + if (display_text(WORDS, help_text, formation, NULL)) + return 1; + do { + button = rb->button_get(true); + if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) + return 1; + } while( ( button == BUTTON_NONE ) + || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); + rb->lcd_setfont(FONT_SYSFIXED); return 0; } @@ -1315,10 +1246,6 @@ int game_loop(void) int sec_count=0,num_count=10; int end; - rb->srand( *rb->current_tick ); - - configfile_load(HIGH_SCORE,config,1,0); - switch(game_menu(0)) { case 0: cur_level = 0; @@ -1329,7 +1256,7 @@ int game_loop(void) con_game = 1; break; case 2: - if (help(0) == 1) return 1; + return help(); break; case 3: return 1; @@ -1885,22 +1812,7 @@ int game_loop(void) sleep(3); } - switch(game_menu(0)) { - case 0: - life=2; - cur_level=0; - int_game(1); - break; - case 1: - con_game=1; - break; - case 2: - if (help(0)==1) return 1; - break; - case 3: - return 1; - break; - } + return 0; } } @@ -2029,24 +1941,28 @@ int game_loop(void) case RC_QUIT: #endif case QUIT: - switch(game_menu(1)) { - case 0: - life=2; - cur_level=0; - int_game(1); - break; - case 1: - for(k=0;k *rb->current_tick) rb->sleep(end-*rb->current_tick); @@ -2128,6 +2028,10 @@ enum plugin_status plugin_start(const void* parameter) /* Turn off backlight timeout */ backlight_force_on(); /* backlight control in lib/helper.c */ + rb->srand( *rb->current_tick ); + + configfile_load(HIGH_SCORE,config,1,0); + /* now go ahead and have fun! */ while (game_loop()!=1); diff --git a/apps/plugins/clix.c b/apps/plugins/clix.c index a6a3bdd626..78bfdb8fdf 100644 --- a/apps/plugins/clix.c +++ b/apps/plugins/clix.c @@ -592,34 +592,34 @@ static int clix_clear_selected(struct clix_game_state_t* state) return state->status; } -static int clix_help(void) +static bool clix_help(void) { - rb->lcd_setfont(FONT_UI); - rb->lcd_set_foreground(LCD_WHITE); #define WORDS (sizeof help_text / sizeof (char*)) static char *help_text[] = { - "Clix", "", "Aim", "", "Remove", "all", "blocks", "from", "the", - "board", "to", "achieve", "the", "next", "level.", "You", "can", - "only", "remove", "blocks,", "if", "at", "least", "two", "blocks", - "with", "the", "same", "color", "have", "a", "direct", "connection.", - "The", "more", "blocks", "you", "remove", "per", "turn,", "the", - "more", "points", "you", "get." + "Clix", "", "Aim", "", + "Remove", "all", "blocks", "from", "the", "board", "to", "achieve", + "the", "next", "level.", "You", "can", "only", "remove", "blocks,", + "if", "at", "least", "two", "blocks", "with", "the", "same", "color", + "have", "a", "direct", "connection.", "The", "more", "blocks", "you", + "remove", "per", "turn,", "the", "more", "points", "you", "get." }; static struct style_text formation[]={ { 0, TEXT_CENTER|TEXT_UNDERLINE }, - { 2, C_RED } + { 2, C_RED }, + { -1, 0 } }; - - if (display_text(WORDS, help_text, formation, NULL)==PLUGIN_USB_CONNECTED) - return PLUGIN_USB_CONNECTED; int button; + + rb->lcd_setfont(FONT_UI); + rb->lcd_set_foreground(LCD_WHITE); + if (display_text(WORDS, help_text, formation, NULL)) + return true; do { button = rb->button_get(true); - if (button == SYS_USB_CONNECTED) { - return PLUGIN_USB_CONNECTED; - } + if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) + return true; } while( ( button == BUTTON_NONE ) - || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); + || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); rb->lcd_setfont(FONT_SYSFIXED); return 0; } @@ -656,7 +656,7 @@ static int clix_menu(struct clix_game_state_t* state, bool ingame) clix_init(state); return 0; case 2: - if (clix_help()==PLUGIN_USB_CONNECTED) + if (clix_help()) return 1; break; case 3: diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c index 08051c8e9e..f19c63fd24 100644 --- a/apps/plugins/jewels.c +++ b/apps/plugins/jewels.c @@ -38,6 +38,8 @@ PLUGIN_HEADER #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_PLAY #define JEWELS_CANCEL BUTTON_OFF +#define HK_SELECT "PLAY" +#define HK_CANCEL "OFF" #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD #define JEWELS_UP BUTTON_UP @@ -46,6 +48,8 @@ PLUGIN_HEADER #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_OFF +#define HK_SELECT "SELECT" +#define HK_CANCEL "OFF" #elif CONFIG_KEYPAD == ONDIO_PAD #define JEWELS_UP BUTTON_UP @@ -54,6 +58,8 @@ PLUGIN_HEADER #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_MENU #define JEWELS_CANCEL BUTTON_OFF +#define HK_SELECT "MENU" +#define HK_CANCEL "OFF" #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) #define JEWELS_UP BUTTON_UP @@ -63,6 +69,8 @@ PLUGIN_HEADER #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_OFF #define JEWELS_RC_CANCEL BUTTON_RC_STOP +#define HK_SELECT "SELECT" +#define HK_CANCEL "OFF" #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ (CONFIG_KEYPAD == IPOD_1G2G_PAD) @@ -75,6 +83,8 @@ PLUGIN_HEADER #define JEWELS_NEXT BUTTON_SCROLL_FWD #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL (BUTTON_SELECT | BUTTON_MENU) +#define HK_SELECT "SELECT" +#define HK_CANCEL "SEL + MENU" #elif (CONFIG_KEYPAD == IPOD_3G_PAD) #define JEWELS_LEFT BUTTON_LEFT @@ -83,6 +93,8 @@ PLUGIN_HEADER #define JEWELS_DOWN BUTTON_SCROLL_FWD #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_MENU +#define HK_SELECT "SELECT" +#define HK_CANCEL "MENU" #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD #define JEWELS_UP BUTTON_UP @@ -91,6 +103,8 @@ PLUGIN_HEADER #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_PLAY +#define HK_SELECT "SELECT" +#define HK_CANCEL "PLAY" #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD #define JEWELS_UP BUTTON_UP @@ -99,6 +113,8 @@ PLUGIN_HEADER #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_POWER +#define HK_SELECT "SELECT" +#define HK_CANCEL "POWER" #elif CONFIG_KEYPAD == GIGABEAT_PAD #define JEWELS_UP BUTTON_UP @@ -107,6 +123,8 @@ PLUGIN_HEADER #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_POWER +#define HK_SELECT "SELECT" +#define HK_CANCEL "POWER" #elif CONFIG_KEYPAD == SANSA_E200_PAD #define JEWELS_SCROLLWHEEL @@ -118,6 +136,8 @@ PLUGIN_HEADER #define JEWELS_NEXT BUTTON_SCROLL_FWD #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_POWER +#define HK_SELECT "SELECT" +#define HK_CANCEL "POWER" #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD) #define JEWELS_SCROLLWHEEL @@ -129,6 +149,8 @@ PLUGIN_HEADER #define JEWELS_NEXT BUTTON_SCROLL_FWD #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL (BUTTON_HOME|BUTTON_REPEAT) +#define HK_SELECT "SELECT" +#define HK_CANCEL "HOME" #elif CONFIG_KEYPAD == SANSA_C200_PAD || \ CONFIG_KEYPAD == SANSA_CLIP_PAD || \ @@ -139,6 +161,8 @@ CONFIG_KEYPAD == SANSA_M200_PAD #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_POWER +#define HK_SELECT "SELECT" +#define HK_CANCEL "POWER" #elif CONFIG_KEYPAD == IRIVER_H10_PAD #define JEWELS_UP BUTTON_SCROLL_UP @@ -147,6 +171,8 @@ CONFIG_KEYPAD == SANSA_M200_PAD #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_PLAY #define JEWELS_CANCEL BUTTON_POWER +#define HK_SELECT "PLAY" +#define HK_CANCEL "POWER" #elif CONFIG_KEYPAD == GIGABEAT_S_PAD #define JEWELS_UP BUTTON_UP @@ -155,6 +181,8 @@ CONFIG_KEYPAD == SANSA_M200_PAD #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_BACK +#define HK_SELECT "SELECT" +#define HK_CANCEL "BACK" #elif CONFIG_KEYPAD == MROBE100_PAD #define JEWELS_UP BUTTON_UP @@ -163,6 +191,8 @@ CONFIG_KEYPAD == SANSA_M200_PAD #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_POWER +#define HK_SELECT "SELECT" +#define HK_CANCEL "POWER" #elif CONFIG_KEYPAD == IAUDIO_M3_PAD #define JEWELS_UP BUTTON_RC_VOL_UP @@ -171,10 +201,14 @@ CONFIG_KEYPAD == SANSA_M200_PAD #define JEWELS_RIGHT BUTTON_RC_FF #define JEWELS_SELECT BUTTON_RC_PLAY #define JEWELS_CANCEL BUTTON_RC_REC +#define HK_SELECT "PLAY" +#define HK_CANCEL "REC" + #define JEWELS_RC_CANCEL BUTTON_REC #elif CONFIG_KEYPAD == COWOND2_PAD #define JEWELS_CANCEL BUTTON_POWER +#define HK_CANCEL "POWER" #elif CONFIG_KEYPAD == IAUDIO67_PAD #define JEWELS_UP BUTTON_STOP @@ -183,6 +217,8 @@ CONFIG_KEYPAD == SANSA_M200_PAD #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_MENU #define JEWELS_CANCEL BUTTON_POWER +#define HK_SELECT "MENU" +#define HK_CANCEL "POWER" #elif CONFIG_KEYPAD == CREATIVEZVM_PAD #define JEWELS_UP BUTTON_UP @@ -191,6 +227,8 @@ CONFIG_KEYPAD == SANSA_M200_PAD #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_BACK +#define HK_SELECT "MIDDLE" +#define HK_CANCEL "BACK" #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD #define JEWELS_UP BUTTON_UP @@ -199,10 +237,13 @@ CONFIG_KEYPAD == SANSA_M200_PAD #define JEWELS_RIGHT BUTTON_RIGHT #define JEWELS_SELECT BUTTON_SELECT #define JEWELS_CANCEL BUTTON_POWER +#define HK_SELECT "SELECT" +#define HK_CANCEL "POWER" #elif CONFIG_KEYPAD == ONDAVX747_PAD || \ CONFIG_KEYPAD == MROBE500_PAD #define JEWELS_CANCEL BUTTON_POWER +#define HK_CANCEL "POWER" #else #error No keymap defined! @@ -223,9 +264,11 @@ CONFIG_KEYPAD == MROBE500_PAD #endif #ifndef JEWELS_SELECT #define JEWELS_SELECT BUTTON_CENTER +#define HK_SELECT "CENTER" #endif #ifndef JEWELS_CANCEL #define JEWELS_CANCEL BUTTON_TOPLEFT +#define HK_CANCEL "TOPLEFT" #endif #endif @@ -1312,15 +1355,26 @@ static int jewels_help(void) rb->lcd_setfont(FONT_UI); #define WORDS (sizeof help_text / sizeof (char*)) static char *help_text[] = { - "Jewels", "", "Aim", "", "Swap", "pairs", "of", "jewels", "to", - "form", "connected", "segments", "of", "three", "or", "more", "of", - "the", "same", "type.", "", "The", "goal", "of", "the", "game", - "is", "to", "score", "as", "many", "points", "as", "possible", - "before", "running", "out", "of", "available", "moves." + "Jewels", "", "Aim", "", + "Swap", "pairs", "of", "jewels", "to", "form", "connected", + "segments", "of", "three", "or", "more", "of", "the", "same", + "type.", "", + "The", "goal", "of", "the", "game", "is", "to", "score", "as", "many", + "points", "as", "possible", "before", "running", "out", "of", + "available", "moves.", "", "", + "Controls", "", + "Directions", +#ifdef JEWELS_SCROLLWHEEL + "or", "scroll", +#endif + "to", "move", "", + HK_SELECT, "to", "select", "", + HK_CANCEL, "to", "go", "to", "menu" }; static struct style_text formation[]={ { 0, TEXT_CENTER|TEXT_UNDERLINE }, - { 2, C_RED } + { 2, C_RED }, + { -1, 0 } }; #ifdef HAVE_LCD_COLOR diff --git a/apps/plugins/lib/display_text.c b/apps/plugins/lib/display_text.c index 67c78ec242..c6b5710644 100644 --- a/apps/plugins/lib/display_text.c +++ b/apps/plugins/lib/display_text.c @@ -134,11 +134,6 @@ bool display_text(short words, char** text, struct style_text* style, rb->screens[SCREEN_MAIN]->update_viewport(); #ifdef HAVE_LCD_BITMAP rb->lcd_set_drawmode(prev_drawmode); -#endif -#ifdef HAVE_LCD_COLOR - if (style!=NULL) { - rb->lcd_set_foreground(standard_fgcolor); - } #endif return false; } diff --git a/apps/plugins/pegbox.c b/apps/plugins/pegbox.c index d6f87cd46b..eb53eca8b5 100644 --- a/apps/plugins/pegbox.c +++ b/apps/plugins/pegbox.c @@ -19,6 +19,7 @@ * ****************************************************************************/ #include "plugin.h" +#include "lib/display_text.h" #include "pluginbitmaps/pegbox_header.h" #include "pluginbitmaps/pegbox_pieces.h" @@ -719,111 +720,6 @@ char levels[NUM_LEVELS][ROWS][COLS] = { }; -/***************************************************************************** -* display_text() formats and outputs text. -******************************************************************************/ -static void display_text(char *str, bool waitkey) -{ - int chars_by_line; - int lines_by_screen; - int chars_for_line; - int current_line = 0; - int char_width, char_height; - int first_char_index = 0; - char *ptr_char; - char *ptr_line; - int i; - char line[255]; - int key; - bool go_on; - - rb->lcd_clear_display(); - - rb->lcd_getstringsize("a", &char_width, &char_height); - - chars_by_line = LCD_WIDTH / char_width; - lines_by_screen = LCD_HEIGHT / char_height; - - do - { - ptr_char = str + first_char_index; - chars_for_line = 0; - i = 0; - ptr_line = line; - while (i < chars_by_line) - { - switch (*ptr_char) - { - case '\t': - case ' ': - *(ptr_line++) = ' '; - case '\n': - case '\0': - chars_for_line = i; - break; - - default: - *(ptr_line++) = *ptr_char; - } - if (*ptr_char == '\n' || *ptr_char == '\0') - break; - ptr_char++; - i++; - } - - if (chars_for_line == 0) - chars_for_line = i; - - line[chars_for_line] = '\0'; - - /* test if we have cut a word. If it is the case we don't have to */ - /* skip the space */ - if (i == chars_by_line && chars_for_line == chars_by_line) - first_char_index += chars_for_line; - else - first_char_index += chars_for_line + 1; - - /* print the line on the screen */ - rb->lcd_putsxy(0, current_line * char_height, line); - - /* if the number of line showed on the screen is equals to the */ - /* maximum number of line we can show, we wait for a key pressed to */ - /* clear and show the remaining text. */ - current_line++; - if (current_line == lines_by_screen || *ptr_char == '\0') - { - current_line = 0; - rb->lcd_update(); - go_on = false; - while (waitkey && !go_on) - { - key = rb->button_get(true); - switch (key) - { -#ifdef HAVE_TOUCHSCREEN - case BUTTON_TOUCHSCREEN: -#endif - case PEGBOX_QUIT: - case PEGBOX_LEFT: - case PEGBOX_DOWN: - go_on = true; - break; - - default: - /*if (rb->default_event_handler(key) == SYS_USB_CONNECTED) - { - usb_detected = true; - go_on = true; - break; - }*/ - break; - } - } - rb->lcd_clear_display(); - } - } while (*ptr_char != '\0'); -} - /***************************************************************************** * draw_board() draws the game's current level. ******************************************************************************/ @@ -1127,6 +1023,48 @@ static void pegbox_callback(void* param) { pegbox_savedata(pb); } +/*********************************************************************** +* pegbox_help() display help text +************************************************************************/ +static bool pegbox_help(void) +{ + int button; +#define WORDS (sizeof help_text / sizeof (char*)) + static char* help_text[] = { + "Pegbox", "", "Aim", "", + "To", "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.", "", "", + "Controls", "", + RESTART_TEXT, "to", "restart", "level", "", + LVL_UP_TEXT, "to", "go", "up", "a", "level", "", + LVL_DOWN_TEXT, "to", "go", "down", "a", "level", "", + SAVE_TEXT, "to", "select/save", "", + QUIT_TEXT, "to", "quit" + }; + static struct style_text formation[]={ + { 0, TEXT_CENTER|TEXT_UNDERLINE }, + { 2, C_RED }, + { 46, C_RED }, + { -1, 0 } + }; + + rb->lcd_setfont(FONT_UI); + + if (display_text(WORDS, help_text, formation, NULL)) + return true; + do { + button = rb->button_get(true); + if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) + return true; + } while( ( button == BUTTON_NONE ) + || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); + rb->lcd_setfont(FONT_SYSFIXED); + return false; +} + /***************************************************************************** * pegbox_menu() is the initial menu at the start of the game. ******************************************************************************/ @@ -1251,28 +1189,12 @@ static unsigned int pegbox_menu(struct game_context* pb) { 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 + { + if(pegbox_help()) + return PB_USB; + } else if (loc == 3) return PB_QUIT; break; @@ -1462,7 +1384,7 @@ enum plugin_status plugin_start(const void* parameter) { rb->lcd_setfont(FONT_SYSFIXED); #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); -#endif +#endif #ifdef HAVE_LCD_COLOR rb->lcd_set_foreground(LCD_WHITE); rb->lcd_set_background(BG_COLOR); diff --git a/apps/plugins/robotfindskitten.c b/apps/plugins/robotfindskitten.c index 1010531951..ed3cda2fc7 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/display_text.h" /* This macros must always be included. Should be placed at the top by convention, although the actual position doesn't matter */ @@ -692,7 +693,7 @@ static void play_game() #else input = rb->button_get(true); #endif - } + } message("Bye!"); refresh(); } @@ -794,7 +795,7 @@ static int validchar(char a) switch(a) { case '#': - case ' ': + case ' ': case 127: return 0; } @@ -850,45 +851,23 @@ static void play_animation(int input) static void instructions() { -#define MARGIN 2 - int y = MARGIN, space_w, width, height; - unsigned short x = MARGIN, i = 0; -#define WORDS (sizeof instructions / sizeof (char*)) - static char* instructions[] = { +#define WORDS (sizeof help_text / sizeof (char*)) + static char* help_text[] = { #if 0 /* Not sure if we want to include this? */ "robotfindskitten", RFK_VERSION, "", "", "By", "the", "illustrious", "Leonard", "Richardson", "(C)", "1997,", "2000", "", "Written", "originally", "for", "the", "Nerth", "Pork", "robotfindskitten", "contest", "", "", #endif - "In", "this", "game", "you", "are", "robot", "(#).", "Your", "job", "is", "to", "find", "kitten.", "This", "task", "is", "complicated", "by", "the", "existence", "of", "various", "things", "which", "are", "not", "kitten.", "Robot", "must", "touch", "items", "to", "determine", "if", "they", "are", "kitten", "or", "not.", "", + "In", "this", "game", "you", "are", "robot", "(#).", "Your", "job", "is", + "to", "find", "kitten.", "This", "task", "is", "complicated", "by", "the", + "existence", "of", "various", "things", "which", "are", "not", "kitten.", + "Robot", "must", "touch", "items", "to", "determine", "if", "they", "are", + "kitten", "or", "not.", "", "The", "game", "ends", "when", "robotfindskitten.", "", "", "Press", "any", "key", "to", "start", }; - rb->lcd_clear_display(); - rb->lcd_getstringsize(" ", &space_w, &height); - for (i = 0; i < WORDS; i++) { - rb->lcd_getstringsize(instructions[i], &width, NULL); - /* Skip to next line if the current one can't fit the word */ - if (x + width > LCD_WIDTH - MARGIN) { - x = MARGIN; - y += height; - } - /* .. or if the word is the empty string */ - if (rb->strcmp(instructions[i], "") == 0) { - x = MARGIN; - y += height; - continue; - } - /* We filled the screen */ - if (y + height > LCD_HEIGHT - MARGIN) { - y = MARGIN; - pause(); - rb->lcd_clear_display(); - } - rb->lcd_putsxy(x, y, instructions[i]); - x += width + space_w; - } + display_text(WORDS, help_text, NULL, NULL); pause(); } @@ -953,7 +932,7 @@ static void initialize_kitten() /*Assign the kitten a character and a color.*/ do { kitten.character = randchar(); - } while (!(validchar(kitten.character))); + } while (!(validchar(kitten.character))); screen[kitten.x][kitten.y] = KITTEN; kitten.color = colors[randcolor()]; @@ -973,7 +952,7 @@ static void initialize_bogus() /*Give it a character.*/ do { bogus[counter].character = randchar(); - } while (!(validchar(bogus[counter].character))); + } while (!(validchar(bogus[counter].character))); /*Give it a position.*/ do { @@ -1059,7 +1038,7 @@ enum plugin_status plugin_start(const void* parameter) /* * Run the game */ - instructions(); + instructions(); initialize_screen(); diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index 47b1b25fa0..668f0d5f96 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c @@ -22,6 +22,7 @@ #include "plugin.h" #include "lib/playback_control.h" #include "lib/configfile.h" +#include "lib/display_text.h" #include "button.h" #include "lcd.h" @@ -447,26 +448,6 @@ PLUGIN_HEADER # define HK_UD "UP/DOWN" #endif -/** - * Help strings - */ - -static int helplines; -static int displaylines; - -static char helptext[] = - /* Use single spaces only! Close each line with one \0. */ - "-- Navigation --\0" - HK_LR ": Move the cursor to the previous/ next column.\0" - HK_UD ": Move the cursor up/ down in the column.\0" - HK_MOVE ": Select cards, move cards, reveal hidden cards...\0" - HK_DRAW ": Deselect a card if it was selected. Else draw new card(s) from the remains stack.\0" - "-- Shortcuts --\0" - HK_REM2CUR ": Put the card on top of the remains stack on top of the cursor.\0" - HK_CUR2STACK ": Put the card under the cursor on one of the 4 final stacks.\0" - HK_REM2STACK ": Put the card on top of the remains stack on one of the 4 final stacks.\0" -; - /** * Misc constants, graphics and other defines */ @@ -634,122 +615,41 @@ static void draw_empty_stack( int s, int x, int y, bool cursor ) draw_card_ext( x, y, false, cursor ); } -/** - * Help - */ - -static void init_help(void) -{ - int lines = 0; - int w_space, w, h; - int para_len; - char *para = helptext; - - rb->lcd_getstringsize(" ", &w_space, &h); - displaylines = LCD_HEIGHT / h; - para_len = rb->strlen(para); - - while (para_len) - { - bool first = true; - int x = 0; - char *next, *store; - - next = rb->strtok_r(para, " ", &store); - while (next) - { - rb->lcd_getstringsize(next, &w, NULL); - if (!first) - { - if (x + w > LCD_WIDTH) - { - lines++; - x = 0; - } - else - next[-1] = ' '; /* re-concatenate string */ - } - else - first = false; - - x += w + w_space; - next = rb->strtok_r(NULL, " ", &store); - } - - lines++; - para += para_len + 1; - para_len = rb->strlen(para); - } - helplines = lines; -} - -enum help { HELP_QUIT, HELP_USB }; - -/* help for the not so intuitive interface */ -enum help solitaire_help( void ) +/* Help */ +static bool solitaire_help( void ) { - int start = 0; int button; - int lastbutton = BUTTON_NONE; - bool fixed = (displaylines >= helplines); - - while( true ) - { - char *text = helptext; - int line = fixed ? (displaylines - helplines) / 2 : 0; - int i; - - rb->lcd_clear_display(); - - for (i = 0; i < start + displaylines; i++) - { - if (i >= start) - rb->lcd_puts(0, line++, text); - text += rb->strlen(text) + 1; - } - rb->lcd_update(); - - button = rb->button_get( true ); - switch( button ) - { - case SOL_UP: -#ifdef SOL_UP_PRE - if( lastbutton != SOL_UP_PRE ) - break; -#else - case SOL_UP|BUTTON_REPEAT: -#endif - if (!fixed && start > 0) - start--; - break; - - case SOL_DOWN: -#ifdef SOL_DOWN_PRE - if( lastbutton != SOL_DOWN_PRE ) - break; -#else - case SOL_DOWN|BUTTON_REPEAT: -#endif - if (!fixed && start < helplines - displaylines) - start++; - break; - -#ifdef SOL_RC_QUIT - case SOL_RC_QUIT: -#endif - case SOL_QUIT: - return HELP_QUIT; - - default: - if( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) - return HELP_USB; - break; - } - if( button != BUTTON_NONE ) - lastbutton = button; - - rb->yield(); - } +#define WORDS (sizeof help_text / sizeof (char*)) + static char* help_text[] = { + "Solitaire", "", "Controlls", "", + HK_LR ":", "Move", "the", "cursor", "to", "the", + "previous/", "next", "column.", "", + HK_UD ":", "Move", "the", "cursor", "up/", "down", "in", "the", + "column.", "", + HK_MOVE ":", "Select", "cards,", "move", "cards...", "", + HK_DRAW ":", "Deselect", "a", "card", "if", "it", "was", "selected.", + "Else", "draw", "new", "card(s)", "from", "the", "remains", + "stack.", "", "", + "Shortcuts", "", + HK_REM2CUR ":", "Put", "the", "card", "on", "top", "of", "the", + "remains", "stack", "on", "top", "of", "the", "cursor.", "", + HK_CUR2STACK ":", "Put", "the", "card", "under", "the", "cursor", + "on", "one", "of", "the", "4", "final", "stacks.", "", + HK_REM2STACK ":", "Put", "the", "card", "on", "top", "of", "the", + "remains", "stack", "on", "one", "of", "the", "4", "final", + "stacks." + }; + + if (display_text(WORDS, help_text, NULL, NULL)) + return true; + do { + button = rb->button_get(true); + if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) + return true; + } while( ( button == BUTTON_NONE ) + || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); + + return false; } /** @@ -831,7 +731,7 @@ int solitaire_menu(bool in_game) break; case 3: - if (solitaire_help() == HELP_USB) + if (solitaire_help()) result = MENU_USB; break; @@ -1929,8 +1829,6 @@ enum plugin_status plugin_start(const void* parameter ) else result = SOLITAIRE_WIN; - init_help(); - /* play the game :) * Keep playing if a game was won (that means display the menu after * winning instead of quiting) */ diff --git a/apps/plugins/star.c b/apps/plugins/star.c index 4bb3afcbd5..0ab6dce17b 100644 --- a/apps/plugins/star.c +++ b/apps/plugins/star.c @@ -20,6 +20,7 @@ ****************************************************************************/ #include "plugin.h" #ifdef HAVE_LCD_BITMAP +#include "lib/display_text.h" PLUGIN_HEADER @@ -66,6 +67,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP BUTTON_F3 #define STAR_LEVEL_DOWN BUTTON_F1 #define STAR_LEVEL_REPEAT BUTTON_F2 +#define STAR_TOGGLE_CONTROL_NAME "ON" +#define STAR_QUIT_NAME "OFF" +#define STAR_LEVEL_UP_NAME "F3" +#define STAR_LEVEL_DOWN_NAME "F1" +#define STAR_LEVEL_REPEAT_NAME "F2" #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD #define STAR_QUIT BUTTON_OFF @@ -78,6 +84,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP BUTTON_F3 #define STAR_LEVEL_DOWN BUTTON_F1 #define STAR_LEVEL_REPEAT BUTTON_F2 +#define STAR_TOGGLE_CONTROL_NAME "ON/SELECT" +#define STAR_QUIT_NAME "OFF" +#define STAR_LEVEL_UP_NAME "F3" +#define STAR_LEVEL_DOWN_NAME "F1" +#define STAR_LEVEL_REPEAT_NAME "F2" #elif CONFIG_KEYPAD == ONDIO_PAD #define STAR_QUIT BUTTON_OFF @@ -90,6 +101,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP (BUTTON_MENU | BUTTON_RIGHT) #define STAR_LEVEL_DOWN (BUTTON_MENU | BUTTON_LEFT) #define STAR_LEVEL_REPEAT (BUTTON_MENU | BUTTON_UP) +#define STAR_TOGGLE_CONTROL_NAME "MODE" +#define STAR_QUIT_NAME "OFF" +#define STAR_LEVEL_UP_NAME "M >" +#define STAR_LEVEL_DOWN_NAME "M <" +#define STAR_LEVEL_REPEAT_NAME "M ^" #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ (CONFIG_KEYPAD == IRIVER_H300_PAD) @@ -103,6 +119,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP (BUTTON_ON | BUTTON_RIGHT) #define STAR_LEVEL_DOWN (BUTTON_ON | BUTTON_LEFT) #define STAR_LEVEL_REPEAT (BUTTON_ON | BUTTON_SELECT) +#define STAR_TOGGLE_CONTROL_NAME "MODE/SELECT" +#define STAR_QUIT_NAME "OFF" +#define STAR_LEVEL_UP_NAME "ON + RIGHT" +#define STAR_LEVEL_DOWN_NAME "ON + LEFT" +#define STAR_LEVEL_REPEAT_NAME "ON + NAVI" #define STAR_RC_QUIT BUTTON_RC_STOP #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ @@ -119,6 +140,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT) #define STAR_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT) #define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_PLAY) +#define STAR_TOGGLE_CONTROL_NAME "SELECT" +#define STAR_QUIT_NAME "S + MENU" +#define STAR_LEVEL_UP_NAME "S >" +#define STAR_LEVEL_DOWN_NAME "S <" +#define STAR_LEVEL_REPEAT_NAME "S + PLAY" #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) @@ -133,6 +159,11 @@ PLUGIN_HEADER #define STAR_LEVEL_DOWN_PRE BUTTON_REC #define STAR_LEVEL_DOWN (BUTTON_REC|BUTTON_REPEAT) #define STAR_LEVEL_REPEAT BUTTON_PLAY +#define STAR_TOGGLE_CONTROL_NAME "SELECT" +#define STAR_QUIT_NAME "POWER" +#define STAR_LEVEL_UP_NAME "REC" +#define STAR_LEVEL_DOWN_NAME "REC.." +#define STAR_LEVEL_REPEAT_NAME "PLAY" #elif (CONFIG_KEYPAD == GIGABEAT_PAD) @@ -145,13 +176,18 @@ PLUGIN_HEADER #define STAR_LEVEL_UP BUTTON_VOL_UP #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN #define STAR_LEVEL_REPEAT BUTTON_A +#define STAR_TOGGLE_CONTROL_NAME "SELECT" +#define STAR_QUIT_NAME "POWER" +#define STAR_LEVEL_UP_NAME "VOL UP" +#define STAR_LEVEL_DOWN_NAME "VOL DOWN" +#define STAR_LEVEL_REPEAT_NAME "A" #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ (CONFIG_KEYPAD == SANSA_C200_PAD) || \ (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \ (CONFIG_KEYPAD == SANSA_M200_PAD) -#define STAR_QUIT BUTTON_POWER +#define STAR_QUIT BUTTON_POWER #define STAR_LEFT BUTTON_LEFT #define STAR_RIGHT BUTTON_RIGHT #define STAR_UP BUTTON_UP @@ -160,11 +196,15 @@ PLUGIN_HEADER #define STAR_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT) #define STAR_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT) #define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_DOWN) - +#define STAR_TOGGLE_CONTROL_NAME "SELECT" +#define STAR_QUIT_NAME "POWER" +#define STAR_LEVEL_UP_NAME "SELECT + RIGHT" +#define STAR_LEVEL_DOWN_NAME "SELECT + LEFT" +#define STAR_LEVEL_REPEAT_NAME "SELECT + DOWN" #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD) -#define STAR_QUIT (BUTTON_HOME|BUTTON_REPEAT) +#define STAR_QUIT (BUTTON_HOME|BUTTON_REPEAT) #define STAR_LEFT BUTTON_LEFT #define STAR_RIGHT BUTTON_RIGHT #define STAR_UP BUTTON_UP @@ -173,6 +213,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP (BUTTON_SELECT | BUTTON_RIGHT) #define STAR_LEVEL_DOWN (BUTTON_SELECT | BUTTON_LEFT) #define STAR_LEVEL_REPEAT (BUTTON_SELECT | BUTTON_DOWN) +#define STAR_TOGGLE_CONTROL_NAME "SELECT" +#define STAR_QUIT_NAME "HOME" +#define STAR_LEVEL_UP_NAME "SELECT + RIGHT" +#define STAR_LEVEL_DOWN_NAME "SELECT + LEFT" +#define STAR_LEVEL_REPEAT_NAME "SELECT + DOWN" #elif (CONFIG_KEYPAD == IRIVER_H10_PAD) @@ -185,6 +230,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP (BUTTON_PLAY | BUTTON_SCROLL_UP) #define STAR_LEVEL_DOWN (BUTTON_PLAY | BUTTON_SCROLL_DOWN) #define STAR_LEVEL_REPEAT (BUTTON_PLAY | BUTTON_RIGHT) +#define STAR_TOGGLE_CONTROL_NAME "REW" +#define STAR_QUIT_NAME "POWER" +#define STAR_LEVEL_UP_NAME "PLAY+UP" +#define STAR_LEVEL_DOWN_NAME "PLAY+DOWN" +#define STAR_LEVEL_REPEAT_NAME "PLAY+RIGHT" #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) @@ -197,6 +247,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP BUTTON_VOL_UP #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN #define STAR_LEVEL_REPEAT BUTTON_MENU +#define STAR_TOGGLE_CONTROL_NAME "SELECT" +#define STAR_QUIT_NAME "BACK" +#define STAR_LEVEL_UP_NAME "VOL UP" +#define STAR_LEVEL_DOWN_NAME "VOL DOWN" +#define STAR_LEVEL_REPEAT_NAME "MENU" #elif (CONFIG_KEYPAD == MROBE100_PAD) @@ -209,6 +264,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP BUTTON_PLAY #define STAR_LEVEL_DOWN BUTTON_MENU #define STAR_LEVEL_REPEAT BUTTON_DISPLAY +#define STAR_TOGGLE_CONTROL_NAME "SELECT" +#define STAR_QUIT_NAME "POWER" +#define STAR_LEVEL_UP_NAME "PLAY" +#define STAR_LEVEL_DOWN_NAME "MENU" +#define STAR_LEVEL_REPEAT_NAME "DISPLAY" #elif CONFIG_KEYPAD == IAUDIO_M3_PAD @@ -221,11 +281,16 @@ PLUGIN_HEADER #define STAR_LEVEL_UP (BUTTON_RC_PLAY|BUTTON_RC_VOL_UP) #define STAR_LEVEL_DOWN (BUTTON_RC_PLAY|BUTTON_RC_VOL_DOWN) #define STAR_LEVEL_REPEAT (BUTTON_RC_PLAY|BUTTON_RC_MENU) +#define STAR_TOGGLE_CONTROL_NAME "MODE" +#define STAR_QUIT_NAME "REC" +#define STAR_LEVEL_UP_NAME "PLAY+VOL+" +#define STAR_LEVEL_DOWN_NAME "PLAY+VOL-" +#define STAR_LEVEL_REPEAT_NAME "PLAY+MENU" #elif (CONFIG_KEYPAD == COWOND2_PAD) #define STAR_QUIT BUTTON_POWER -#define STAR_QUIT_NAME "[POWER]" +#define STAR_QUIT_NAME "POWER" #elif CONFIG_KEYPAD == CREATIVEZVM_PAD @@ -238,6 +303,11 @@ PLUGIN_HEADER #define STAR_LEVEL_UP (BUTTON_CUSTOM | BUTTON_UP) #define STAR_LEVEL_DOWN (BUTTON_CUSTOM | BUTTON_DOWN) #define STAR_LEVEL_REPEAT (BUTTON_CUSTOM | BUTTON_RIGHT) +#define STAR_TOGGLE_CONTROL_NAME "PLAY" +#define STAR_QUIT_NAME "BACK" +#define STAR_LEVEL_UP_NAME "CUSTOM+UP" +#define STAR_LEVEL_DOWN_NAME "CUSTOM+DOWN" +#define STAR_LEVEL_REPEAT_NAME "CUSTOM+RIGHT" #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD @@ -250,15 +320,20 @@ PLUGIN_HEADER #define STAR_LEVEL_UP BUTTON_VOL_UP #define STAR_LEVEL_DOWN BUTTON_VOL_DOWN #define STAR_LEVEL_REPEAT BUTTON_VIEW +#define STAR_TOGGLE_CONTROL_NAME "SELECT" +#define STAR_QUIT_NAME "POWER" +#define STAR_LEVEL_UP_NAME "VOL UP" +#define STAR_LEVEL_DOWN_NAME "VOL DOWN" +#define STAR_LEVEL_REPEAT_NAME "VIEW" #elif (CONFIG_KEYPAD == ONDAVX747_PAD) #define STAR_QUIT BUTTON_POWER -#define STAR_QUIT_NAME "[POWER]" +#define STAR_QUIT_NAME "POWER" #elif CONFIG_KEYPAD == MROBE500_PAD #define STAR_QUIT BUTTON_POWER -#define STAR_QUIT_NAME "[POWER]" +#define STAR_QUIT_NAME "POWER" #else #error No keymap defined! @@ -267,7 +342,7 @@ PLUGIN_HEADER #ifdef HAVE_TOUCHSCREEN //#ifndef STAR_QUIT //#define STAR_QUIT BUTTON_TOPLEFT -//#define STAR_QUIT_NAME "[TOPLEFT]" +//#define STAR_QUIT_NAME "TOPLEFT" //#endif #ifndef STAR_LEFT #define STAR_LEFT BUTTON_MIDLEFT @@ -283,19 +358,19 @@ PLUGIN_HEADER #endif #ifndef STAR_TOGGLE_CONTROL #define STAR_TOGGLE_CONTROL BUTTON_CENTER -#define STAR_TOGGLE_CONTROL_NAME "[CENTER]" +#define STAR_TOGGLE_CONTROL_NAME "CENTER" #endif #ifndef STAR_LEVEL_UP #define STAR_LEVEL_UP BUTTON_TOPLEFT -#define STAR_LEVEL_UP_NAME "[TOPLEFT]" +#define STAR_LEVEL_UP_NAME "TOPLEFT" #endif #ifndef STAR_LEVEL_DOWN #define STAR_LEVEL_DOWN BUTTON_BOTTOMLEFT -#define STAR_LEVEL_DOWN_NAME "[BOTTOMLEFT]" +#define STAR_LEVEL_DOWN_NAME "BOTTOMLEFT" #endif #ifndef STAR_LEVEL_REPEAT #define STAR_LEVEL_REPEAT BUTTON_BOTTOMRIGHT -#define STAR_LEVEL_REPEAT_NAME "[BOTTOMRIGHT]" +#define STAR_LEVEL_REPEAT_NAME "BOTTOMRIGHT" #endif #endif @@ -538,104 +613,6 @@ static unsigned char* levels = "*........o*o...*\n" "****************"; -/** - * Display text. - */ -void star_display_text(char *str, bool waitkey) -{ - int chars_by_line; - int lines_by_screen; - int chars_for_line; - int current_line = 0; - int first_char_index = 0; - char *ptr_char; - char *ptr_line; - int i; - char line[255]; - int key; - bool go_on; - - rb->lcd_clear_display(); - - chars_by_line = LCD_WIDTH / char_width; - lines_by_screen = LCD_HEIGHT / char_height; - - do - { - ptr_char = str + first_char_index; - chars_for_line = 0; - i = 0; - ptr_line = line; - while (i < chars_by_line) - { - switch (*ptr_char) - { - case '\t': - case ' ': - *(ptr_line++) = ' '; - case '\n': - case '\0': - chars_for_line = i; - break; - - default: - *(ptr_line++) = *ptr_char; - } - if (*ptr_char == '\n' || *ptr_char == '\0') - break; - ptr_char++; - i++; - } - - if (chars_for_line == 0) - chars_for_line = i; - - line[chars_for_line] = '\0'; - - /* test if we have cut a word. If it is the case we don't have to */ - /* skip the space */ - if (i == chars_by_line && chars_for_line == chars_by_line) - first_char_index += chars_for_line; - else - first_char_index += chars_for_line + 1; - - /* print the line on the screen */ - rb->lcd_putsxy(0, current_line * char_height, line); - - /* if the number of line showed on the screen is equals to the */ - /* maximum number of line we can show, we wait for a key pressed to */ - /* clear and show the remaining text. */ - current_line++; - if (current_line == lines_by_screen || *ptr_char == '\0') - { - current_line = 0; - rb->lcd_update(); - go_on = false; - while (waitkey && !go_on) - { - key = rb->button_get(true); - switch (key) - { - case STAR_QUIT: - case STAR_LEFT: - case STAR_DOWN: - go_on = true; - break; - - default: - if (rb->default_event_handler(key) == SYS_USB_CONNECTED) - { - usb_detected = true; - go_on = true; - break; - } - } - } - rb->lcd_clear_display(); - } - } while (*ptr_char != '\0'); -} - /** * Do a pretty transition from one level to another. */ @@ -986,7 +963,7 @@ static int star_run_game(int current_level) if (current_level == STAR_LEVEL_COUNT) { rb->lcd_clear_display(); - star_display_text("Congratulations!", true); + rb->splash(HZ*2, "Congratulations!"); rb->lcd_update(); /* There is no such level as STAR_LEVEL_COUNT so it can't be the @@ -999,6 +976,45 @@ static int star_run_game(int current_level) } } +/** + * Display help text. + */ +static bool star_help(void) +{ + int button; +#define WORDS (sizeof help_text / sizeof (char*)) + static char* help_text[] = { + "Star", "", "Aim", "", + "Take", "all", "the", "stars", "to", "go", "to", "the", "next", "level.", + "You", "can", "toggle", "control", "with", "the", "block", "to", "use", + "it", "as", "a", "mobile", "wall.", "The", "block", "cannot", "take", + "stars.", "", "", + "Controls", "", + STAR_TOGGLE_CONTROL_NAME":", "Toggle", "Control", "", + STAR_QUIT_NAME":", "", "Exit", "", + STAR_LEVEL_DOWN_NAME":", "Prev.", "level", "", + STAR_LEVEL_REPEAT_NAME":", "Reset", "level", "", + STAR_LEVEL_UP_NAME":", "Next", "level" + }; + static struct style_text formation[]={ + { 0, TEXT_CENTER|TEXT_UNDERLINE }, + { 2, C_RED }, + { 35, C_RED }, + { -1, 0 } + }; + + if (display_text(WORDS, help_text, formation, NULL)) + return true; + do { + button = rb->button_get(true); + if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) + return true; + } while( ( button == BUTTON_NONE ) + || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); + + return false; +} + /** * Display the choice menu. */ @@ -1010,7 +1026,7 @@ static int star_menu(void) rb->lcd_getstringsize("a", &char_width, &char_height); MENUITEM_STRINGLIST(menu,"Star Menu",NULL,"Play","Choose Level", - "Information","Keys","Quit"); + "Help", "Quit"); while(!menu_quit) { @@ -1024,80 +1040,8 @@ static int star_menu(void) NULL, 1, 1, STAR_LEVEL_COUNT, NULL ); break; case 2: - star_display_text( - "INFO\n\n" - "Take all the stars to go to the next level. " - "You can toggle control with the block to " - "use it as a mobile wall. The block cannot " - "take stars.", true); - break; - case 3: -#if CONFIG_KEYPAD == RECORDER_PAD - star_display_text("KEYS\n\n" - "[ON] Toggle Ctl.\n" - "[OFF] Exit\n" - "[F1] Prev. level\n" - "[F2] Reset level\n" - "[F3] Next level", true); -#elif CONFIG_KEYPAD == ONDIO_PAD - star_display_text("KEYS\n\n" - "[MODE] Toggle Ctl\n" - "[OFF] Exit\n" - "[M <] Prev. level\n" - "[M ^] Reset level\n" - "[M >] Next level", true); -#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) - star_display_text("KEYS\n\n" - "[MODE/NAVI] Toggle Ctrl\n" - "[OFF] Exit\n" - "[ON + LEFT] Prev. level\n" - "[ON + NAVI] Reset level\n" - "[ON + RIGHT] Next level", true); -#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ - (CONFIG_KEYPAD == IPOD_1G2G_PAD) - star_display_text("KEYS\n\n" - "[SELECT] Toggle Ctl\n" - "[S + MENU] Exit\n" - "[S <] Prev. level\n" - "[S + PLAY] Reset level\n" - "[S >] Next level", true); -#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD - star_display_text("KEYS\n\n" - "[SELECT] Toggle Ctl\n" - "[POWER] Exit\n" - "[REC..] Prev. level\n" - "[PLAY] Reset level\n" - "[REC] Next level", true); -#elif CONFIG_KEYPAD == GIGABEAT_PAD - star_display_text("KEYS\n\n" - "[SELECT] Toggle Control\n" - "[POWER] Exit\n" - "[VOL DOWN] Prev. level\n" - "[A] Reset level\n" - "[VOL UP] Next level", true); -#elif CONFIG_KEYPAD == IRIVER_H10_PAD - star_display_text("KEYS\n\n" - "[REW] Toggle Ctl\n" - "[POWER] Exit\n" - "[PLAY+DOWN] Prev. level\n" - "[PLAY+RIGHT] Reset level\n" - "[PLAY+UP] Next level", true); -#elif CONFIG_KEYPAD == GIGABEAT_S_PAD - star_display_text("KEYS\n\n" - "[SELECT] Toggle Control\n" - "[BACK] Exit\n" - "[VOL DOWN] Prev. level\n" - "[MENU] Reset level\n" - "[VOL UP] Next level", true); -#endif -#ifdef HAVE_TOUCHSCREEN - star_display_text("KEYS\n\n" - STAR_TOGGLE_CONTROL_NAME " Toggle Control\n" - STAR_QUIT_NAME " Exit\n" - STAR_LEVEL_DOWN_NAME " Prev. level\n" - STAR_LEVEL_REPEAT_NAME " Reset level\n" - STAR_LEVEL_UP_NAME " Next level", true); -#endif + if(star_help()) + usb_detected = true; break; default: menu_quit = true; diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index 80dd4f518b..1a44bad518 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c @@ -20,6 +20,7 @@ ****************************************************************************/ #include "plugin.h" #include "lib/playback_control.h" +#include "lib/display_text.h" PLUGIN_HEADER extern const fb_data superdom_boarditems[]; @@ -557,11 +558,9 @@ int settings_menu_function(void) { static int do_help(void) { int button; - int y = MARGIN, space_w, width, height; - unsigned short x = MARGIN, i = 0; -#define WORDS (sizeof instructions / sizeof (char*)) - static char* instructions[] = { - "Super", "domination", "is", "a", "turn", "based", "strategy", "game,", +#define WORDS (sizeof help_text / sizeof (char*)) + static char* help_text[] = { + "Super", "domination", "is", "a", "turn", "based", "strategy", "game,", "where", "the", "aim", "is", "to", "overpower", "the", "computer", "player", "by", "taking", "their", "territory.", "", "Each", "year", "you", "are", "allocated", "an", "amount", "of", "cash", @@ -572,49 +571,17 @@ static int do_help(void) { "the", "ownership", "of", "adjacent", "tiles,", "and", "the", "type", "and", "number", "of", "troops", "on", "them.", }; - rb->lcd_clear_display(); - rb->lcd_getstringsize(" ", &space_w, &height); - for (i = 0; i < WORDS; i++) { - rb->lcd_getstringsize(instructions[i], &width, NULL); - /* Skip to next line if the current one can't fit the word */ - if (x + width > LCD_WIDTH - MARGIN) { - x = MARGIN; - y += height; - } - /* .. or if the word is the empty string */ - if (rb->strcmp(instructions[i], "") == 0) { - x = MARGIN; - y += height; - continue; - } - /* We filled the screen */ - if (y + height > LCD_HEIGHT - MARGIN) { - y = MARGIN; - rb->lcd_update(); - do { - button = rb->button_get(true); - if (button == SYS_USB_CONNECTED) { - return PLUGIN_USB_CONNECTED; - } - } while( ( button == BUTTON_NONE ) - || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); - - rb->lcd_clear_display(); - } - rb->lcd_putsxy(x, y, instructions[i]); - x += width + space_w; - } - rb->lcd_update(); + if (display_text(WORDS, help_text, NULL, NULL)) + return PLUGIN_USB_CONNECTED; do { button = rb->button_get(true); - if (button == SYS_USB_CONNECTED) { + if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) return PLUGIN_USB_CONNECTED; - } } while( ( button == BUTTON_NONE ) || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); - return 0; + return PLUGIN_OK; } int menu(void) { @@ -661,7 +628,7 @@ int save_game(void) { if(fd < 0) { DEBUGF("Couldn't create/open file\n"); return -1; - } + } rb->write(fd, "SSGv3", 5); rb->write(fd, &gamestate, sizeof(gamestate)); @@ -1599,7 +1566,7 @@ int killmen(int colour) { } } } - + if(human) humanres.men -= menkilled; else -- cgit v1.2.3