Index: apps/plugins/rockboy/menu.c =================================================================== --- apps/plugins/rockboy/menu.c (Revision 28479) +++ apps/plugins/rockboy/menu.c (Arbeitskopie) @@ -212,33 +212,11 @@ return true; } -/* - * do_slot - load or save game data in the given slot - * - * Returns true on success and false on failure. - */ -static bool do_slot(int slot_id, bool is_load) { - char path_buf[256], desc_buf[20]; - - /* build slot filename, clear desc buf */ - build_slot_path(path_buf, 256, slot_id); - memset(desc_buf, 0, 20); - - /* if we're saving to a slot, then get a brief description */ - if (!is_load) - if ( (rb->kbd_input(desc_buf, 20) < 0) || !strlen(desc_buf) ) - { - strlcpy(desc_buf, "Untitled", 20); - } - - /* load/save file */ - return do_file(path_buf, desc_buf, is_load); -} - /* * get information on the given slot */ -static void slot_info(char *info_buf, size_t info_bufsiz, int slot_id) { +static void slot_info(char *info_buf, size_t info_bufsiz, int slot_id, + bool number) { char buf[256]; int fd; @@ -252,20 +230,58 @@ if (read(fd, buf, 20) > 0) { buf[20] = '\0'; - snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, buf); + if(number) + snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, buf); + else + snprintf(info_buf, info_bufsiz, "%s", buf); } else - snprintf(info_buf, info_bufsiz, "%d. ERROR", slot_id + 1); - + if(number) + snprintf(info_buf, info_bufsiz, "%d. ERROR", slot_id + 1); + else + snprintf(info_buf, info_bufsiz, "ERROR"); + close(fd); } else { /* if we couldn't open the file, then the slot is empty */ - snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, ""); + /* a little hack: If we are here and number is true, we want to get + * the menu-entry for an new savegame. If number is false, we want + * to get the preset for the inputdialog for the name of a new + * savegame */ + if(number) + snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, ""); } } +/* + * do_slot - load or save game data in the given slot + * + * Returns true on success and false on failure. + */ +static bool do_slot(int slot_id, bool is_load) { + char path_buf[256], desc_buf[20]; + + /* build slot filename, clear desc buf */ + build_slot_path(path_buf, 256, slot_id); + memset(desc_buf, 0, 20); + slot_info(desc_buf, 20, slot_id, false); + + /* if we're saving to a slot, then get a brief description */ + if (!is_load) { + int status = rb->kbd_input(desc_buf, 20); + /* if the user cancelled the input for name, do not save */ + if(status < 0) + return status; + if ( !strlen(desc_buf) ) + strlcpy(desc_buf, "Untitled", 20); + } + + /* load/save file */ + return do_file(path_buf, desc_buf, is_load); +} + /* * slot_get_name */ @@ -290,19 +306,33 @@ } /* + * how many slots shall be shown? + */ +static int determine_slot_count() { + char path_buf[256]; + int slot_id = 0; + while(true) { + build_slot_path(path_buf, 256, slot_id); + if(!rb->file_exists(path_buf)) return slot_id; + slot_id++; + } +} + +/* * do_slot_menu - prompt the user for a load/save memory slot */ static void do_slot_menu(bool is_load) { bool done=false; - char items[5][20]; + int num_items = determine_slot_count(); + if (!is_load) num_items++; + char items[num_items][20]; int result; int i; - int num_items = sizeof(items) / sizeof(*items); struct simplelist_info info; /* create menu items */ for (i = 0; i < num_items; i++) - slot_info(items[i], 20, i); + slot_info(items[i], 20, i, true); rb->simplelist_info_init(&info, NULL, num_items, (void *)items); info.get_name = slot_get_name; @@ -379,7 +409,7 @@ #endif MENUITEM_STRINGLIST(menu, "Options", NULL, - "Max Frameskip", "Sound", "Stats", "Set Keys (Buggy)", + "Max Frameskip", "Sound", "Volume", "Stats", "Set Keys (Buggy)", #ifdef HAVE_LCD_COLOR "Screen Size", "Screen Rotate", "Set Palette", #endif @@ -387,6 +417,9 @@ options.dirty=1; /* Assume that the settings have been changed */ + struct viewport *parentvp = NULL; + const struct settings_list* vol = rb->find_setting(&rb->global_settings->volume, NULL); + while(!done) { result = rb->do_menu(&menu, &selected, NULL, false); @@ -402,24 +435,27 @@ rb->set_option("Sound", &options.sound, INT, onoff, 2, NULL ); if(options.sound) sound_dirty(); break; - case 2: /* Stats */ + case 2: /* Volume */ + rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume"); + break; + case 3: /* Stats */ rb->set_option("Stats", &options.showstats, INT, onoff, 2, NULL ); break; - case 3: /* Keys */ + case 4: /* Keys */ setupkeys(); break; #ifdef HAVE_LCD_COLOR - case 4: /* Screen Size */ + case 5: /* Screen Size */ rb->set_option("Screen Size", &options.scaling, INT, scaling, sizeof(scaling)/sizeof(*scaling), NULL ); setvidmode(); break; - case 5: /* Screen rotate */ + case 6: /* Screen rotate */ rb->set_option("Screen Rotate", &options.rotate, INT, rotate, sizeof(rotate)/sizeof(*rotate), NULL ); setvidmode(); break; - case 6: /* Palette */ + case 7: /* Palette */ rb->set_option("Set Palette", &options.pal, INT, palette, 17, NULL ); set_pal(); break;