Changeset 217

Show
Ignore:
Timestamp:
06/24/07 01:54:38 (2 years ago)
Author:
ajps
Message:

A possibly misplaced attempt to make the options menus internally consistent and reliable and all that other good stuff.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd4.c

    r193 r217  
    210210                                byte c, byte attr_top, byte char_left); 
    211211 
    212 static void dump_pref_file(void (*dump)(FILE*), const char *title); 
     212static void dump_pref_file(void (*dump)(FILE*), const char *title, int row); 
    213213 
    214214/* 
     
    21582158                case 'T': 
    21592159                case '5': 
     2160                case '\n': 
     2161                case '\r': 
    21602162                case '\xff': 
    21612163                { 
     
    21742176} 
    21752177 
    2176 static const menu_iter options_iter = 
     2178static const menu_iter options_toggle_iter = 
    21772179{ 
    21782180        0, 
     
    22212223                cx = menu_select(menu, &cursor_pos, EVT_MOVE); 
    22222224 
    2223                 if (cx.type == EVT_BACK || cx.key == ESCAPE) 
     2225                if (cx.key == ESCAPE) 
    22242226                        break; 
    22252227                else if (cx.type == EVT_MOVE) 
     
    23522354 
    23532355                /* Toggle */ 
    2354                 if ((ke.key == '5') || (ke.key == 't') || ((ke.key == '\xff') && (ke.index))) 
     2356                if ((ke.key == '5') || (ke.key == 't') || (ke.key == '\n') || (ke.key == '\r') || ((ke.key == '\xff') && (ke.index))) 
    23552357                { 
    23562358                        /* Hack -- ignore the main window */ 
     
    25752577 *   Comments are generated automatically 
    25762578 */ 
    2577 static void dump_pref_file(void (*dump)(FILE*), const char *title
     2579static void dump_pref_file(void (*dump)(FILE*), const char *title, int row
    25782580{ 
    25792581        char ftmp[80]; 
    25802582        char buf[1025]; 
    25812583        FILE *fff; 
    2582  
    2583         int row = 15; 
    25842584 
    25852585        /* Prompt */ 
     
    30223022 
    30233023                if (ESCAPE == c.key) break; 
     3024                if (c.key == ARROW_LEFT || c.key == ARROW_RIGHT) continue; 
    30243025                evt = macro_actions[cursor].id; 
    30253026 
     
    30363037                { 
    30373038                        /* Dump the macros */ 
    3038                         (void)dump_pref_file(macro_dump, "Dump Macros"); 
     3039                        (void)dump_pref_file(macro_dump, "Dump Macros", 15); 
    30393040 
    30403041                        break; 
     
    31383139                { 
    31393140                        /* Dump the keymaps */ 
    3140                         (void)dump_pref_file(keymap_dump, "Dump Keymaps"); 
     3141                        (void)dump_pref_file(keymap_dump, "Dump Keymaps", 15); 
    31413142                        break; 
    31423143                } 
     
    35143515                        break; 
    35153516 
     3517                if (key.key == ARROW_LEFT || key.key == ARROW_RIGHT) 
     3518                        continue; 
     3519 
    35163520                assert(cursor >= 0 && cursor < visual_menu.count); 
    35173521 
     
    35283532                else if (evt == DUMP_MON) 
    35293533                { 
    3530                         dump_pref_file(dump_monsters, "Dump Monster attr/chars"); 
     3534                        dump_pref_file(dump_monsters, "Dump Monster attr/chars", 15); 
    35313535                } 
    35323536 
    35333537                else if (evt == DUMP_OBJ) 
    35343538                { 
    3535                         dump_pref_file(dump_objects, "Dump Object attr/chars"); 
     3539                        dump_pref_file(dump_objects, "Dump Object attr/chars", 15); 
    35363540                } 
    35373541 
    35383542                else if (evt == DUMP_FEAT) 
    35393543                { 
    3540                         dump_pref_file(dump_features, "Dump Feature attr/chars"); 
     3544                        dump_pref_file(dump_features, "Dump Feature attr/chars", 15); 
    35413545                } 
    35423546 
     
    35443548                else if (evt == DUMP_FLAV)  
    35453549                { 
    3546                         dump_pref_file(dump_flavors, "Dump Flavor attr/chars"); 
     3550                        dump_pref_file(dump_flavors, "Dump Flavor attr/chars", 15); 
    35473551                } 
    35483552 
     
    36863690                /* Done */ 
    36873691                if (key.key == ESCAPE) break; 
     3692 
     3693                if (key.key == ARROW_RIGHT || key.key == ARROW_LEFT) continue; 
     3694 
    36883695                evt = color_events[cursor].id; 
    36893696 
     
    37083715                else if (evt == DUMP_COL) 
    37093716                { 
    3710                         dump_pref_file(dump_colors, "Dump Colors"); 
     3717                        dump_pref_file(dump_colors, "Dump Colors", 15); 
    37113718                } 
    37123719 
     
    39033910static void do_dump_options(void *unused, const char *title) 
    39043911{ 
    3905         dump_pref_file(option_dump, title); 
     3912        dump_pref_file(option_dump, title, 20); 
    39063913} 
    39073914 
     
    39153922 * XXX Too many entries. 
    39163923 */ 
    3917 static menu_item option_actions [] = 
    3918 
    3919         {{0, "Interface options", do_cmd_options_aux, (void*)0}, '1'}, 
    3920         {{0, "Display options", do_cmd_options_aux, (void*)1}, '2'}, 
    3921         {{0, "Warning options", do_cmd_options_aux, (void*)2}, '3'}, 
    3922         {{0, "Birth (Difficulty) options", do_cmd_options_aux, (void*)3}, '4'}, 
    3923         {{0, "Cheat options", do_cmd_options_aux, (void*)4}, '5'}, 
    3924         {{0, 0, 0, 0}}, /* Load and append */ 
    3925         {{0, "Subwindow display settings", (action_f) do_cmd_options_win, 0}, 'W'}, 
    3926         {{0, "Item squelch and Autoinscribe settings", (action_f) do_cmd_options_item, 0}, 'S'}, 
    3927         {{0, "Set base delay factor", (action_f) do_cmd_delay, 0}, 'D'}, 
    3928         {{0, "Set hitpoint warning", (action_f) do_cmd_hp_warn, 0}, 'H'}, 
    3929         {{0, 0, 0,}, 0}, /* Special choices */ 
    3930         {{0, "Load a user pref file", (action_f) do_cmd_pref_file_hack, (void*)20}, 'L'}, 
    3931         {{0, "Dump options", do_dump_options, 0}, 'A'}, 
    3932         {{0, 0, 0,}, 0}, /* Interact with */     
    3933         {{0, "Interact with macros (advanced)", (action_f) do_cmd_macros, 0}, 'M'}, 
    3934         {{0, "Interact with visuals (advanced)", (action_f) do_cmd_visuals, 0}, 'V'}, 
    3935         {{0, "Interact with colours (advanced)", (action_f) do_cmd_colors, 0}, 'C'}, 
     3924 
     3925static event_action option_actions [] =  
     3926
     3927        {'1', "Interface options", do_cmd_options_aux, (void*)0},  
     3928        {'2', "Display options", do_cmd_options_aux, (void*)1}, 
     3929        {'3', "Warning options", do_cmd_options_aux, (void*)2},  
     3930        {'4', "Birth (Difficulty) options", do_cmd_options_aux, (void*)3},  
     3931        {'5', "Cheat options", do_cmd_options_aux, (void*)4},  
     3932        {0, 0, 0, 0}, /* Load and append */ 
     3933        {'W', "Subwindow display settings", (action_f) do_cmd_options_win, 0},  
     3934        {'S', "Item squelch and Autoinscribe settings", (action_f) do_cmd_options_item, 0},  
     3935        {'D', "Set base delay factor", (action_f) do_cmd_delay, 0},  
     3936        {'H', "Set hitpoint warning", (action_f) do_cmd_hp_warn, 0},  
     3937        {0, 0, 0,}, /* Special choices */ 
     3938        {'L', "Load a user pref file", (action_f) do_cmd_pref_file_hack, (void*)20}, 
     3939        {'A', "Dump options", do_dump_options, 0},  
     3940        {0, 0, 0,}, /* Interact with */  
     3941        {'M', "Interact with macros (advanced)", (action_f) do_cmd_macros, 0}, 
     3942        {'V', "Interact with visuals (advanced)", (action_f) do_cmd_visuals, 0}, 
     3943        {'C', "Interact with colours (advanced)", (action_f) do_cmd_colors, 0}, 
    39363944}; 
    39373945 
    39383946static menu_type option_menu; 
     3947 
     3948static char tag_opt_main(menu_type *menu, int oid) 
     3949{ 
     3950        if (option_actions[oid].id) 
     3951                return option_actions[oid].id; 
     3952 
     3953        return 0; 
     3954} 
     3955 
     3956static int valid_opt_main(menu_type *menu, int oid) 
     3957{ 
     3958        if (option_actions[oid].name) 
     3959                return 1; 
     3960 
     3961        return 0; 
     3962} 
     3963 
     3964static void display_opt_main(menu_type *menu, int oid, bool cursor, int row, int col, int width) 
     3965{ 
     3966        byte attr = curs_attrs[CURS_KNOWN][(int)cursor]; 
     3967 
     3968        if (option_actions[oid].name) 
     3969                c_prt(attr, option_actions[oid].name, row, col); 
     3970} 
     3971 
     3972 
     3973static const menu_iter options_iter = 
     3974{ 
     3975        0, 
     3976        tag_opt_main, 
     3977        valid_opt_main, 
     3978        display_opt_main, 
     3979        NULL 
     3980}; 
    39393981 
    39403982 
     
    39543996                clear_from(0); 
    39553997                c = menu_select(&option_menu, &cursor, 0); 
     3998                if (c.type == EVT_SELECT && option_actions[cursor].action) 
     3999                { 
     4000                        option_actions[cursor].action(option_actions[cursor].data, 
     4001                                                      option_actions[cursor].name); 
     4002                } 
    39564003        } 
    39574004 
     
    40114058void init_cmd4_c(void) 
    40124059{ 
     4060        /* some useful standard command keys */ 
     4061        static const char cmd_keys[] = { ARROW_LEFT, ARROW_RIGHT, '\0' }; 
     4062 
    40134063        /* Initialize the menus */ 
    4014         menu_type *menu; 
     4064        menu_type *menu;                  
    40154065 
    40164066        /* options screen selection menu */ 
     
    40204070        menu->title = "Options Menu"; 
    40214071        menu->menu_data = option_actions; 
     4072        menu->cmd_keys = cmd_keys; 
    40224073        menu->count = N_ELEMENTS(option_actions); 
    4023         menu_init(menu, MN_SCROLL, MN_ACT, &SCREEN_REGION); 
     4074        menu_init2(menu, find_menu_skin(MN_SCROLL), &options_iter, &SCREEN_REGION); 
    40244075 
    40254076        /* Initialize the options toggle menu */ 
     
    40274078        WIPE(menu, menu_type); 
    40284079        menu->prompt = "Set option (y/n/t), '?' for information"; 
    4029         menu->cmd_keys = "?YyNnTt"; 
     4080        menu->cmd_keys = "?Yy\n\rNnTt\x8C"; /* \x8c = ARROW_RIGHT */ 
    40304081        menu->selections = "abcdefghijklmopqrsuvwxz"; 
    40314082        menu->count = OPT_PAGE_PER; 
    40324083        menu->flags = MN_DBL_TAP; 
    4033         menu_init2(menu, find_menu_skin(MN_SCROLL), &options_iter, &SCREEN_REGION); 
     4084        menu_init2(menu, find_menu_skin(MN_SCROLL), &options_toggle_iter, &SCREEN_REGION); 
    40344085 
    40354086        /* macro menu */ 
     
    40384089        menu_set_id(menu, MACRO_MENU); 
    40394090        menu->title = "Interact with macros"; 
     4091        menu->cmd_keys = cmd_keys; 
    40404092        menu->selections = default_choice; 
    40414093        menu->menu_data = macro_actions; 
     
    40484100        menu_set_id(menu, VISUAL_MENU); 
    40494101        menu->title = "Interact with visuals"; 
     4102        menu->cmd_keys = cmd_keys; 
    40504103        menu->selections = default_choice; 
    40514104        menu->menu_data = visual_menu_items; 
     
    40584111        menu_set_id(menu, COLOR_MENU); 
    40594112        menu->title = "Interact with colors"; 
     4113        menu->cmd_keys = cmd_keys; 
    40604114        menu->selections = default_choice; 
    40614115        menu->menu_data = color_events; 
     
    41304184        /* Silly message */ 
    41314185        msg_format("You are playing %s %s.  Type '?' for more info.", 
    4132                    VERSION_NAME, VERSION_STRING); 
     4186                       VERSION_NAME, VERSION_STRING); 
    41334187} 
    41344188 
  • trunk/src/externs.h

    r216 r217  
    597597void squelch_set(object_type *o_ptr); 
    598598void squelch_items(void); 
    599 void do_cmd_options_item(void); 
     599void do_cmd_options_item(void *, cptr); 
    600600 
    601601/* store.c */ 
  • trunk/src/squelch.c

    r191 r217  
    363363                        } 
    364364 
    365                       break; 
     365                      break; 
    366366                } 
    367367 
     
    375375                        } 
    376376 
    377                       break; 
     377                      break; 
    378378                } 
    379379 
     
    381381                { 
    382382                        if ((feel == INSCRIP_BROKEN) || (feel == INSCRIP_TERRIBLE) || 
    383                          (feel == INSCRIP_WORTHLESS) || (feel == INSCRIP_CURSED) || 
     383                          (feel == INSCRIP_WORTHLESS) || (feel == INSCRIP_CURSED) || 
    384384                            (feel == INSCRIP_AVERAGE) || (feel == INSCRIP_GOOD)) 
    385385                        { 
     
    407407                { 
    408408                        return TRUE; 
    409                       break; 
     409                      break; 
    410410                } 
    411411        } 
     
    645645 
    646646        /* Select an entry */ 
    647         while (evt.key != ESCAPE && evt.type != EVT_BACK
     647        while (evt.key != ESCAPE
    648648                evt = menu_select(&menu, &cursor, 0); 
    649649 
     
    686686 
    687687        /* Toggle */ 
    688         if (cmd == ' ') 
     688        if (cmd == '\n' || cmd == '\r') 
    689689        { 
    690690                int idx = choice[oid]; 
     
    696696        return FALSE; 
    697697} 
     698 
    698699 
    699700/* 
     
    759760        text_out_c(TERM_L_GREEN, "ESC"); 
    760761        text_out(" to return to the previous menu.  "); 
    761         text_out_c(TERM_L_BLUE, "Space"); 
     762        text_out_c(TERM_L_BLUE, "Enter"); 
    762763        text_out(" toggles the current setting."); 
    763764 
     
    770771 
    771772        /* Select an entry */ 
    772         while (evt.key != ESCAPE && evt.type != EVT_BACK
     773        while (evt.key != ESCAPE
    773774                evt = menu_select(&menu, &cursor, 0); 
    774775 
     
    782783 
    783784 
     785/* Returns TRUE if there's anything to display a menu of */ 
     786static bool seen_tval(int tval) 
     787{ 
     788        int i; 
     789 
     790        for (i = 1; i < z_info->k_max; i++) 
     791        { 
     792                object_kind *k_ptr = &k_info[i]; 
     793 
     794                /* Skip empty objects, unseen objects, and incorrect tvals */ 
     795                if (!k_ptr->name) continue; 
     796                if (!k_ptr->everseen) continue; 
     797                if (k_ptr->tval != tval) continue; 
     798 
     799                 return TRUE; 
     800        } 
     801 
     802 
     803        return FALSE; 
     804} 
     805 
     806 
     807/* Extra options on the "item options" menu */ 
     808struct { 
     809        char tag; 
     810        char *name; 
     811        void (*action)(void); 
     812} extra_item_options[] = { {'Q', "Quality squelching options", quality_menu } }; 
     813 
     814static char tag_options_item(menu_type *menu, int oid) 
     815{ 
     816        if (oid < N_ELEMENTS(sval_dependent)) 
     817                return I2A(oid); 
     818 
     819        /* Separator - blank line. */ 
     820        if (oid == N_ELEMENTS(sval_dependent)) 
     821                return 0; 
     822 
     823        oid = oid - N_ELEMENTS(sval_dependent); 
     824 
     825        if (oid - 1 < N_ELEMENTS(extra_item_options)) 
     826                return extra_item_options[oid - 1].tag; 
     827 
     828        return 0; 
     829} 
     830 
     831static int valid_options_item(menu_type *menu, int oid) 
     832{ 
     833        if (oid < N_ELEMENTS(sval_dependent)) 
     834                return 1; 
     835 
     836        /* Separator - blank line. */ 
     837        if (oid == N_ELEMENTS(sval_dependent)) 
     838                return 0; 
     839 
     840        oid = oid - N_ELEMENTS(sval_dependent); 
     841 
     842        if (oid - 1 < N_ELEMENTS(extra_item_options)) 
     843                return 1; 
     844 
     845        return 0; 
     846} 
     847 
     848static void display_options_item(menu_type *menu, int oid, bool cursor, int row, int col, int width) 
     849{ 
     850        if (oid < N_ELEMENTS(sval_dependent)) 
     851        { 
     852                bool known = seen_tval(sval_dependent[oid].tval); 
     853                byte attr = curs_attrs[known ? CURS_KNOWN: CURS_UNKNOWN][(int)cursor]; 
     854 
     855                c_prt(attr, sval_dependent[oid].desc, row, col); 
     856        } 
     857        else 
     858        { 
     859                byte attr = curs_attrs[CURS_KNOWN][(int)cursor]; 
     860 
     861                oid = oid - N_ELEMENTS(sval_dependent); 
     862     
     863                if (oid - 1 < N_ELEMENTS(extra_item_options)) 
     864                        c_prt(attr, extra_item_options[oid - 1].name, row, col); 
     865        } 
     866} 
     867 
     868 
     869static const menu_iter options_item_iter = 
     870{ 
     871        0, 
     872        tag_options_item, 
     873        valid_options_item, 
     874        display_options_item, 
     875        NULL 
     876}; 
     877 
    784878 
    785879/* 
    786880 * Display and handle the main squelching menu. 
    787881 */ 
    788 void do_cmd_options_item(void) 
    789 
    790         bool done = FALSE; 
    791         bool no_known = FALSE; 
    792         size_t i; 
     882void do_cmd_options_item(void *unused, cptr title) 
     883
     884        int cursor = 0; 
     885        event_type c = EVENT_EMPTY; 
     886        const char cmd_keys[] = { ARROW_LEFT, ARROW_RIGHT, '\0' }; 
     887 
     888        menu_type menu; 
     889 
     890        WIPE(&menu, menu_type); 
     891        menu.title = title; 
     892        menu.cmd_keys = cmd_keys; 
     893        menu.count = N_ELEMENTS(sval_dependent) + N_ELEMENTS(extra_item_options) + 1; 
     894        menu_init2(&menu, find_menu_skin(MN_SCROLL), &options_item_iter, &SCREEN_REGION); 
     895 
     896        menu_layout(&menu, &SCREEN_REGION); 
    793897 
    794898        /* Save and clear screen */ 
     
    796900        clear_from(0); 
    797901 
    798  
    799         /* Header */ 
    800         prt("Item handling menu", 0, 0); 
    801  
    802         /* Print all typevals and their descriptions */ 
    803         for (i = 0; i < N_ELEMENTS(sval_dependent); i++) 
    804                 prt(format("%c) %s", I2A(i), sval_dependent[i].desc), i + 3, 1); 
    805  
    806         prt("Q) Quality squelching options", i + 4, 1); 
    807         prt("ESC) Back to options menu.", i + 6, 1); 
    808  
    809         while (!done) 
    810         { 
    811                 char ch; 
    812  
    813                 if (no_known) 
     902        while (c.key != ESCAPE) 
     903        { 
     904                clear_from(0); 
     905                c = menu_select(&menu, &cursor, 0); 
     906 
     907                if (c.type == EVT_SELECT) 
    814908                { 
    815                         prt("You've not seen any object of that type yet.", 1, 0); 
    816                         no_known = FALSE; 
    817                 } 
    818                 else 
    819                 { 
    820                         prt("", 1, 0); 
    821                 } 
    822  
    823                 /* Prompt */ 
    824                 ch = inkey(); 
    825  
    826                 /* Choose! */ 
    827                 if (ch == 'Q') quality_menu();         /* Switch to secondary squelching menu */ 
    828                 else if (ch == ESCAPE) done = TRUE;         /* Finished */ 
    829  
    830                 else 
    831                 { 
    832                         /* Analyze choice */ 
    833                         int choice = A2I(ch); 
    834  
    835                         /* Ignore illegal choice */ 
    836                         if (choice < 0 || choice >= (int)N_ELEMENTS(sval_dependent)) continue; 
    837  
    838                         if (!sval_menu(sval_dependent[choice].tval, sval_dependent[choice].desc)) 
    839                                 no_known = TRUE; 
     909                        if (cursor < N_ELEMENTS(sval_dependent)) 
     910                        { 
     911                                sval_menu(sval_dependent[cursor].tval, sval_dependent[cursor].desc); 
     912                        } 
     913                        else 
     914                        { 
     915                                cursor = cursor - N_ELEMENTS(sval_dependent) - 1; 
     916                                if (cursor< N_ELEMENTS(extra_item_options)) 
     917                                        extra_item_options[cursor].action(); 
     918                        } 
    840919                } 
    841920        }