summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorTom Ross <midgey@rockbox.org>2007-03-28 07:33:18 +0000
committerTom Ross <midgey@rockbox.org>2007-03-28 07:33:18 +0000
commitc7f5cccd3e061c8a53e919d117a2adb3fe58473b (patch)
treec65e1f2c13e07bcf9169d098e5b29f3f2727d7a6 /apps/plugins
parenta289324e30c78db7b333d461aca5554f6ecf9cfe (diff)
Adjust plugins to use the new menu API. Int settings still use the old API. Remove a nasty global in Star and add some error checking. Add a work-around for the gigabeat so that Star doesn't crash on target. The transition works fine on the sim and I see nothing obviously wrong with the code but it manages to crash on target everytime.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12946 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/dice.c235
-rw-r--r--apps/plugins/disktidy.c19
-rw-r--r--apps/plugins/minesweeper.c109
-rw-r--r--apps/plugins/snake.c87
-rw-r--r--apps/plugins/star.c355
5 files changed, 242 insertions, 563 deletions
diff --git a/apps/plugins/dice.c b/apps/plugins/dice.c
index 7c265dac4b..cfeceae539 100644
--- a/apps/plugins/dice.c
+++ b/apps/plugins/dice.c
@@ -28,129 +28,80 @@ use stop to exit
*****************************************************************************/
#include "plugin.h"
-#include "button.h"
-#include "lcd.h"
#define MAX_DICE 12
#define NUM_SIDE_CHOICES 8
#if (CONFIG_KEYPAD == PLAYER_PAD)
- #define SELECTIONS_SIZE 9
#define START_DICE_ROW 1
#define ROWS 1
#define LINE_LENGTH 50
#define SELECTIONS_ROW 0
#else
- #define SELECTIONS_SIZE 7
- #define SELECTIONS_ROW 4
#if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == ONDIO_PAD)
#define START_DICE_ROW 0
#define ROWS 3
#define LINE_LENGTH 18
#else
- #define START_DICE_ROW 7
+ #define START_DICE_ROW 0
#define ROWS 2
#define LINE_LENGTH 26
#endif
#endif
-/* Values for selected */
-#define CHANGE_DICE 0
-#define CHANGE_SIDES 1
-#define EXIT 2
-
-
+#define min(x,y) (x<y?x:y)
+#define max(x,y) (x>y?x:y)
#if CONFIG_KEYPAD == RECORDER_PAD
-#define DICE_BUTTON_UP BUTTON_UP
-#define DICE_BUTTON_DOWN BUTTON_DOWN
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
-#define DICE_BUTTON_OFF BUTTON_OFF
#define DICE_BUTTON_ON BUTTON_ON
+#define DICE_BUTTON_OFF BUTTON_OFF
#define DICE_BUTTON_SELECT BUTTON_PLAY
#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
-#define DICE_BUTTON_UP BUTTON_UP
-#define DICE_BUTTON_DOWN BUTTON_DOWN
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
-#define DICE_BUTTON_OFF BUTTON_OFF
#define DICE_BUTTON_ON BUTTON_ON
+#define DICE_BUTTON_OFF BUTTON_OFF
#define DICE_BUTTON_SELECT BUTTON_SELECT
#elif CONFIG_KEYPAD == ONDIO_PAD
-#define DICE_BUTTON_UP BUTTON_UP
-#define DICE_BUTTON_DOWN BUTTON_DOWN
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
+#define DICE_BUTTON_ON (BUTTON_MENU|BUTTON_OFF)
#define DICE_BUTTON_OFF BUTTON_OFF
#define DICE_BUTTON_SELECT (BUTTON_MENU|BUTTON_REL)
-#define DICE_BUTTON_ON (BUTTON_MENU|BUTTON_OFF)
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
-#define DICE_BUTTON_UP BUTTON_UP
-#define DICE_BUTTON_DOWN BUTTON_DOWN
-#define DICE_BUTTON_OFF BUTTON_OFF
#define DICE_BUTTON_ON BUTTON_ON
+#define DICE_BUTTON_OFF BUTTON_OFF
#define DICE_BUTTON_SELECT BUTTON_SELECT
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
#define DICE_BUTTON_RC_OFF BUTTON_RC_STOP
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD)
-#define DICE_BUTTON_UP BUTTON_SCROLL_FWD
-#define DICE_BUTTON_DOWN BUTTON_SCROLL_BACK
-#define DICE_BUTTON_OFF (BUTTON_PLAY|BUTTON_REPEAT)
#define DICE_BUTTON_ON (BUTTON_SELECT|BUTTON_PLAY)
+#define DICE_BUTTON_OFF (BUTTON_PLAY|BUTTON_REPEAT)
#define DICE_BUTTON_SELECT BUTTON_SELECT
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
-#elif (CONFIG_KEYPAD == PLAYER_PAD)
-#define DICE_BUTTON_UP BUTTON_PLAY
-#define DICE_BUTTON_DOWN BUTTON_STOP
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
-#define DICE_BUTTON_SELECT BUTTON_ON
+#elif CONFIG_KEYPAD == PLAYER_PAD
#define DICE_BUTTON_ON (BUTTON_ON|BUTTON_REPEAT)
#define DICE_BUTTON_OFF BUTTON_MENU
+#define DICE_BUTTON_SELECT BUTTON_ON
-#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
-#define DICE_BUTTON_UP BUTTON_UP
-#define DICE_BUTTON_DOWN BUTTON_DOWN
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
-#define DICE_BUTTON_SELECT BUTTON_SELECT
+#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
#define DICE_BUTTON_ON BUTTON_PLAY
#define DICE_BUTTON_OFF BUTTON_POWER
-
-#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
-#define DICE_BUTTON_UP BUTTON_UP
-#define DICE_BUTTON_DOWN BUTTON_DOWN
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
#define DICE_BUTTON_SELECT BUTTON_SELECT
+
+#elif CONFIG_KEYPAD == GIGABEAT_PAD
#define DICE_BUTTON_ON BUTTON_POWER
#define DICE_BUTTON_OFF BUTTON_A
-
-#elif (CONFIG_KEYPAD == SANSA_E200_PAD)
-#define DICE_BUTTON_UP BUTTON_SCROLL_UP
-#define DICE_BUTTON_DOWN BUTTON_SCROLL_DOWN
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
#define DICE_BUTTON_SELECT BUTTON_SELECT
+
+#elif CONFIG_KEYPAD == SANSA_E200_PAD
#define DICE_BUTTON_ON BUTTON_UP
#define DICE_BUTTON_OFF BUTTON_POWER
+#define DICE_BUTTON_SELECT BUTTON_SELECT
-#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
-#define DICE_BUTTON_UP BUTTON_SCROLL_UP
-#define DICE_BUTTON_DOWN BUTTON_SCROLL_DOWN
-#define DICE_BUTTON_LEFT BUTTON_LEFT
-#define DICE_BUTTON_RIGHT BUTTON_RIGHT
-#define DICE_BUTTON_SELECT BUTTON_REW
+#elif CONFIG_KEYPAD == IRIVER_H10_PAD
#define DICE_BUTTON_ON BUTTON_PLAY
#define DICE_BUTTON_OFF BUTTON_POWER
+#define DICE_BUTTON_SELECT BUTTON_REW
#else
#error DICE: Unsupported keypad
@@ -167,16 +118,15 @@ static struct plugin_api* rb;
static int roll_dice(int dice[], const int num_dice, const int side_index);
static void print_dice(const int dice[], const int total);
-static void print_selections(const int selected,
- const int num_dice,
- const int side_index);
-static void print_help(void);
+static bool dice_menu(int *num_dice, int *side_index);
/* plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
int side_index = 6;
int num_dice = 1;
- int selected = CHANGE_DICE;
+ bool exit = false;
+ int dice[MAX_DICE];
+ int total;
/* plugin init */
(void)parameter;
@@ -185,60 +135,25 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
rb->lcd_clear_display();
rb->srand(*rb->current_tick);
/* end of plugin init */
-
- print_selections(selected, num_dice, side_index);
- print_help();
- while(selected!=EXIT) {
+
+ if(!dice_menu(&num_dice, &side_index))
+ exit = true;
+ else {
+ total = roll_dice(dice, num_dice, side_index);
+ print_dice(dice, total);
+ }
+ while(!exit) {
switch(rb->button_get(true)) {
- case DICE_BUTTON_UP:
- if (selected==CHANGE_DICE) {
- num_dice%=MAX_DICE;
- num_dice++;
- } else if (selected==CHANGE_SIDES) {
- side_index++;
- side_index%=NUM_SIDE_CHOICES;
- }
- print_selections(selected, num_dice, side_index);
- break;
-
- case DICE_BUTTON_DOWN:
- if (selected==CHANGE_DICE) {
- num_dice--;
- if (num_dice==0) {
- num_dice=MAX_DICE;
- }
- } else if (selected==CHANGE_SIDES) {
- if (side_index==0) {
- side_index=NUM_SIDE_CHOICES;
- }
- side_index--;
- }
- print_selections(selected, num_dice, side_index);
- break;
-
- case DICE_BUTTON_LEFT:
- selected = CHANGE_DICE;
- print_selections(selected, num_dice, side_index);
- break;
-
- case DICE_BUTTON_RIGHT:
- selected = CHANGE_SIDES;
- print_selections(selected, num_dice, side_index);
- break;
-
case DICE_BUTTON_ON:
case DICE_BUTTON_SELECT:
- {
- int dice[MAX_DICE];
- int total = roll_dice(dice, num_dice, side_index);
- print_dice(dice, total);
- }
+ total = roll_dice(dice, num_dice, side_index);
+ print_dice(dice, total);
break;
#ifdef DICE_BUTTON_RC_OFF
case DICE_BUTTON_RC_OFF:
#endif
case DICE_BUTTON_OFF:
- selected = EXIT;
+ exit=true;
break;
default:
@@ -261,14 +176,12 @@ static int roll_dice(int dice[], const int num_dice, const int side_index) {
return total;
}
-#define min(x,y) (x<y?x:y)
-#define max(x,y) (x>y?x:y)
-
/* Prints the dice, and the sum of the dice values */
static void print_dice(const int dice[], const int total) {
const int dice_per_row = MAX_DICE/ROWS + (MAX_DICE%ROWS?1:0);
char showdice[LINE_LENGTH];
int row;
+ rb->lcd_clear_display();
for (row=0; /*break;*/; row++) {
const int start = row*dice_per_row;
const int end = min(MAX_DICE,start+dice_per_row);
@@ -305,43 +218,49 @@ static void print_dice(const int dice[], const int total) {
rb->lcd_update();
#endif
}
-
-/* Print the current user input choices */
-static void print_selections(const int selected,
- const int num_dice,
- const int side_index) {
- char buffer[SELECTIONS_SIZE];
-#if (CONFIG_KEYPAD == PLAYER_PAD)
- rb->snprintf(buffer, SELECTIONS_SIZE, "%c%2dd%c%3d",
- selected==CHANGE_DICE?'*':' ', num_dice,
- selected==CHANGE_SIDES?'*':' ', SIDES[side_index]);
- rb->lcd_puts(1,SELECTIONS_ROW,buffer);
-#else
- rb->snprintf(
- buffer,SELECTIONS_SIZE,"%2dd%3d",num_dice,SIDES[side_index]);
- rb->lcd_puts(1,SELECTIONS_ROW,buffer);
- if (selected==CHANGE_DICE) {
- rb->lcd_puts(1,SELECTIONS_ROW+1,"--");
- } else if (selected==CHANGE_SIDES) {
- rb->lcd_puts(1,SELECTIONS_ROW+1," ---");
+static bool dice_menu(int *num_dice, int *side_index) {
+ int selection;
+ bool menu_quit = false, result = false;
+
+ MENUITEM_STRINGLIST(menu,"Dice Menu",NULL,"Roll Dice","Number of Dice",
+ "Number of Sides","Quit");
+
+ static const struct opt_items num_sides_option[8] = {
+ { "3", -1 },
+ { "4", -1 },
+ { "6", -1 },
+ { "8", -1 },
+ { "10", -1 },
+ { "12", -1 },
+ { "20", -1 },
+ { "100", -1 }
+ };
+
+ while (!menu_quit) {
+ selection = rb->do_menu(&menu, &selection);
+ switch(selection)
+ {
+ case 0:
+ menu_quit = true;
+ result = true;
+ break;
+
+ case 1:
+ rb->set_int("Number of Dice", "", UNIT_INT, num_dice, NULL,
+ 1, 1, MAX_DICE, NULL );
+ break;
+
+ case 2:
+ rb->set_option("Number of Sides", side_index, INT,
+ num_sides_option, 8, NULL);
+ break;
+
+ default:
+ menu_quit = true;
+ result = false;
+ break;
+ }
}
-#endif
-#ifdef HAVE_LCD_BITMAP
- rb->lcd_update();
-#endif
-}
-static void print_help() {
-#if (CONFIG_KEYPAD == PLAYER_PAD)
- rb->lcd_puts_scroll(1,SELECTIONS_ROW, "</>, +/- setup");
- rb->lcd_puts_scroll(1,SELECTIONS_ROW+1, "on roll, menu exit");
-#else
- rb->lcd_puts(1,START_DICE_ROW,"</> pick dice/sides");
- rb->lcd_puts(1,START_DICE_ROW+1,"+/- change");
- rb->lcd_puts(1,START_DICE_ROW+2,"on/select roll");
- rb->lcd_puts(1,START_DICE_ROW+3,"off exit");
-#endif
-#ifdef HAVE_LCD_BITMAP
- rb->lcd_update();
-#endif
+ return result;
}
diff --git a/apps/plugins/disktidy.c b/apps/plugins/disktidy.c
index f5e34cd54d..d1f40cf9f8 100644
--- a/apps/plugins/disktidy.c
+++ b/apps/plugins/disktidy.c
@@ -340,15 +340,11 @@ enum plugin_status tidy_do(enum tidy_system system)
int tidy_lcd_menu(void)
{
- int loc, ret = 2;
+ int selection, ret = 2;
bool menu_quit = false;
- static const struct menu_item items[] =
- {
- { "Start Cleaning", NULL },
- { "Files to Clean", NULL },
- { "Quit", NULL }
- };
+ MENUITEM_STRINGLIST(menu,"Disktidy Menu",NULL,"Start Cleaning",
+ "Files to Clean","Quit");
static const struct opt_items system_option[3] =
{
@@ -356,13 +352,11 @@ int tidy_lcd_menu(void)
{ "Windows", -1 },
{ "Both", -1 }
};
-
- loc = rb->menu_init(items, sizeof(items) / sizeof(*items),
- NULL, NULL, NULL, NULL);
while (!menu_quit)
{
- switch(rb->menu_show(loc))
+ selection = rb->do_menu(&menu,&selection);
+ switch(selection)
{
case 0:
@@ -373,13 +367,12 @@ int tidy_lcd_menu(void)
rb->set_option("Files to Clean", &ret, INT, system_option, 3, NULL);
break;
- case 2:
+ default:
ret = 99; /* exit plugin */
menu_quit = true;
break;
}
}
- rb->menu_exit(loc);
return ret;
}
diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c
index 26c2df5233..862bfcfce3 100644
--- a/apps/plugins/minesweeper.c
+++ b/apps/plugins/minesweeper.c
@@ -415,99 +415,50 @@ int count_tiles_left( void )
/* welcome screen where player can chose mine percentage */
enum minesweeper_status menu( void )
{
- int button;
-
- while( true )
- {
+ int selection, result = MINESWEEPER_QUIT;
+ bool menu_quit = false;
+
+ MENUITEM_STRINGLIST(menu, "Minesweeper Menu",NULL,"Play Minesweeper",
+ "Mine Percentage", "Number of Rows", "Number of Columns",
+ "Quit");
+
#ifdef HAVE_LCD_COLOR
- rb->lcd_set_background( LCD_WHITE );
- rb->lcd_set_foreground( LCD_BLACK );
-#endif
- rb->lcd_clear_display();
-
- rb->lcd_puts( 0, 0, "Mine Sweeper" );
-
- rb->snprintf( str, 20, "%d%% mines", p );
- rb->lcd_puts( 0, 2, str );
- rb->lcd_puts( 0, 3, "down / up" );
- rb->snprintf( str, 20, "%d cols x %d rows", width, height );
- rb->lcd_puts( 0, 4, str );
- rb->lcd_puts( 0, 5, "left x right" );
- rb->lcd_puts( 0, 6,
-#if CONFIG_KEYPAD == RECORDER_PAD
- "ON to start"
-#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
- "ON to start"
-#elif CONFIG_KEYPAD == ONDIO_PAD
- "MODE to start"
-#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \
- || (CONFIG_KEYPAD == IRIVER_H300_PAD ) \
- || (CONFIG_KEYPAD == IPOD_4G_PAD) \
- || (CONFIG_KEYPAD == IPOD_3G_PAD) \
- || (CONFIG_KEYPAD == GIGABEAT_PAD)
- "SELECT to start"
-#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
- "REC to start"
-#elif CONFIG_KEYPAD == IRIVER_H10_PAD
- "FF to start"
-#elif CONFIG_KEYPAD == SANSA_E200_PAD
- "SELECT to start"
-#else
- ""
-# warning Please define help string for this keypad.
+ rb->lcd_set_foreground(rb->global_settings->fg_color);
+ rb->lcd_set_background(rb->global_settings->bg_color);
#endif
- );
- rb->lcd_update();
- switch( button = rb->button_get( true ) )
+ while (!menu_quit) {
+ selection=rb->do_menu(&menu,&selection);
+ switch(selection)
{
- case MINESWP_DOWN:
- case MINESWP_DOWN|BUTTON_REPEAT:
- p = (p + 94)%98 + 2;
- break;
-
- case MINESWP_UP:
- case MINESWP_UP|BUTTON_REPEAT:
- p = p%98 + 2;
+ case 0:
+ result = MINESWEEPER_WIN; /* start playing */
+ menu_quit = true;
break;
- case BUTTON_RIGHT:
- case BUTTON_RIGHT|BUTTON_REPEAT:
- height = height%MAX_HEIGHT + 1;
+ case 1:
+ rb->set_int("Mine Percentage", "%", UNIT_INT, &p, NULL, 1, 2,
+ 98, NULL );
break;
- case BUTTON_LEFT:
- case BUTTON_LEFT|BUTTON_REPEAT:
- width = width%MAX_WIDTH + 1;
- break;
-
- case MINESWP_RIGHT:
- case MINESWP_RIGHT|BUTTON_REPEAT:
- height--;
- if( height < 1 ) height = MAX_HEIGHT;
+ case 2:
+ rb->set_int("Number of Rows", "", UNIT_INT, &height, NULL, 1, 1,
+ MAX_HEIGHT, NULL );
break;
-
- case MINESWP_LEFT:
- case MINESWP_LEFT|BUTTON_REPEAT:
- width--;
- if( width < 1 ) width = MAX_WIDTH;
+
+ case 3:
+ rb->set_int("Number of Columns", "", UNIT_INT, &width, NULL, 1, 1,
+ MAX_WIDTH, NULL );
break;
-
- case MINESWP_START:/* start playing */
- return MINESWEEPER_WIN;
-
-#ifdef MINESWP_RC_QUIT
- case MINESWP_RC_QUIT:
-#endif
- case MINESWP_QUIT:/* quit program */
- return MINESWEEPER_QUIT;
-
+
default:
- if( rb->default_event_handler(button) == SYS_USB_CONNECTED )
- return MINESWEEPER_USB;
+ result = MINESWEEPER_QUIT; /* quit program */
+ menu_quit = true;
break;
}
}
+
+ return result;
}
/* the big and ugly game function */
diff --git a/apps/plugins/snake.c b/apps/plugins/snake.c
index 7551e59e40..96412cbd22 100644
--- a/apps/plugins/snake.c
+++ b/apps/plugins/snake.c
@@ -102,25 +102,24 @@ PLUGIN_HEADER
#define BOARD_HEIGHT (LCD_HEIGHT/4)
static int board[BOARD_WIDTH][BOARD_HEIGHT],snakelength;
-static unsigned int score,hiscore=0;
-static short dir,frames,apple,level=1,dead=0;
+static unsigned int score,hiscore=0,level=1;
+static short dir,frames,apple,dead=0;
static struct plugin_api* rb;
void die (void)
{
- char pscore[5],hscore[17];
+ char pscore[17];
rb->lcd_clear_display();
- rb->snprintf(pscore,sizeof(pscore),"%d",score);
- rb->lcd_putsxy(3,12,"oops...");
- rb->lcd_putsxy(3,22,"Your score :");
- rb->lcd_putsxy(3,32, pscore);
+ rb->snprintf(pscore,sizeof(pscore),"Your score: %d",score);
+ rb->lcd_puts(0,0,"Oops...");
+ rb->lcd_puts(0,1, pscore);
if (score>hiscore) {
hiscore=score;
- rb->lcd_putsxy(3,42,"New High Score!");
+ rb->lcd_puts(0,2,"New High Score!");
}
else {
- rb->snprintf(hscore,sizeof(hscore),"High Score: %d",hiscore);
- rb->lcd_putsxy(3,42,hscore);
+ rb->snprintf(pscore,sizeof(pscore),"High Score: %d",hiscore);
+ rb->lcd_puts(0,2,pscore);
}
rb->lcd_update();
rb->sleep(3*HZ);
@@ -324,9 +323,9 @@ void game (void) {
}
void game_init(void) {
- int button;
+ int selection=0;
short x,y;
- char plevel[10],phscore[20];
+ bool menu_quit = false;
for (x=0; x<BOARD_WIDTH; x++) {
for (y=0; y<BOARD_HEIGHT; y++) {
@@ -338,58 +337,30 @@ void game_init(void) {
snakelength=4;
score=0;
board[11][7]=1;
-
-
- rb->lcd_clear_display();
- rb->lcd_setfont(FONT_SYSFIXED);
- rb->snprintf(plevel,sizeof(plevel),"Level - %d",level);
- rb->snprintf(phscore,sizeof(phscore),"High Score: %d",hiscore);
- rb->lcd_puts(0,0, plevel);
- rb->lcd_puts(0,1, "(1-slow, 9-fast)");
- rb->lcd_puts(0,2, "OFF - quit");
-#if CONFIG_KEYPAD == RECORDER_PAD
- rb->lcd_puts(0,3, "PLAY - start/pause");
-#elif CONFIG_KEYPAD == ONDIO_PAD
- rb->lcd_puts(0,3, "MODE - start/pause");
-#endif
- rb->lcd_puts(0,4, phscore);
- rb->lcd_update();
-
- while (1) {
- button=rb->button_get(true);
- switch (button) {
- case BUTTON_RIGHT:
- case SNAKE_UP:
- if (level<9)
- level++;
- break;
- case BUTTON_LEFT:
- case SNAKE_DOWN:
- if (level>1)
- level--;
- break;
-#ifdef SNAKE_RC_QUIT
- case SNAKE_RC_QUIT:
-#endif
- case SNAKE_QUIT:
- dead=1;
- return;
+
+ MENUITEM_STRINGLIST(menu,"Snake Menu",NULL,"Start New Game","Starting Level",
+ "Quit");
+
+ while (!menu_quit) {
+ selection = rb->do_menu(&menu, &selection);
+ switch(selection)
+ {
+ case 0:
+ menu_quit = true; /* start playing */
break;
- case SNAKE_PLAYPAUSE:
- return;
+
+ case 1:
+ rb->set_int("Starting Level", "", UNIT_INT, &level, NULL,
+ 1, 1, 9, NULL );
break;
+
default:
- if (rb->default_event_handler(button)==SYS_USB_CONNECTED) {
- dead=2;
- return;
- }
+ dead=1; /* quit program */
+ menu_quit = true;
break;
+
}
- rb->snprintf(plevel,sizeof(plevel),"Level - %d",level);
- rb->lcd_puts(0,0, plevel);
- rb->lcd_update();
}
-
}
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
diff --git a/apps/plugins/star.c b/apps/plugins/star.c
index 03c0422158..071a0bb284 100644
--- a/apps/plugins/star.c
+++ b/apps/plugins/star.c
@@ -21,12 +21,6 @@
PLUGIN_HEADER
-/* title of the game */
-#define STAR_TITLE "Star"
-
-/* font used to display title */
-#define STAR_TITLE_FONT 2
-
/* size of a level in file */
#define STAR_LEVEL_SIZE ((STAR_WIDTH + 1) * STAR_HEIGHT + 1)
@@ -45,7 +39,8 @@ PLUGIN_HEADER
#define STAR_BLOCK 'x'
/* sleep time between two frames */
-#if (LCD_HEIGHT * LCD_WIDTH >= 70000) /* iPod 5G LCD is *slow* */
+#if (LCD_HEIGHT * LCD_WIDTH >= 70000) && defined(IPOD_ARCH)
+/* iPod 5G LCD is *slow* */
#define STAR_SLEEP rb->yield();
#elif (LCD_HEIGHT * LCD_WIDTH >= 30000)
#define STAR_SLEEP rb->sleep(0);
@@ -204,20 +199,7 @@ static char board[STAR_HEIGHT][STAR_WIDTH];
#define STAR 3
#define BALL 4
-/* bitmap of the arrow animation */
-static unsigned char arrow_bmp[4][7] =
- {
- {0x7f, 0x7f, 0x3e, 0x3e, 0x1c, 0x1c, 0x08},
- {0x3e, 0x3e, 0x1c, 0x1c, 0x08, 0x08, 0x08},
- {0x1c, 0x1c, 0x1c, 0x1c, 0x08, 0x08, 0x08},
- {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08}
- };
-
-/* sequence of the bitmap arrow to follow to do one turn */
-static unsigned char anim_arrow[8] = {0, 1, 2, 3, 2, 1, 0};
-
-/* current_level */
-static int current_level = 0;
+#define MENU_START 0
/* char font size */
static int char_width = -1;
@@ -528,6 +510,8 @@ void star_display_text(char *str, bool waitkey)
/**
* Do a pretty transition from one level to another.
*/
+#if !defined(GIGABEAT_F) || defined(SIMULATOR)
+/* FIXME: this crashes on the Gigabeat but not in the sim */
static void star_transition_update(void)
{
int center_x = LCD_WIDTH / 2;
@@ -573,11 +557,12 @@ static void star_transition_update(void)
#endif
rb->lcd_update();
}
+#endif
/**
* Display information board of the current level.
*/
-static void star_display_board_info(void)
+static void star_display_board_info(int current_level)
{
int label_pos_y, tile_pos_y;
char str_info[32];
@@ -617,6 +602,12 @@ 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;
@@ -667,8 +658,12 @@ static int star_load_level(int current_level)
}
ptr_tab++;
}
- star_display_board_info();
+ star_display_board_info(current_level);
+#if !defined(GIGABEAT_F) || defined(SIMULATOR)
star_transition_update();
+#else
+ rb->lcd_update();
+#endif
return 1;
}
@@ -708,7 +703,7 @@ static void star_animate_tile(int tile_no, int start_x, int start_y,
/**
* Run the game.
*/
-static int star_run_game(void)
+static int star_run_game(int current_level)
{
int move_x = 0;
int move_y = 0;
@@ -794,7 +789,7 @@ static int star_run_game(void)
control = STAR_CONTROL_BLOCK;
else
control = STAR_CONTROL_BALL;
- star_display_board_info();
+ star_display_board_info(current_level);
break;
default:
@@ -827,7 +822,7 @@ static int star_run_game(void)
board[ball_y][ball_x] = STAR_VOID;
star_count--;
- star_display_board_info();
+ star_display_board_info(current_level);
}
}
board[ball_y][ball_x] = STAR_BALL;
@@ -866,251 +861,106 @@ static int star_run_game(void)
}
/**
- * Display the choose level screen.
- */
-static int star_choose_level(void)
-{
- int level = current_level;
- int key = BUTTON_NONE;
- char str_info[32];
- int lastkey = BUTTON_NONE;
-
- while (true)
- {
- rb->lcd_clear_display();
- /* levels are numbered 0 to (STAR_LEVEL_COUNT-1) internally, but
- * displayed as 1 to STAR_LEVEL_COUNT because it looks nicer */
- rb->snprintf(str_info, sizeof(str_info), "Level:%02d / %02d",
- level+1, STAR_LEVEL_COUNT );
- rb->lcd_putsxy(0, 0, str_info);
- rb->lcd_update();
- key = rb->button_get(true);
- switch (key)
- {
- case STAR_QUIT:
- case BUTTON_LEFT:
- return -1;
- break;
-
- case STAR_MENU_RUN:
-#ifdef STAR_MENU_RUN2
- case STAR_MENU_RUN2:
-#endif
-#ifdef STAR_MENU_RUN3
- case STAR_MENU_RUN3:
-#endif
- current_level=level;
- return star_run_game();
- break;
-
- case STAR_UP:
- case BUTTON_REPEAT | STAR_UP:
- if(level< STAR_LEVEL_COUNT - 1)
- level++;
- break;
-
- case STAR_DOWN:
- case BUTTON_REPEAT | STAR_DOWN:
- if(level> 0)
- level--;
- break;
-
- default:
- if (rb->default_event_handler(key) == SYS_USB_CONNECTED)
- {
- usb_detected = true;
- return 0;
- }
- break;
- }
-
- if (key != BUTTON_NONE)
- lastkey = key;
- }
-}
-
-/**
* Display the choice menu.
*/
static int star_menu(void)
{
- int move_y;
- int menu_y = 0;
- int i = 0;
- bool refresh = true;
- char anim_state = 0;
- unsigned char *menu[5] = {"Play", "Choose Level", "Information",
- "Keys", "Exit"};
- int menu_count = sizeof(menu) / sizeof(unsigned char *);
- int menu_offset_y;
- int key;
-
- menu_offset_y = LCD_HEIGHT - char_height * menu_count;
-
- while (true)
+ int selection, level=1;
+ bool menu_quit = false;
+
+ /* get the size of char */
+ rb->lcd_getstringsize("a", &char_width, &char_height);
+
+ MENUITEM_STRINGLIST(menu,"Star Menu",NULL,"Play","Choose Level",
+ "Information","Keys","Quit");
+
+ while(!menu_quit)
{
- if (refresh)
+ selection = rb->do_menu(&menu, &selection);
+ switch(selection)
{
- rb->lcd_clear_display();
- rb->lcd_putsxy((LCD_WIDTH - char_width *
- rb->strlen(STAR_TITLE)) / 2,
- 0, STAR_TITLE);
- for (i = 0 ; i < menu_count ; i++)
- {
- rb->lcd_putsxy(15, menu_offset_y + char_height * i, menu[i]);
- }
-
- rb->lcd_update();
- refresh = false;
- }
-
- move_y = 0;
- rb->lcd_mono_bitmap(arrow_bmp[anim_arrow[(anim_state & 0x38) >> 3]],
- 2, menu_offset_y + menu_y * char_height, 7, 8);
- rb->lcd_update_rect (2, menu_offset_y + menu_y * 8, 8, 8);
- STAR_SLEEP
- anim_state++;
-
- key = rb->button_get(false);
- switch (key)
- {
-#ifdef STAR_RC_QUIT
- case STAR_RC_QUIT:
-#endif
- case STAR_QUIT:
- return PLUGIN_OK;
- case STAR_UP:
- if (menu_y > 0) {
- move_y = -1;
-#if LCD_DEPTH > 1
- int oldforeground = rb->lcd_get_foreground();
- rb->lcd_set_foreground(LCD_BLACK);
-#endif
- rb->lcd_fillrect(0,menu_offset_y + char_height * menu_y - 2,
- 15, char_height + 3);
-#if LCD_DEPTH > 1
- rb->lcd_set_foreground(oldforeground);
-#endif
- }
+ case 0:
+ menu_quit = true;
break;
- case STAR_DOWN:
- if (menu_y < menu_count-1) {
- move_y = 1;
-#if LCD_DEPTH > 1
- int oldforeground = rb->lcd_get_foreground();
- rb->lcd_set_foreground(LCD_BLACK);
-#endif
- rb->lcd_fillrect(0,menu_offset_y + char_height * menu_y - 1,
- 15, char_height + 2);
-#if LCD_DEPTH > 1
- rb->lcd_set_foreground(oldforeground);
-#endif
- }
+ case 1:
+ rb->set_int("Level", "", UNIT_INT, &level,
+ NULL, 1, 1, STAR_LEVEL_COUNT, NULL );
break;
-
- case STAR_MENU_RUN:
-#ifdef STAR_MENU_RUN2
- case STAR_MENU_RUN2:
-#endif
-#ifdef STAR_MENU_RUN3
- case STAR_MENU_RUN3:
-#endif
- refresh = true;
- switch (menu_y)
- {
- case 0:
- star_run_game();
- break;
- case 1:
- star_choose_level();
- 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:
+ 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);
+ 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);
+ 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);
+ 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)
- 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);
+ 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);
+ 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"
- "[MENU] Toggle Ctl\n"
- "[A] Exit\n"
- "[PWR+DOWN] Prev. level\n"
- "[PWR+RIGHT] Reset level\n"
- "[PWR+UP] Next level", true);
+ star_display_text("KEYS\n\n"
+ "[MENU] Toggle Control\n"
+ "[A] Exit\n"
+ "[PWR+DOWN] Prev. level\n"
+ "[PWR+RIGHT] Reset level\n"
+ "[PWR+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);
+ 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);
#endif
- break;
- case 4:
- return PLUGIN_OK;
- }
- if (usb_detected)
- return PLUGIN_USB_CONNECTED;
break;
-
default:
- if (rb->default_event_handler(key) == SYS_USB_CONNECTED)
- return PLUGIN_USB_CONNECTED;
+ menu_quit = true;
break;
}
-
- for (i = 0 ; i < char_height ; i++)
- {
- rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
- rb->lcd_fillrect (2, menu_offset_y, 8, menu_count * 8);
- rb->lcd_set_drawmode(DRMODE_FG);
- rb->lcd_mono_bitmap(arrow_bmp[anim_arrow[(anim_state & 0x38) >> 3]],
- 2, menu_offset_y + menu_y * 8 + move_y * i, 7, 8);
- rb->lcd_update_rect(2, menu_offset_y, 8, menu_count * 8);
- anim_state++;
- STAR_SLEEP
- }
- rb->lcd_set_drawmode(DRMODE_SOLID);
- menu_y += move_y;
}
+
+ if (selection == MENU_START)
+ {
+ rb->lcd_setfont(FONT_SYSFIXED);
+ rb->lcd_getstringsize("a", &char_width, &char_height);
+ level--;
+ star_run_game(level);
+ }
+
+ return PLUGIN_OK;
}
/**
@@ -1121,11 +971,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
(void)parameter;
rb = api;
- /* get the size of char */
- rb->lcd_setfont(FONT_SYSFIXED);
- if (char_width == -1)
- rb->lcd_getstringsize("a", &char_width, &char_height);
-
#if LCD_DEPTH > 1
rb->lcd_set_backdrop(NULL);
rb->lcd_set_background( LCD_BLACK );