Changeset 22

Show
Ignore:
Timestamp:
03/29/07 03:20:15 (2 years ago)
Author:
pmac
Message:

Some bug fixes =

  • birth menu does not go back properly
  • ui.c const correctness, regions, refresh on selection
  • birth menu does not refresh on '*'
  • squelch menu missing
  • squelch menu (and wizard menu) should not show flavors for unknown items.
  • column menus aren't presented properly
  • bugs in (not yet supported) mouse interface in ui.c
Files:

Legend:

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

    r21 r22  
    685685static region gender_region = {SEX_COL, TABLE_ROW, 15, -2}; 
    686686static region race_region = {RACE_COL, TABLE_ROW, 15, -2}; 
    687 static region class_region = {CLASS_COL, TABLE_ROW, 15, -2}; 
     687static region class_region = {CLASS_COL, TABLE_ROW, 19, -2}; 
    688688 
    689689static void show_help(cptr helpfile, cptr topic) { 
     
    705705 
    706706/* Not worth writing a general purpose handler */ 
    707 static bool gender_handler(char cmd, void *db, int oid) 
    708 { 
    709         if(cmd == '\xff') { 
     707static bool gender_handler(char cmd, const void *db, int oid) 
     708{ 
     709        if(cmd == '\xff' || cmd == '\r') { 
    710710                p_ptr->psex = oid; 
    711711                sp_ptr = &sex_info[p_ptr->psex]; 
    712712        } 
    713713        else if(cmd == '*') { 
    714                 p_ptr->psex = rand_int(SEX_MALE); 
     714                p_ptr->psex = rand_int(SEX_MALE+1); 
    715715                sp_ptr = &sex_info[p_ptr->psex]; 
    716716        } 
     717        else if(cmd == '=') do_cmd_options(); 
    717718        else if(cmd == KTRL('X')) quit(NULL); 
    718719        else if(cmd == '?')  show_help("birth.txt", sex_info[oid].title); 
     
    729730} 
    730731 
    731 static bool race_handler(char cmd, void *db, int oid) 
    732 { 
    733         if(cmd == '\xff') { 
     732static bool race_handler(char cmd, const void *db, int oid) 
     733{ 
     734        if(cmd == '\xff' || cmd == '\r') { 
    734735                p_ptr->prace = oid; 
    735736                rp_ptr = &p_info[p_ptr->prace]; 
     
    739740                rp_ptr = &p_info[p_ptr->prace]; 
    740741        } 
     742        else if(cmd == '=') do_cmd_options(); 
    741743        else if(cmd == KTRL('X')) quit(NULL); 
    742744        else if(cmd == '?')  show_help("birth.txt", p_name+p_info[oid].name); 
     
    754756} 
    755757 
    756 static bool class_handler(char cmd, void *db, int oid) 
    757 { 
    758         if(cmd == '\xff') { 
     758static bool class_handler(char cmd, const void *db, int oid) 
     759{ 
     760        if(cmd == '\xff' || cmd == '\r') { 
    759761                p_ptr->pclass = oid; 
    760762                cp_ptr = &c_info[p_ptr->pclass]; 
     
    763765        else if(cmd == '*') { 
    764766                for(;;) { 
    765                         p_ptr->pclass = rand_int(z_info->c_max); 
     767                        oid = rand_int(z_info->c_max); 
     768                        p_ptr->pclass = oid; 
    766769                        cp_ptr = &c_info[p_ptr->pclass]; 
    767770                        mp_ptr = &cp_ptr->spells; 
     
    770773                } 
    771774        } 
     775        else if(cmd == '=') do_cmd_options(); 
    772776        else if(cmd == KTRL('X')) quit(NULL); 
    773777        else if(cmd == '?') show_help("birth.txt", c_name+c_info[oid].name); 
     
    785789/* Menu display and selector */ 
    786790 
    787 static void choose_character() 
     791static bool choose_character() 
    788792{ 
    789793        int i; 
     
    801805        menu_type menu; 
    802806        WIPE(&menu, menu); 
    803         menu.cmd_keys = "?*"; 
    804  
    805         for(i = 0; i < N_ELEMENTS(menu_defs); i++) 
    806         { 
     807        menu.cmd_keys = "?*\r\x18";              /* ?, *, \n, <ctl-X> */ 
     808 
     809        i = 0; 
     810        while(i < N_ELEMENTS(menu_defs)) 
     811        { 
     812                menu.flags = MN_NO_TAGS | MN_DBL_TAP; 
     813                menu_init(&menu); 
    807814                key_event cx; 
    808815                int cursor = *values[i]; 
    809816                clear_question(); 
    810       Term_putstr(QUESTION_COL, QUESTION_ROW, -1, TERM_YELLOW, hints[i]); 
     817              Term_putstr(QUESTION_COL, QUESTION_ROW, -1, TERM_YELLOW, hints[i]); 
    811818                menu.count = limits[i]; 
    812                 menu.flags = MN_NO_TAGS | MN_DBL_TAP; 
    813                 menu_init(&menu); 
    814819                menu_set_class(&menu, &menu_defs[i]); 
    815820                menu.browse_hook = browse[i]; 
     
    817822                cx = menu_select(&menu, 0, menu.count, &cursor, *regions[i]); 
    818823                if(cx.key == ESCAPE) { 
    819                         i = 0; /* restart */ 
     824                        return FALSE; /* restart */ 
    820825                } 
    821826                else if(cx.type == EVT_BACK) { 
     827                        region_erase(regions[i]); 
    822828                        i--; 
    823829                } 
    824         } 
     830                else if(cx.key == '*') { 
     831                        /* Force refresh */ 
     832                        Term_key_push('6'); 
     833                        continue; 
     834                } 
     835                else i++; 
     836        } 
     837        return TRUE; 
    825838 
    826839} 
     
    871884        text_out_indent = 0; 
    872885 
    873         choose_character()
     886        if(!choose_character()) return FALSE
    874887 
    875888 
     
    10551068                if ((ch == '\r') || (ch == '\n')) break; 
    10561069 
     1070                ch = target_dir(ch); 
     1071 
    10571072                /* Prev stat */ 
    1058                 if (ch == '8'
     1073                if (ch == 8
    10591074                { 
    10601075                        stat = (stat + A_MAX - 1) % A_MAX; 
     
    10621077 
    10631078                /* Next stat */ 
    1064                 if (ch == '2'
     1079                if (ch == 2
    10651080                { 
    10661081                        stat = (stat + 1) % A_MAX; 
     
    10681083 
    10691084                /* Decrease stat */ 
    1070                 if ((ch == '4') && (stats[stat] > 10)) 
     1085                if ((ch == 4) && (stats[stat] > 10)) 
    10711086                { 
    10721087                        stats[stat]--; 
     
    10741089 
    10751090                /* Increase stat */ 
    1076                 if ((ch == '6') && (stats[stat] < 18)) 
     1091                if ((ch == 6) && (stats[stat] < 18)) 
    10771092                { 
    10781093                        stats[stat]++; 
  • trunk/src/cmd4.c

    r18 r22  
    13461346 
    13471347        /* Tidy name */ 
    1348         strip_name(o_name,k_idx); 
     1348        strip_name(o_name, k_idx, FALSE); 
    13491349 
    13501350        /* Display the name */ 
     
    20322032} 
    20332033 
    2034 static bool update_option(char key, void *pgdb, int oid) 
     2034static bool update_option(char key, const void *pgdb, int oid) 
    20352035{ 
    20362036        switch(toupper(key)) 
     
    41484148        {{0, 0, 0, 0}}, /* Load and append */ 
    41494149        {{0, "Window Flags", (action_f) do_cmd_options_win, 0}, 'W'}, 
     4150        {{0, "Item Squelch and Autoinscribe Menus", (action_f) do_cmd_squelch_autoinsc, 0}, 'S'}, 
    41504151        {{0, "Load a user pref file", (action_f) do_cmd_pref_file_hack, (void*)20}, 'L'}, 
    41514152        {{0, "Dump Options", (action_f) dump_pref_file, option_dump}, 'A'}, 
  • trunk/src/externs.h

    r16 r22  
    852852 
    853853bool make_fake_artifact(object_type *o_ptr, byte name1); 
    854 extern void strip_name(char *buf, int k_idx); 
     854extern void strip_name(char *buf, int k_idx, bool easy_know); 
  • trunk/src/squelch.c

    r18 r22  
    15191519 
    15201520                        /* Acquire the "name" of object "i" */ 
    1521                         strip_name(buf, choice[i]); 
     1521                        strip_name(buf, choice[i], TRUE); 
    15221522 
    15231523                        /* Deal with the active selection */ 
  • trunk/src/ui.c

    r20 r22  
    2121int menu_width = 23; 
    2222 
     23void region_erase(const region *loc) 
     24{ 
     25        int i = 0; 
     26        int w = loc->width; 
     27        int h = loc->page_rows; 
     28        if(loc->width <= 0 || loc->page_rows <= 0) { 
     29                Term_get_size(&w, &h); 
     30                if(loc->width <= 0) w -= loc->width; 
     31                if(loc->page_rows <= 0) h -= loc->page_rows; 
     32        } 
     33        for(i = 0; i < h; i++) { 
     34                Term_erase(loc->col, loc->row+i, w); 
     35        } 
     36} 
     37 
    2338static void display_menu_row(menu_type *menu, const int object_list[], int pos, 
    2439                                                                int top, bool cursor, int row, int col, int width); 
     
    3651} 
    3752 
    38 static bool inside(region *loc, key_event *key) { 
    39         if(loc->col < key->mousex) return FALSE; 
    40         if(loc->col + loc->width <= key->mousex) return FALSE; 
    41         if(loc->row < key->mousey) return FALSE; 
    42         if(loc->row + loc->page_rows <= key->mousey) return FALSE; 
    43  
     53static bool inside(const region *loc, const key_event *key) 
     54
     55        if((loc->col > key->mousex) || (loc->col + loc->width <= key->mousex)) 
     56               return FALSE; 
     57        if((loc->row > key->mousey) || (loc->row + loc->page_rows <= key->mousey)) 
     58                return FALSE; 
    4459        return TRUE; 
    4560} 
     
    5772/* act on selection only */ 
    5873/* Return: true if handled. */ 
    59 static bool handle_menu_item_event(char cmd, void *db, int oid) 
     74static bool handle_menu_item_event(char cmd, const void *db, int oid) 
    6075{ 
    6176        event_action *evt = &((event_action*)db)[oid]; 
    6277        if(cmd == '\xff' && evt->action) { 
    6378                evt->action(evt->data, evt->name); 
     79                return TRUE; 
    6480        } 
    6581        else if(cmd == '\xff') 
    6682                return TRUE; 
     83        return FALSE; 
    6784} 
    6885 
     
    101118 
    102119/* act on selection only */ 
    103 static bool handle_menu_item(char cmd, void *db, int oid) 
     120static bool handle_menu_item(char cmd, const void *db, int oid) 
    104121{ 
    105122        if(cmd == '\xff') 
     
    141158                                                                        int top, region *loc) 
    142159{ 
    143         int cursor = col - loc->col + top; 
     160        int cursor = row - loc->row + top; 
    144161        if(cursor < top) cursor = top-1; 
    145162        else if(cursor > loc->page_rows) cursor = loc->page_rows; 
     
    170187                bool is_curs = (cursor == i - *top); 
    171188                display_menu_row(menu, object_list, i, *top, is_curs, row+i, col, loc->width); 
     189        } 
     190        if(cursor >= 0) { 
     191                Term_gotoxy(col, row + cursor-*top); 
    172192        } 
    173193} 
     
    212232                        int pos = c*rows_per_page + r; 
    213233                        bool is_cursor = (pos == cursor); 
    214                         display_menu_row(menu, object_list, pos, 0, is_cursor, row+r, col+c, colw); 
     234                        display_menu_row(menu, object_list, pos, 0, is_cursor, 
     235                                                                row+r, col+c*colw, colw); 
    215236                } 
    216237        } 
     
    328349 
    329350 
    330 key_event get_menu_choice(menu_type *menu, const int object_list[], int n, int *cursor, 
    331                                                         int top, region *loc) 
     351key_event get_menu_choice(menu_type *menu, const int object_list[], int n, 
     352                                                        int *cursor, int top, region *loc) 
    332353{ 
    333354        key_event ke; 
     
    348369                        if(ke.mousex < loc->col) { 
    349370                                ke.type = EVT_BACK; 
    350                                 return ke
     371                                break
    351372                        } 
    352373 
     
    355376                                goto retry; 
    356377 
     378                        ke.index = m_curs; 
     379                        *cursor = m_curs; 
    357380                        if(*cursor == m_curs || !(menu->flags & MN_DBL_TAP)) 
    358381                        { 
    359382                                /* menu selection event*/ 
    360383                                ke.type = EVT_SELECT; 
    361                                 return ke; 
    362                         } 
    363                         *cursor = m_curs; 
     384                                break; 
     385                        } 
    364386                        /* menu movement event */ 
    365387                        ke.type = EVT_MOVE; 
     
    372394                        int dir; 
    373395                        if(menu->cmd_keys && strchr(menu->cmd_keys, ke.key)) 
    374                                 return ke
     396                                break
    375397                        if(!(menu->flags & MN_NO_TAGS)) { 
    376398                                int c = get_cursor_key(menu, object_list, n, top, ke.key); 
     
    380402                                        *cursor = c; 
    381403                                        ke.type = EVT_SELECT; 
     404                                        ke.index = c; 
    382405                                        ke.key = '\xff'; 
    383406                                        break; 
     
    488511                } 
    489512 
    490                 ke = get_menu_choice(menu, object_list, menu->count, cursor, top, &loc); 
     513                ke = get_menu_choice(menu, object_list, menu->count, cursor, top, &active); 
     514                if(*cursor != oid && ke.type == EVT_SELECT || menu->flags == MN_ONCE) 
     515                { 
     516                        /* refresh prior to return */ 
     517                        menu->skin->display_list(menu, object_list, n, *cursor, &top, &active); 
     518                } 
    491519                if(ke.key == ESCAPE) return ke; 
    492520                if(menu->flags & MN_ONCE) return ke; 
  • trunk/src/ui.h

    r20 r22  
    135135        bool (*valid_row)(menu_type *menu, int oid); 
    136136        display_row_f display_row; 
    137         bool (*handler)(char cmd, void *db, int oid); 
     137        bool (*handler)(char cmd, const void *db, int oid); 
    138138}; 
    139139 
     
    198198 
    199199 
    200         void *menu_data; /* the data used to access rows. */ 
     200        const void *menu_data; /* the data used to access rows. */ 
    201201 
    202202 
    203203        /* command action.  Should handle 0xff for selection */ 
    204         bool (*handler)(char cmd, void *db, int oid); 
     204        bool (*handler)(char cmd, const void *db, int oid); 
    205205 
    206206        void (*browse_hook)(int oid, const region *loc);  /* auxiliary browser help function */ 
     
    268268static const region SCREEN_REGION = {0, 0, 0, 0}; 
    269269 
     270/* Move to Term_ ? */ 
     271void region_erase(const region *loc); 
     272 
    270273 
    271274#endif /* UI_H */ 
  • trunk/src/wizard2.c

    r16 r22  
    416416 * Strip an "object name" into a buffer 
    417417 */ 
    418 void strip_name(char *buf, int k_idx
     418void strip_name(char *buf, int k_idx, bool easy_know
    419419{ 
    420420        char *t; 
     
    532532 
    533533                        /* Get the "name" of object "i" */ 
    534                         strip_name(buf, i); 
     534                        strip_name(buf, i, TRUE); 
    535535 
    536536                        /* Print it */