summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Kurbjun <kkurbjun@gmail.com>2006-04-17 04:38:26 +0000
committerKarl Kurbjun <kkurbjun@gmail.com>2006-04-17 04:38:26 +0000
commitb0722d11c11c9824fce7bec1b2fb48d84b8f6ff3 (patch)
tree67687c638f68cde011f8d0c73f36e81cb4d26bb6
parentc87f98ce7faed9ba1d2acc9e0e9c9eb5bfb32bfe (diff)
downloadrockbox-b0722d11c11c9824fce7bec1b2fb48d84b8f6ff3.tar.gz
rockbox-b0722d11c11c9824fce7bec1b2fb48d84b8f6ff3.zip
Changed the way the addons and demos menus are displayed and built. Should be a good setup for adding multiple wad files as addons. Need to add some status feedback to let the user know what has been selected previously.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9701 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/doom/rockdoom.c96
1 files changed, 81 insertions, 15 deletions
diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c
index fab1fb308e..23d977b876 100644
--- a/apps/plugins/doom/rockdoom.c
+++ b/apps/plugins/doom/rockdoom.c
@@ -240,8 +240,8 @@ const unsigned char wads_builtin[7][30] =
240}; 240};
241 241
242int namemap[7]; 242int namemap[7];
243static struct opt_items *addons; 243static struct menu_item *addons;
244static struct opt_items *demolmp; 244static struct menu_item *demolmp;
245char addon[200]; 245char addon[200];
246// This sets up the base game and builds up myargv/c 246// This sets up the base game and builds up myargv/c
247bool Dhandle_ver (int dver) 247bool Dhandle_ver (int dver)
@@ -297,14 +297,14 @@ bool Dhandle_ver (int dver)
297 297
298 if(argvlist.addonnum) 298 if(argvlist.addonnum)
299 { 299 {
300 snprintf(addon,sizeof(addon),"%s%s", GAMEBASE"addons/", addons[argvlist.addonnum].string); 300 snprintf(addon,sizeof(addon),"%s%s", GAMEBASE"addons/", addons[argvlist.addonnum].desc);
301 D_AddFile(addon,source_pwad); 301 D_AddFile(addon,source_pwad);
302 modifiedgame = true; 302 modifiedgame = true;
303 } 303 }
304 304
305 if(argvlist.demonum) 305 if(argvlist.demonum)
306 { 306 {
307 snprintf(addon, sizeof(addon),"%s%s", GAMEBASE"demos/", demolmp[argvlist.demonum].string); 307 snprintf(addon, sizeof(addon),"%s%s", GAMEBASE"demos/", demolmp[argvlist.demonum].desc);
308 D_AddFile(addon, source_lmp); 308 D_AddFile(addon, source_lmp);
309 G_DeferedPlayDemo(addon); 309 G_DeferedPlayDemo(addon);
310 singledemo = true; // quit after one demo 310 singledemo = true; // quit after one demo
@@ -391,6 +391,7 @@ int Dbuild_base (struct opt_items *names)
391 return i; 391 return i;
392} 392}
393 393
394#if 0
394// This is a general function that takes in an opt_items structure and makes a list 395// This is a general function that takes in an opt_items structure and makes a list
395// of files within it based on matching the string stringmatch to the files. 396// of files within it based on matching the string stringmatch to the files.
396int Dbuild_filelist(struct opt_items **names, char *firstentry, char *directory, char *stringmatch) 397int Dbuild_filelist(struct opt_items **names, char *firstentry, char *directory, char *stringmatch)
@@ -441,6 +442,58 @@ int Dbuild_filelist(struct opt_items **names, char *firstentry, char *directory,
441 *names=temp; 442 *names=temp;
442 return i; 443 return i;
443} 444}
445#endif
446
447// This is a general function that takes in an menu_item structure and makes a list
448// of files within it based on matching the string stringmatch to the files.
449int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory, char *stringmatch)
450{
451 int i=0;
452 DIR *filedir;
453 struct dirent *dptr;
454 char *startpt;
455 struct menu_item *temp;
456
457 filedir=opendir(directory);
458
459 if(filedir==NULL)
460 {
461 temp=malloc(sizeof(struct opt_items));
462 temp[0].desc=firstentry;
463 temp[0].function=0;
464 *names=temp;
465 return 1;
466 }
467
468 // Get the total number of entries
469 while((dptr=rb->readdir(filedir)))
470 i++;
471
472 // Reset the directory
473 closedir(filedir);
474 filedir=opendir(directory);
475
476 i++;
477 temp=malloc(i*sizeof(struct opt_items));
478 temp[0].desc=firstentry;
479 temp[0].function=0;
480 i=1;
481
482 while((dptr=rb->readdir(filedir)))
483 {
484 if(rb->strcasestr(dptr->d_name, stringmatch))
485 {
486 startpt=malloc(strlen(dptr->d_name)*sizeof(char));
487 strcpy(startpt,dptr->d_name);
488 temp[i].desc=startpt;
489 temp[i].function=0;
490 i++;
491 }
492 }
493 closedir(filedir);
494 *names=temp;
495 return i;
496}
444 497
445// This key configuration code is not the cleanest or the most efficient, but it works 498// This key configuration code is not the cleanest or the most efficient, but it works
446int translatekey(int key) 499int translatekey(int key)
@@ -612,15 +665,15 @@ int Oset_keys()
612 return (1); 665 return (1);
613} 666}
614 667
615static const struct opt_items onoff[2] = {
616 { "Off", NULL },
617 { "On", NULL },
618};
619
620extern int fake_contrast; 668extern int fake_contrast;
621 669
622static bool Doptions() 670static bool Doptions()
623{ 671{
672 static const struct opt_items onoff[2] = {
673 { "Off", NULL },
674 { "On", NULL },
675 };
676
624 int m, result; 677 int m, result;
625 int menuquit=0; 678 int menuquit=0;
626 679
@@ -688,6 +741,19 @@ static bool Doptions()
688 return (1); 741 return (1);
689} 742}
690 743
744int menuchoice(struct menu_item *menu, int items)
745{
746 int m, result;
747
748 m = rb->menu_init(menu, items,doom_menu_cb, NULL, NULL, NULL);
749
750 result= rb->menu_show(m);
751 rb->menu_exit(m);
752 if(result<items && result>=0)
753 return result;
754 return 0;
755}
756
691// 757//
692// Doom Menu 758// Doom Menu
693// 759//
@@ -712,13 +778,13 @@ int doom_menu()
712 778
713 if( (status=Dbuild_base(names)) == 0 ) // Build up the base wad files (select last added file) 779 if( (status=Dbuild_base(names)) == 0 ) // Build up the base wad files (select last added file)
714 { 780 {
715 rb->splash(HZ, true, "Sorry, you have no base wads"); 781 rb->splash(HZ, true, "Missing Base WAD!");
716 return -1; 782 return -1;
717 } 783 }
718 784
719 int numadd=Dbuild_filelist(&addons, "No Addons", GAMEBASE"addons/", ".WAD" ); 785 int numadd=Dbuild_filelistm(&addons, "No Addon", GAMEBASE"addons/", ".WAD" );
720 786
721 int numdemos=Dbuild_filelist(&demolmp, "No Demos", GAMEBASE"demos/", ".LMP" ); 787 int numdemos=Dbuild_filelistm(&demolmp, "No Demo", GAMEBASE"demos/", ".LMP" );
722 788
723 argvlist.demonum=0; 789 argvlist.demonum=0;
724 argvlist.addonnum=0; 790 argvlist.addonnum=0;
@@ -733,15 +799,15 @@ int doom_menu()
733 result=rb->menu_show(m); 799 result=rb->menu_show(m);
734 switch (result) { 800 switch (result) {
735 case 0: /* Game picker */ 801 case 0: /* Game picker */
736 rb->set_option("Base Game", &gamever, INT, names, status, NULL ); 802 rb->set_option("Game WAD", &gamever, INT, names, status, NULL );
737 break; 803 break;
738 804
739 case 1: /* Addon picker */ 805 case 1: /* Addon picker */
740 rb->set_option("Select Addon", &argvlist.addonnum, INT, addons, numadd, NULL ); 806 argvlist.addonnum=menuchoice(addons,numadd);
741 break; 807 break;
742 808
743 case 2: /* Demos */ 809 case 2: /* Demos */
744 rb->set_option("Demos", &argvlist.demonum, INT, demolmp, numdemos, NULL ); 810 argvlist.demonum=menuchoice(demolmp,numdemos);
745 break; 811 break;
746 812
747 case 3: /* Options */ 813 case 3: /* Options */