1
0
Fork 0
forked from len0rd/rockbox

FS#10283 simplify plugins' menus by using stringlist with callback (by Teruaki Kawashima - some minor changes by myself)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21523 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Johannes Schwarz 2009-06-26 17:59:33 +00:00
parent c2565c9bcf
commit 73d25744fb
7 changed files with 124 additions and 184 deletions

View file

@ -81,7 +81,8 @@ static void get_menu_callback(const struct menu_item_ex *m,
static int get_menu_selection(int selected_item, const struct menu_item_ex *menu) static int get_menu_selection(int selected_item, const struct menu_item_ex *menu)
{ {
int type = (menu->flags&MENU_TYPE_MASK); int type = (menu->flags&MENU_TYPE_MASK);
if (type == MT_MENU && (selected_item<current_subitems_count)) if ((type == MT_MENU || type == MT_RETURN_ID)
&& (selected_item<current_subitems_count))
return current_subitems[selected_item]; return current_subitems[selected_item];
return selected_item; return selected_item;
} }

View file

@ -627,8 +627,9 @@ static void add_memo(struct shown *shown, int type)
static int edit_menu_cb(int action, const struct menu_item_ex *this_item) static int edit_menu_cb(int action, const struct menu_item_ex *this_item)
{ {
(void) this_item; int i = (intptr_t)this_item;
if (action == ACTION_REQUEST_MENUITEM && memos_in_shown_memory <= 0) if (action == ACTION_REQUEST_MENUITEM
&& memos_in_shown_memory <= 0 && (i==0 || i==1))
return ACTION_EXIT_MENUITEM; return ACTION_EXIT_MENUITEM;
return action; return action;
} }
@ -638,24 +639,10 @@ static bool edit_memo(int change, struct shown *shown)
bool exit = false; bool exit = false;
int selected = 0; int selected = 0;
MENUITEM_RETURNVALUE(edit_menu_remove, "Remove", 0, MENUITEM_STRINGLIST(edit_menu, "Edit menu", edit_menu_cb,
edit_menu_cb, Icon_NOICON); "Remove", "Edit",
MENUITEM_RETURNVALUE(edit_menu_edit, "Edit", 1, "New Weekly", "New Monthly",
edit_menu_cb, Icon_NOICON); "New Yearly", "New One off");
MENUITEM_RETURNVALUE(edit_menu_weekly, "New Weekly", 2,
NULL, Icon_NOICON);
MENUITEM_RETURNVALUE(edit_menu_monthly, "New Monthly", 3,
NULL, Icon_NOICON);
MENUITEM_RETURNVALUE(edit_menu_yearly, "New Yearly", 4,
NULL, Icon_NOICON);
MENUITEM_RETURNVALUE(edit_menu_oneoff, "New One off", 5,
NULL, Icon_NOICON);
MAKE_MENU(edit_menu, "Edit menu",
NULL, Icon_NOICON,
&edit_menu_remove, &edit_menu_edit,
&edit_menu_weekly, &edit_menu_monthly,
&edit_menu_yearly, &edit_menu_oneoff);
while (!exit) while (!exit)
{ {

View file

@ -700,9 +700,17 @@ static void chopDrawScene(void)
rb->lcd_update(); rb->lcd_update();
} }
static bool _ingame;
static int chopMenuCb(int action, const struct menu_item_ex *this_item)
{
if(action == ACTION_REQUEST_MENUITEM
&& !_ingame && ((intptr_t)this_item)==0)
return ACTION_EXIT_MENUITEM;
return action;
}
static int chopMenu(int menunum) static int chopMenu(int menunum)
{ {
int result = (menunum==0)?0:1; int result = 0;
int res = 0; int res = 0;
bool menu_quit = false; bool menu_quit = false;
@ -711,8 +719,10 @@ static int chopMenu(int menunum)
{ "Steep", -1 }, { "Steep", -1 },
}; };
MENUITEM_STRINGLIST(menu,"Chopper Menu",NULL,"Start New Game","Resume Game", MENUITEM_STRINGLIST(menu,"Chopper Menu",chopMenuCb,
"Resume Game","Start New Game",
"Level","Playback Control","Quit"); "Level","Playback Control","Quit");
_ingame = (menunum!=0);
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
rb->lcd_set_foreground(LCD_WHITE); rb->lcd_set_foreground(LCD_WHITE);
@ -727,19 +737,15 @@ static int chopMenu(int menunum)
while (!menu_quit) { while (!menu_quit) {
switch(rb->do_menu(&menu, &result, NULL, false)) switch(rb->do_menu(&menu, &result, NULL, false))
{ {
case 0: /* Start New Game */ case 0: /* Resume Game */
menu_quit=true;
res = -1;
break;
case 1: /* Start New Game */
menu_quit=true; menu_quit=true;
chopper_load(true); chopper_load(true);
res = -1; res = -1;
break; break;
case 1: /* Resume Game */
if(menunum==1) {
menu_quit=true;
res = -1;
} else if(menunum==0){
rb->splash(HZ, "No game to resume");
}
break;
case 2: case 2:
rb->set_option("Level", &iLevelMode, INT, levels, 2, NULL); rb->set_option("Level", &iLevelMode, INT, levels, 2, NULL);
break; break;

View file

@ -71,7 +71,6 @@ static uint32_t salt;
static union hash pwhash; static union hash pwhash;
static bool data_changed = false; static bool data_changed = false;
static int context_item_cb(int action, const struct menu_item_ex *this_item);
static void encrypt_buffer(char *buf, size_t size, uint32_t *key); static void encrypt_buffer(char *buf, size_t size, uint32_t *key);
static void decrypt_buffer(char *buf, size_t size, uint32_t *key); static void decrypt_buffer(char *buf, size_t size, uint32_t *key);
@ -105,35 +104,22 @@ static void decrypt(uint32_t* v, uint32_t* k)
v[0]=v0; v[1]=v1; v[0]=v0; v[1]=v1;
} }
MENUITEM_RETURNVALUE(context_add_entry, "Add entry", 0,
NULL, Icon_NOICON);
MENUITEM_RETURNVALUE(context_edit_title, "Edit title", 1,
&context_item_cb, Icon_NOICON);
MENUITEM_RETURNVALUE(context_edit_name, "Edit user name", 2,
&context_item_cb, Icon_NOICON);
MENUITEM_RETURNVALUE(context_edit_password, "Edit password", 3,
&context_item_cb, Icon_NOICON);
MENUITEM_RETURNVALUE(context_delete_entry, "Delete entry", 4,
&context_item_cb, Icon_NOICON);
MENUITEM_RETURNVALUE(context_debug, "debug", 5,
&context_item_cb, Icon_NOICON);
MAKE_MENU(context_m, "Context menu",
context_item_cb, Icon_NOICON,
&context_add_entry, &context_edit_title, &context_edit_name,
&context_edit_password, &context_delete_entry);
static int context_item_cb(int action, const struct menu_item_ex *this_item) static int context_item_cb(int action, const struct menu_item_ex *this_item)
{ {
if (action == ACTION_REQUEST_MENUITEM if (action == ACTION_REQUEST_MENUITEM
&& pw_list.num_entries == 0 && pw_list.num_entries == 0
&& this_item != &context_add_entry) && ((intptr_t)this_item) != 0)
{ {
return ACTION_EXIT_MENUITEM; return ACTION_EXIT_MENUITEM;
} }
return action; return action;
} }
MENUITEM_STRINGLIST(context_m, "Context menu", context_item_cb,
"Add entry",
"Edit title", "Edit user name", "Edit password",
"Delete entry")
static char * kb_list_cb(int selected_item, void *data, static char * kb_list_cb(int selected_item, void *data,
char *buffer, size_t buffer_len) char *buffer, size_t buffer_len)
{ {

View file

@ -52,13 +52,12 @@ const struct button_mapping *plugin_contexts[]
#define MAZEZAM_TEXT_WELLDONE_OPTION "Goodbye" #define MAZEZAM_TEXT_WELLDONE_OPTION "Goodbye"
#define MAZEZAM_TEXT_MAZEZAM_MENU "MazezaM Menu" #define MAZEZAM_TEXT_MAZEZAM_MENU "MazezaM Menu"
#define MAZEZAM_TEXT_RETRY_LEVEL "Retry level" #define MAZEZAM_TEXT_RETRY_LEVEL "Retry level"
#define MAZEZAM_TEXT_AUDIO_PLAYBACK "Audio playback" #define MAZEZAM_TEXT_AUDIO_PLAYBACK "Playback Control"
#define MAZEZAM_TEXT_QUIT "Quit" #define MAZEZAM_TEXT_QUIT "Quit"
#define MAZEZAM_TEXT_BACK "Return" #define MAZEZAM_TEXT_BACK "Resume Game"
#define MAZEZAM_TEXT_MAIN_MENU "MazezaM" #define MAZEZAM_TEXT_MAIN_MENU "MazezaM"
#define MAZEZAM_TEXT_CONTINUE "Play from checkpoint" #define MAZEZAM_TEXT_CONTINUE "Play from checkpoint"
#define MAZEZAM_TEXT_PLAY_GAME "Play game" #define MAZEZAM_TEXT_PLAY_NEW_GAME "Start New Game"
#define MAZEZAM_TEXT_PLAY_NEW_GAME "Play new game"
#define MAZEZAM_START_LIVES 3 /* how many lives at game start */ #define MAZEZAM_START_LIVES 3 /* how many lives at game start */
#define MAZEZAM_FIRST_CHECKPOINT 3 /* The level at the first checkpoint */ #define MAZEZAM_FIRST_CHECKPOINT 3 /* The level at the first checkpoint */
@ -837,32 +836,17 @@ static void resume_save_data (struct resume_data *r, struct resume_data *old)
MAZEZAM_CONFIG_NUM_ITEMS, MAZEZAM_CONFIG_MINVERSION); MAZEZAM_CONFIG_NUM_ITEMS, MAZEZAM_CONFIG_MINVERSION);
} }
/*****************************************************************************
* Offer a main menu with no continue option
******************************************************************************/
static int main_menu_without_continue(int* start_selection)
{
MENUITEM_STRINGLIST(menu,MAZEZAM_TEXT_MAIN_MENU,NULL,
MAZEZAM_TEXT_PLAY_GAME,
MAZEZAM_TEXT_QUIT);
return rb->do_menu(&menu, start_selection, NULL, false);
}
/*****************************************************************************
* Offer a main menu with a continue option
******************************************************************************/
static int main_menu_with_continue(int* start_selection)
{
MENUITEM_STRINGLIST(menu,MAZEZAM_TEXT_MAIN_MENU,NULL,
MAZEZAM_TEXT_CONTINUE,
MAZEZAM_TEXT_PLAY_NEW_GAME,
MAZEZAM_TEXT_QUIT);
return rb->do_menu(&menu, start_selection, NULL, false);
}
/***************************************************************************** /*****************************************************************************
* Manages the main menu * Manages the main menu
******************************************************************************/ ******************************************************************************/
static bool have_continue;
static int main_menu_cb(int action, const struct menu_item_ex *this_item)
{
if(action == ACTION_REQUEST_MENUITEM
&& !have_continue && ((intptr_t)this_item)==0)
return ACTION_EXIT_MENUITEM;
return action;
}
static void main_menu(void) static void main_menu(void)
{ {
/* The initial option is "play game" */ /* The initial option is "play game" */
@ -873,11 +857,14 @@ static void main_menu(void)
/* Load data */ /* Load data */
resume_load_data(&r_data, &old_data); resume_load_data(&r_data, &old_data);
MENUITEM_STRINGLIST(menu,MAZEZAM_TEXT_MAIN_MENU,main_menu_cb,
MAZEZAM_TEXT_CONTINUE,
MAZEZAM_TEXT_PLAY_NEW_GAME,
MAZEZAM_TEXT_QUIT);
while (state >= STATE_IN_APPLICATION) { while (state >= STATE_IN_APPLICATION) {
if (r_data.level == 0) have_continue = (r_data.level != 0);
choice = main_menu_without_continue(&start_selection); choice = rb->do_menu(&menu, &start_selection, NULL, false);
else
choice = main_menu_with_continue(&start_selection);
switch(choice) { switch(choice) {
case 0: /* Continue */ case 0: /* Continue */
@ -885,14 +872,10 @@ static void main_menu(void)
game_loop(&r_data); game_loop(&r_data);
break; break;
case 1: /* Quit or Play new game */ case 1: /* Play new game */
if (r_data.level == 0) r_data.level = 0;
state = STATE_QUIT; state = STATE_IN_GAME;
else { /* Play new game */ game_loop(&r_data);
r_data.level = 0;
state = STATE_IN_GAME;
game_loop(&r_data);
}
break; break;
case MENU_ATTACHED_USB: case MENU_ATTACHED_USB:

View file

@ -782,22 +782,33 @@ void solitaire_init(void);
/* menu return codes */ /* menu return codes */
enum { MENU_RESUME, MENU_SAVE_AND_QUIT, MENU_QUIT, MENU_USB }; enum { MENU_RESUME, MENU_SAVE_AND_QUIT, MENU_QUIT, MENU_USB };
static bool _ingame;
int solitaire_menu_cb(int action, const struct menu_item_ex *this_item)
{
int i = (intptr_t)this_item;
if( action == ACTION_REQUEST_MENUITEM )
{
if((!_ingame && (i==0 || i==5)) || ( _ingame && i==2 ))
return ACTION_EXIT_MENUITEM;
}
return action;
}
int solitaire_menu(bool in_game) int solitaire_menu(bool in_game)
{ {
int selected = 0; int selected = 0;
int result = -1; int result = -1;
MENUITEM_STRINGLIST(menu, "Solitaire Menu", NULL, MENUITEM_STRINGLIST(menu, "Solitaire Menu", solitaire_menu_cb,
"Start Game", "Draw Cards Option", "Resume Game", "Start New Game",
"Help", "Audio Playback", "Quit"); "Draw Cards Option",
MENUITEM_STRINGLIST(menu_in_game, "Solitaire Menu", NULL, "Help", "Playback Control",
"Resume Game", "Restart Game", "Help", "Save and Quit", "Quit");
"Audio Playback", "Save and Quit", "Quit"); _ingame = in_game;
while (result < 0) while (result < 0)
{ {
switch (rb->do_menu(in_game? &menu_in_game: &menu, switch (rb->do_menu(&menu, &selected, NULL, false))
&selected, NULL, false))
{ {
default: default:
result = MENU_RESUME; result = MENU_RESUME;
@ -812,36 +823,30 @@ int solitaire_menu(bool in_game)
break; break;
case 1: case 1:
if (in_game) solitaire_init();
{ result = MENU_RESUME;
solitaire_init();
result = MENU_RESUME;
}
else
{
if (rb->set_option("Draw Cards Option", &sol.draw_type,
INT, drawcards, 2, NULL))
result = MENU_USB;
}
break; break;
case 2: case 2:
if (solitaire_help() == HELP_USB) if (rb->set_option("Draw Cards Option", &sol.draw_type,
INT, drawcards, 2, NULL))
result = MENU_USB; result = MENU_USB;
break; break;
case 3: case 3:
if (solitaire_help() == HELP_USB)
result = MENU_USB;
break;
case 4:
playback_control(NULL); playback_control(NULL);
break; break;
case 4: case 5:
if( in_game ) result = MENU_SAVE_AND_QUIT;
result = MENU_SAVE_AND_QUIT;
else
result = MENU_QUIT;
break; break;
case 5: case 6:
result = MENU_QUIT; result = MENU_QUIT;
break; break;
} }

View file

@ -920,77 +920,49 @@ static void init_game (void)
} }
/* the main menu */ /* the main menu */
static bool _ingame;
static int xobox_menu_cb(int action, const struct menu_item_ex *this_item)
{
if(action == ACTION_REQUEST_MENUITEM
&& !_ingame && ((intptr_t)this_item)==0)
return ACTION_EXIT_MENUITEM;
return action;
}
static int xobox_menu(bool ingame) static int xobox_menu(bool ingame)
{ {
rb->button_clear_queue(); rb->button_clear_queue();
int choice = 0;
if (ingame) { int selection = 0;
MENUITEM_STRINGLIST (main_menu, "Xobox Menu", NULL, MENUITEM_STRINGLIST(main_menu, "Xobox Menu", xobox_menu_cb,
"Resume Game", "Resume Game", "Start New Game",
"Restart Level", "Speed", "Difficulty",
"Speed", "Playback Control", "Quit");
"Difficulty", _ingame = ingame;
"Playback Control",
"Quit");
while (true) { while (true) {
choice = rb->do_menu(&main_menu, &choice, NULL, false); switch (rb->do_menu(&main_menu, &selection, NULL, false)) {
switch (choice) { case 0:
case 0: return 0;
return 0; case 1:
case 1: init_game ();
init_game (); return 0;
return 0; case 2:
case 2: rb->set_int ("Speed", "", UNIT_INT, &speed, NULL, 1, 1, 10, NULL);
rb->set_int ("Speed", "", UNIT_INT, &speed, NULL, 1, 1, 10, NULL); break;
break; case 3:
case 3: rb->set_int ("Difficulty", "", UNIT_INT, &difficulty, NULL,
rb->set_int ("Difficulty", "", UNIT_INT, &difficulty, NULL, 5, 50, 95, NULL);
5, 50, 95, NULL); break;
break; case 4:
case 4: playback_control(NULL);
playback_control(NULL); break;
break; case 5:
case 5: return 1;
return 1; case MENU_ATTACHED_USB:
case MENU_ATTACHED_USB: return 1;
return 1; default:
default: break;
break;
}
}
}
else {
MENUITEM_STRINGLIST (main_menu, "Xobox Menu", NULL,
"Start Game",
"Speed",
"Difficulty",
"Playback Control",
"Quit");
while (true) {
choice = rb->do_menu(&main_menu, &choice, NULL, false);
switch (choice) {
case 0:
init_game ();
return 0;
case 1:
rb->set_int ("Speed", "", UNIT_INT, &speed, NULL, 1, 1, 10, NULL);
break;
case 2:
rb->set_int ("Difficulty", "", UNIT_INT, &difficulty, NULL,
5, 50, 95, NULL);
break;
case 3:
playback_control(NULL);
break;
case 4:
return 1;
case MENU_ATTACHED_USB:
return 1;
default:
break;
}
} }
} }
} }