summaryrefslogtreecommitdiff
path: root/apps/plugins/doom
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2009-06-16 04:25:21 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2009-06-16 04:25:21 +0000
commitaf9f4056510f248c4c9c1335167853bb455e8cc0 (patch)
treeeff7ad7726083ee605d753bd9aa9e22213b1acf0 /apps/plugins/doom
parentcb57a568e8dc9def607dc9ab27f515309bd13841 (diff)
downloadrockbox-af9f4056510f248c4c9c1335167853bb455e8cc0.tar.gz
rockbox-af9f4056510f248c4c9c1335167853bb455e8cc0.zip
Accept FS#10094 by Teruaki Kawashima:
Replace the old menu API with the "new" one (a very long time overdue so huge thanks for the work.) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21306 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/doom')
-rw-r--r--apps/plugins/doom/rockdoom.c144
1 files changed, 61 insertions, 83 deletions
diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c
index 1e7c9fa13a..0220b984d8 100644
--- a/apps/plugins/doom/rockdoom.c
+++ b/apps/plugins/doom/rockdoom.c
@@ -39,7 +39,6 @@
39#include "i_system.h" 39#include "i_system.h"
40#include "hu_stuff.h" 40#include "hu_stuff.h"
41#include "st_stuff.h" 41#include "st_stuff.h"
42#include "lib/oldmenuapi.h"
43#include "lib/helper.h" 42#include "lib/helper.h"
44 43
45PLUGIN_HEADER 44PLUGIN_HEADER
@@ -217,8 +216,8 @@ const unsigned char wads_builtin[7][30] =
217}; 216};
218 217
219int namemap[7]; 218int namemap[7];
220static struct menu_item *addons; 219static char **addons;
221static struct menu_item *demolmp; 220static char **demolmp;
222char addon[200]; 221char addon[200];
223// This sets up the base game and builds up myargv/c 222// This sets up the base game and builds up myargv/c
224bool Dhandle_ver (int dver) 223bool Dhandle_ver (int dver)
@@ -274,14 +273,14 @@ bool Dhandle_ver (int dver)
274 273
275 if(argvlist.addonnum) 274 if(argvlist.addonnum)
276 { 275 {
277 snprintf(addon,sizeof(addon),"%s%s", GAMEBASE"addons/", addons[argvlist.addonnum].desc); 276 snprintf(addon,sizeof(addon),"%s%s", GAMEBASE"addons/", addons[argvlist.addonnum]);
278 D_AddFile(addon,source_pwad); 277 D_AddFile(addon,source_pwad);
279 modifiedgame = true; 278 modifiedgame = true;
280 } 279 }
281 280
282 if(argvlist.demonum) 281 if(argvlist.demonum)
283 { 282 {
284 snprintf(addon, sizeof(addon),"%s%s", GAMEBASE"demos/", demolmp[argvlist.demonum].desc); 283 snprintf(addon, sizeof(addon),"%s%s", GAMEBASE"demos/", demolmp[argvlist.demonum]);
285 D_AddFile(addon, source_lmp); 284 D_AddFile(addon, source_lmp);
286 G_DeferedPlayDemo(addon); 285 G_DeferedPlayDemo(addon);
287 singledemo = true; // quit after one demo 286 singledemo = true; // quit after one demo
@@ -323,21 +322,20 @@ int Dbuild_base (struct opt_items *names)
323 322
324// This is a general function that takes in a menu_item structure and makes a list 323// This is a general function that takes in a menu_item structure and makes a list
325// of files within it based on matching the string stringmatch to the files. 324// of files within it based on matching the string stringmatch to the files.
326int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory, char *stringmatch) 325int Dbuild_filelistm(char ***names, char *firstentry, char *directory, char *stringmatch)
327{ 326{
328 int i=0; 327 int i=0;
329 DIR *filedir; 328 DIR *filedir;
330 struct dirent *dptr; 329 struct dirent *dptr;
331 char *startpt; 330 char *startpt;
332 struct menu_item *temp; 331 char **temp;
333 332
334 filedir=rb->opendir(directory); 333 filedir=rb->opendir(directory);
335 334
336 if(filedir==NULL) 335 if(filedir==NULL)
337 { 336 {
338 temp=malloc(sizeof(struct menu_item)); 337 temp=malloc(sizeof(char *));
339 temp[0].desc=firstentry; 338 temp[0]=firstentry;
340 temp[0].function=0;
341 *names=temp; 339 *names=temp;
342 return 1; 340 return 1;
343 } 341 }
@@ -351,9 +349,8 @@ int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory
351 filedir=rb->opendir(directory); 349 filedir=rb->opendir(directory);
352 350
353 i++; 351 i++;
354 temp=malloc(i*sizeof(struct menu_item)); 352 temp=malloc(i*sizeof(char *));
355 temp[0].desc=firstentry; 353 temp[0]=firstentry;
356 temp[0].function=0;
357 i=1; 354 i=1;
358 355
359 while((dptr=rb->readdir(filedir))) 356 while((dptr=rb->readdir(filedir)))
@@ -362,8 +359,7 @@ int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory
362 { 359 {
363 startpt=malloc(strlen(dptr->d_name)*sizeof(char)); 360 startpt=malloc(strlen(dptr->d_name)*sizeof(char));
364 strcpy(startpt,dptr->d_name); 361 strcpy(startpt,dptr->d_name);
365 temp[i].desc=startpt; 362 temp[i]=startpt;
366 temp[i].function=0;
367 i++; 363 i++;
368 } 364 }
369 } 365 }
@@ -444,7 +440,7 @@ static int translatekey(int key)
444 440
445int Oset_keys() 441int Oset_keys()
446{ 442{
447 int m, result; 443 int selected=0, result;
448 int menuquit=0; 444 int menuquit=0;
449 445
450 446
@@ -483,36 +479,24 @@ int Oset_keys()
483 479
484 int numdoomkeys=sizeof(doomkeys) / sizeof(*doomkeys); 480 int numdoomkeys=sizeof(doomkeys) / sizeof(*doomkeys);
485 481
486 static const struct menu_item items[] = { 482 MENUITEM_STRINGLIST(menu, "Set Keys", NULL,
487 { "Game Right", NULL }, 483 "Game Right", "Game Left", "Game Up", "Game Down",
488 { "Game Left", NULL }, 484 "Game Shoot", "Game Open", "Game Strafe",
489 { "Game Up", NULL }, 485 "Game Weapon", "Game Automap");
490 { "Game Down", NULL },
491 { "Game Shoot", NULL },
492 { "Game Open", NULL },
493 { "Game Strafe", NULL },
494 { "Game Weapon", NULL },
495 { "Game Automap", NULL },
496 };
497
498 m = menu_init(items, sizeof(items) / sizeof(*items),
499 NULL, NULL, NULL, NULL);
500 486
501 while(!menuquit) 487 while(!menuquit)
502 { 488 {
503 result=menu_show(m); 489 result = rb->do_menu(&menu, &selected, NULL, false);
504 if(result<0) 490 if(result<0)
505 menuquit=1; 491 menuquit=1;
506 else 492 else
507 { 493 {
508 *keys[result]=translatekey(*keys[result]); 494 *keys[result]=translatekey(*keys[result]);
509 rb->set_option(items[result].desc, keys[result], INT, doomkeys, numdoomkeys, NULL ); 495 rb->set_option(menu_[result], keys[result], INT, doomkeys, numdoomkeys, NULL );
510 *keys[result]=translatekey(*keys[result]); 496 *keys[result]=translatekey(*keys[result]);
511 } 497 }
512 } 498 }
513 499
514 menu_exit(m);
515
516 return (1); 500 return (1);
517} 501}
518 502
@@ -525,24 +509,17 @@ static bool Doptions()
525 { "On", -1 }, 509 { "On", -1 },
526 }; 510 };
527 511
528 int m, result; 512 int selected=0, result;
529 int menuquit=0; 513 int menuquit=0;
530 514
531 static const struct menu_item items[] = { 515 MENUITEM_STRINGLIST(menu, "Options", NULL,
532 { "Set Keys", NULL }, 516 "Set Keys", "Sound", "Timedemo", "Player Bobbing",
533 { "Sound", NULL }, 517 "Weapon Recoil", "Translucency", "Fake Contrast",
534 { "Timedemo", NULL }, 518 "Always Run", "Headsup Display", "Statusbar Always Red",
535 { "Player Bobbing", NULL },
536 { "Weapon Recoil", NULL },
537 { "Translucency", NULL },
538 { "Fake Contrast", NULL },
539 { "Always Run", NULL },
540 { "Headsup Display", NULL },
541 { "Statusbar Always Red", NULL },
542#if(LCD_HEIGHT>LCD_WIDTH) 519#if(LCD_HEIGHT>LCD_WIDTH)
543 { "Rotate Screen 90 deg", NULL }, 520 "Rotate Screen 90 deg",
544#endif 521#endif
545 }; 522 );
546 523
547 void *options[]={ 524 void *options[]={
548 &enable_sound, 525 &enable_sound,
@@ -559,36 +536,48 @@ static bool Doptions()
559#endif 536#endif
560 }; 537 };
561 538
562 m = menu_init(items, sizeof(items) / sizeof(*items),
563 NULL, NULL, NULL, NULL);
564
565 while(!menuquit) 539 while(!menuquit)
566 { 540 {
567 result=menu_show(m); 541 result = rb->do_menu(&menu, &selected, NULL, false);
568 if(result==0) 542 if(result==0)
569 Oset_keys(); 543 Oset_keys();
570 else if (result > 0) 544 else if (result > 0)
571 rb->set_option(items[result].desc, options[result-1], INT, onoff, 2, NULL ); 545 rb->set_option(menu_[result], options[result-1], INT, onoff, 2, NULL );
572 else 546 else
573 menuquit=1; 547 menuquit=1;
574 } 548 }
575 549
576 menu_exit(m);
577
578 return (1); 550 return (1);
579} 551}
580 552
581int menuchoice(struct menu_item *menu, int items) 553char* choice_get_name(int selected_item, void * data,
554 char * buffer, size_t buffer_len)
582{ 555{
583 int m, result; 556 char **names = (char **) data;
584 557 (void) buffer;
585 m = menu_init(menu, items,NULL, NULL, NULL, NULL); 558 (void) buffer_len;
586 559 return names[selected_item];
587 result= menu_show(m); 560}
588 menu_exit(m); 561int list_action_callback(int action, struct gui_synclist *lists)
589 if(result<items && result>=0) 562{
590 return result; 563 (void) lists;
591 return 0; 564 if (action == ACTION_STD_OK)
565 return ACTION_STD_CANCEL;
566 return action;
567}
568bool menuchoice(char **names, int count, int *selected)
569{
570 struct simplelist_info info;
571 rb->simplelist_info_init(&info, NULL, count, (void*)names);
572 info.selection = *selected;
573 info.get_name = choice_get_name;
574 info.action_callback = list_action_callback;
575 if(rb->simplelist_show_list(&info))
576 return true;
577
578 if(info.selection<count && info.selection>=0)
579 *selected = info.selection;
580 return false;
592} 581}
593 582
594// 583//
@@ -596,22 +585,16 @@ int menuchoice(struct menu_item *menu, int items)
596// 585//
597int doom_menu() 586int doom_menu()
598{ 587{
599 int m; 588 int selected=0, result;
600 int result;
601 int status; 589 int status;
602 int gamever; 590 int gamever;
603 bool menuquit=0; 591 bool menuquit=0;
604 592
605 static struct opt_items names[7]; 593 static struct opt_items names[7];
606 594
607 static const struct menu_item items[] = { 595 MENUITEM_STRINGLIST(menu, "Doom Menu", NULL,
608 { "Game", NULL }, 596 "Game", "Addons", "Demos",
609 { "Addons", NULL }, 597 "Options", "Play Game", "Quit");
610 { "Demos", NULL },
611 { "Options", NULL },
612 { "Play Game", NULL },
613 { "Quit", NULL },
614 };
615 598
616 if( (status=Dbuild_base(names)) == 0 ) // Build up the base wad files (select last added file) 599 if( (status=Dbuild_base(names)) == 0 ) // Build up the base wad files (select last added file)
617 { 600 {
@@ -632,23 +615,20 @@ int doom_menu()
632 while (rb->button_get(false) != BUTTON_NONE) 615 while (rb->button_get(false) != BUTTON_NONE)
633 rb->yield(); 616 rb->yield();
634 617
635 m = menu_init(items, sizeof(items) / sizeof(*items),
636 NULL, NULL, NULL, NULL);
637
638 while(!menuquit) 618 while(!menuquit)
639 { 619 {
640 result=menu_show(m); 620 result = rb->do_menu(&menu, &selected, NULL, false);
641 switch (result) { 621 switch (result) {
642 case 0: /* Game picker */ 622 case 0: /* Game picker */
643 rb->set_option("Game WAD", &gamever, INT, names, status, NULL ); 623 rb->set_option("Game WAD", &gamever, INT, names, status, NULL );
644 break; 624 break;
645 625
646 case 1: /* Addon picker */ 626 case 1: /* Addon picker */
647 argvlist.addonnum=menuchoice(addons,numadd); 627 menuchoice(addons,numadd,&argvlist.addonnum);
648 break; 628 break;
649 629
650 case 2: /* Demos */ 630 case 2: /* Demos */
651 argvlist.demonum=menuchoice(demolmp,numdemos); 631 menuchoice(demolmp,numdemos,&argvlist.demonum);
652 break; 632 break;
653 633
654 case 3: /* Options */ 634 case 3: /* Options */
@@ -669,8 +649,6 @@ int doom_menu()
669 } 649 }
670 } 650 }
671 651
672 menu_exit(m);
673
674 return (gamever); 652 return (gamever);
675} 653}
676 654