Changeset 191

Show
Ignore:
Timestamp:
06/16/07 09:32:37 (1 year ago)
Author:
takkaria
Message:

Add autoinscribe back in, using the knowledge menus, UnAngband?-style.

Files:

Legend:

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

    r171 r191  
    1919#include "angband.h" 
    2020#include "ui.h" 
     21 
     22 
    2123 
    2224 
     
    6870typedef struct 
    6971{ 
    70                int maxnum; /* Maximum possible item count for this class */ 
    71                bool easy_know; /* Items don't need to be IDed to recognize membership */ 
    72  
    73                const char *(*name)(int gid); /* name of this group */ 
    74  
    75                /* Compare, in group and display order */ 
    76                /* Optional, if already sorted */ 
    77                int (*gcomp)(const void *, const void *); /* Compare GroupIDs of two oids */ 
    78                int (*group)(int oid); /* Group ID for of an oid */ 
    79                 bool (*aware)(object_type *obj); /* Object is known sufficiently for group */ 
    80  
    81                /* summary function for the "object" information. */ 
    82                 void (*summary)(int gid, const int *object_list, int n, int top, int row, int col); 
     72        int maxnum; /* Maximum possible item count for this class */ 
     73        bool easy_know; /* Items don't need to be IDed to recognize membership */ 
     74 
     75        const char *(*name)(int gid); /* name of this group */ 
     76 
     77        /* Compare, in group and display order */ 
     78        /* Optional, if already sorted */ 
     79        int (*gcomp)(const void *, const void *); /* Compare GroupIDs of two oids */ 
     80        int (*group)(int oid); /* Group ID for of an oid */ 
     81 
     82        /* summary function for the "object" information. */ 
     83        void (*summary)(int gid, const int *object_list, int n, int top, int row, int col); 
     84 
    8385} group_funcs; 
    8486 
    8587typedef struct 
    8688{ 
    87  
    88                /* Print a tabular-formatted description for an oid */ 
    89                /* This includes things like kill-count, the current graphic, */ 
    90                /* any tile illumination info. Item id for Wizard mode and */ 
    91                /* autoinscription are handled by the caller */ 
    92                 void (*display_member)(int col, int row, bool cursor, int oid);  
    93  
    94                 void (*lore)(int oid); /* Dump known lore to screen*/ 
    95  
    96  
    97                /* Required only for objects with modifiable display attributes */ 
    98                /* Unknown 'flavors' return flavor attributes */ 
    99                char *(*xchar)(int oid); /* get character attr for OID (by address) */ 
    100                 byte *(*xattr)(int oid); /* get color attr for OID (by address) */ 
    101  
    102                /* Required only for manipulable (ordinary) objects */ 
    103                /* Address of inscription.  Unknown 'flavors' return null */ 
    104                 u16b *(*note)(int oid); 
    105  
    106                /* extra context for display of members */ 
    107                bool is_visual; 
     89        /* Print a tabular-formatted description for an oid */ 
     90        /* This includes things like kill-count, the current graphic, */ 
     91        /* any tile illumination info. Item id for Wizard mode and */ 
     92        /* autoinscription are handled by the caller */ 
     93        void (*display_member)(int col, int row, bool cursor, int oid); 
     94 
     95        void (*lore)(int oid); /* Dump known lore to screen*/ 
     96 
     97 
     98        /* Required only for objects with modifiable display attributes */ 
     99        /* Unknown 'flavors' return flavor attributes */ 
     100        char *(*xchar)(int oid); /* get character attr for OID (by address) */ 
     101        byte *(*xattr)(int oid); /* get color attr for OID (by address) */ 
     102 
     103 
     104        const char *(*xtra_prompt)(int oid);           /* For kinds that need extra prompts */ 
     105        void (*xtra_act)(char ch, int oid);            /* For kinds that need extra actions */ 
     106 
     107 
     108        /* extra context for display of members */ 
     109        bool is_visual; 
    108110 
    109111 
     
    301303} 
    302304 
    303 /* 
    304  * Interact with inscriptions. 
    305  * Create a copy of an existing quark, except if the quark has '=x' in it,  
    306  * If an quark has '=x' in it remove it from the copied string, otherwise append it where 'x' is ch. 
    307  * Return the new quark location. 
    308  */ 
    309 static int auto_note_modify(int note, char ch) 
    310 { 
    311         char tmp[80]; 
    312  
    313         cptr s; 
    314  
    315         /* Paranoia */ 
    316         if (!ch) return(note); 
    317  
    318         /* Null length string to start */ 
    319         tmp[0] = '\0'; 
    320  
    321         /* Inscription */ 
    322         if (note) 
    323         { 
    324  
    325                 /* Get the inscription */ 
    326                 s = quark_str(note); 
    327  
    328                 /* Temporary copy */ 
    329                 my_strcpy(tmp,s,80); 
    330  
    331                 /* Process inscription */ 
    332                 while (s) 
    333                 { 
    334  
    335                         /* Auto-pickup on "=g" */ 
    336                         if (s[1] == ch) 
    337                         { 
    338  
    339                                 /* Truncate string */ 
    340                                 tmp[strlen(tmp)-strlen(s)] = '\0'; 
    341  
    342                                 /* Overwrite shorter string */ 
    343                                 my_strcat(tmp,s+2,80); 
    344  
    345                                 /* Create quark */ 
    346                                 return(quark_add(tmp)); 
    347                         } 
    348  
    349                         /* Find another '=' */ 
    350                         s = strchr(s + 1, '='); 
    351                 } 
    352         } 
    353  
    354         /* Append note */ 
    355         my_strcat(tmp,format("=%c",ch),80); 
    356  
    357         /* Create quark */ 
    358         return(quark_add(tmp)); 
    359 } 
    360  
    361305 
    362306static void display_group_member(menu_type *menu, int oid, 
     
    366310        byte attr = curs_attrs[CURS_KNOWN][cursor == oid]; 
    367311 
    368         /* Show inscription, if applicable, aware and existing */ 
    369         if (o_funcs->note && o_funcs->note(oid) && *o_funcs->note(oid)) 
    370         { 
    371                 c_put_str(TERM_YELLOW,quark_str(*o_funcs->note(oid)), row, 65); 
    372         } 
    373312        /* Print the interesting part */ 
    374313        o_funcs->display_member(col, row, cursor, oid); 
     
    421360        byte attr_top = 0; 
    422361        char char_left = 0; 
    423         int note_idx = 0; 
    424362 
    425363        int delay = 0; 
     
    520458                        region_erase(&title_area); 
    521459                        prt(format("Knowledge - %s", title), 2, 0); 
    522                         prt( "Group", 4, 0); 
     460                        prt("Group", 4, 0); 
    523461                        prt("Name", 4, g_name_len + 3); 
    524                         Term_gotoxy(65, 4); 
    525                         if (o_funcs.note) 
    526                                 Term_addstr(-1, TERM_WHITE, "Inscribed "); 
     462 
     463                        Term_gotoxy(55, 4); 
    527464                        if (otherfields) 
    528465                                Term_addstr(-1, TERM_WHITE, otherfields); 
     466 
    529467                        for (i = 0; i < 78; i++) 
    530468                                Term_putch(i, 5, TERM_WHITE, '='); 
     469 
    531470                        for (i = 0; i < browser_rows; i++) 
    532471                                Term_putch(g_name_len + 1, 6 + i, TERM_WHITE, '|'); 
     
    544483                        object_menu.cursor = 0; 
    545484                } 
     485 
    546486                /* HACK ... */ 
    547487                if (!visual_list) 
     
    556496                        /* ... or just a single element in the group. */ 
    557497                        o_funcs.is_visual = TRUE; 
    558                         menu_set_filter(&object_menu, obj_list + o_cur +g_offset[g_cur], 1); 
     498                        menu_set_filter(&object_menu, obj_list + o_cur + g_offset[g_cur], 1); 
    559499                        object_menu.cursor = 0; 
    560500                } 
     501 
    561502                oid = obj_list[g_offset[g_cur]+o_cur]; 
     503 
    562504                /* Prompt */ 
    563505                { 
     
    565507                                        (!(attr_idx|char_idx) ? ", 'c' to copy" : ", 'c', 'p' to paste"); 
    566508 
    567                         const char *pnote = (!o_funcs.note || !o_funcs.note(oid)) ? 
    568                                                         "" : ((note_idx) ? ", '\\' to re-inscribe"  :  ""); 
    569  
    570                         const char *pnote1 = (!o_funcs.note || !o_funcs.note(oid)) ? 
    571                                                                         "" : ", '{', '}', 'k', 'g', ..."; 
    572  
    573                         const char *pvs = (!o_funcs.xattr) ? "" : ", 'v' for visuals"; 
     509                        const char *pvs =  o_funcs.xattr       ? ", 'v' for visuals"      : ""; 
     510                        const char *xtra = o_funcs.xtra_prompt ? o_funcs.xtra_prompt(oid) : ""; 
    574511 
    575512                        if (visual_list) 
    576513                                prt(format("<dir>, 'r' to recall, ENTER to accept%s, ESC", pedit), hgt-1, 0); 
    577514                        else  
    578                                 prt(format("<dir>, 'r' to recall%s ESC%s%s%s", 
    579                                                                                pvs, pedit, pnote, pnote1), hgt-1, 0); 
    580                 } 
     515                                prt(format("<dir>, 'r' to recall%s%s%s, ESC", pvs, pedit, xtra), hgt-1, 0); 
     516                } 
     517 
    581518                if (do_swap) 
    582519                { 
     
    596533                if (visual_list) 
    597534                { 
    598          
    599535                        display_visual_list(g_name_len + 3, 7, browser_rows-1, 
    600536                                   wid - (g_name_len + 3), attr_top, char_left); 
     
    636572                        } 
    637573                } 
     574 
    638575                ke0 = run_event_loop(&active_menu->target, 0, &ke); 
    639576                if (ke0.type != EVT_AGAIN) ke = ke0; 
    640                 switch(ke.type) { 
     577                switch(ke.type) 
     578                { 
    641579                        case EVT_KBRD: 
    642580                                break; 
     
    659597                                continue; 
    660598                } 
     599 
    661600                switch (ke.key) 
    662601                { 
    663  
    664602                        case ESCAPE: 
    665603                        { 
     
    679617                        } 
    680618 
    681                         /* HACK: make this a function.  Replace g_funcs.aware() */ 
    682                         case '{': 
    683                         case '}': 
    684                         case '\\': 
    685                                 /* precondition -- valid object */ 
    686                                 if (o_funcs.note == NULL || o_funcs.note(oid) == 0) 
    687                                                 break; 
    688                         { 
    689                                 char note_text[80] = ""; 
    690                                 u16b *note = o_funcs.note(oid); 
    691                                 u16b old_note = *note; 
    692  
    693                                 if (ke.key == '{') 
    694                                 { 
    695                                         /* Prompt */ 
    696                                         prt("Inscribe with: ", hgt, 0); 
    697  
    698                                         /* Default note */ 
    699                                         if (old_note) 
    700                                                 strnfmt(note_text, sizeof note_text, "%s", quark_str(old_note)); 
    701  
    702                                         /* Get a filename */ 
    703                                         if (!askfor_aux(note_text, sizeof note_text, NULL)) continue; 
    704  
    705                                                 /* Set the inscription */ 
    706                                                 *note = quark_add(note_text); 
    707  
    708                                         /* Set the current default note */ 
    709                                         note_idx = *note; 
    710                                 } 
    711                                 else if (ke.key == '}') 
    712                                 { 
    713                                         *note = 0; 
    714                                 } 
    715                                 else 
    716                                 { 
    717                                         /* '\\' */ 
    718                                         *note = note_idx; 
    719                                 } 
    720  
    721                                 /* Process existing objects */ 
    722                                 for (i = 1; i < o_max; i++) 
    723                                 { 
    724                                         /* Get the object */ 
    725                                         object_type *i_ptr = &o_list[i]; 
    726  
    727                                         /* Skip dead or differently sourced items */ 
    728                                         if (!i_ptr->k_idx || i_ptr->note != old_note) continue; 
    729  
    730                                         /* Not matching item */ 
    731                                         if (!g_funcs.group(oid) != i_ptr->tval) continue; 
    732  
    733                                         /* Auto-inscribe */ 
    734                                         if (g_funcs.aware(i_ptr) || cheat_peek) 
    735                                                 i_ptr->note = note_idx; 
    736                                 } 
    737  
    738                                 break; 
    739                         } 
    740  
    741619                        default: 
    742620                        { 
    743621                                int d = target_dir(ke.key); 
     622 
    744623                                /* Handle key-driven motion between panels */ 
    745624                                if (ddx[d] && ((ddx[d] < 0) == (panel == 1))) 
     
    752631                                        do_swap = TRUE; 
    753632                                } 
    754                                 else if (o_funcs.note && o_funcs.note(oid)
     633                                else if (o_funcs.xtra_act
    755634                                { 
    756                                         note_idx = auto_note_modify(*o_funcs.note(oid), ke.key); 
    757                                         *o_funcs.note(oid) = note_idx; 
     635                                        o_funcs.xtra_act(ke.key, oid); 
    758636                                } 
     637 
    759638                                break; 
    760639                        } 
     
    1112991{ 
    1113992        group_funcs r_funcs = {N_ELEMENTS(monster_group), FALSE, race_name, 
    1114                                                         m_cmp_race, default_group, 0, mon_summary}; 
    1115  
    1116         member_funcs m_funcs = {display_monster, mon_lore, m_xchar, m_xattr, 0, 0}; 
     993                                                        m_cmp_race, default_group, mon_summary}; 
     994 
     995        member_funcs m_funcs = {display_monster, mon_lore, m_xchar, m_xattr, 0, 0, 0}; 
    1117996 
    1118997         
     
    11611040 
    11621041        display_knowledge("monsters", monsters, m_count, r_funcs, m_funcs, 
    1163                                                 "Sym  Kills"); 
     1042                                                "          Sym  Kills"); 
    11641043        FREE(monsters); 
    11651044        FREE(default_join); 
     
    12551134{ 
    12561135        /* HACK -- should be TV_MAX */ 
    1257         group_funcs obj_f = {TV_GOLD, FALSE, kind_name, a_cmp_tval, art2tval, 0, 0}; 
    1258         member_funcs art_f = {display_artifact, desc_art_fake, 0, 0, 0, 0}; 
     1136        group_funcs obj_f = {TV_GOLD, FALSE, kind_name, a_cmp_tval, art2tval, 0}; 
     1137        member_funcs art_f = {display_artifact, desc_art_fake, 0, 0, 0, 0, 0}; 
    12591138 
    12601139 
     
    13851264{ 
    13861265        group_funcs obj_f = 
    1387                 {TV_GOLD, FALSE, ego_grp_name, e_cmp_tval, default_group, 0, 0}; 
    1388  
    1389         member_funcs ego_f = {display_ego_item, desc_ego_fake, 0, 0, 0, 0/*e_note */ }; 
     1266                {TV_GOLD, FALSE, ego_grp_name, e_cmp_tval, default_group, 0}; 
     1267 
     1268        member_funcs ego_f = {display_ego_item, desc_ego_fake, 0, 0, 0, 0, 0}; 
    13901269 
    13911270        int *egoitems; 
     
    14291308        int k_idx = oid; 
    14301309         
    1431         /* Access the object */ 
    14321310        object_kind *k_ptr = &k_info[k_idx]; 
     1311        const char *inscrip = get_autoinscription(oid); 
    14331312 
    14341313        char o_name[80]; 
     1314 
    14351315 
    14361316        /* Choose a color */ 
     
    14521332        strip_name(o_name, k_idx, cheat_know); 
    14531333 
     1334 
    14541335        /* Display the name */ 
    14551336        c_prt(attr, o_name, row, col); 
     1337 
     1338        /* Show autoinscription if around */ 
     1339        if (inscrip) 
     1340                c_put_str(TERM_YELLOW, inscrip, row, 55); 
    14561341 
    14571342 
     
    15311416} 
    15321417 
    1533 static u16b *o_note(int oid) { 
     1418/* 
     1419 * Display special prompt for object inscription. 
     1420 */ 
     1421static const char *o_xtra_prompt(int oid) 
     1422
    15341423        object_kind *k_ptr = &k_info[oid]; 
    1535         int ind = get_autoinscription_index(oid); 
    1536         if (!k_ptr->flavor || k_ptr->aware) return (u16b*) &inscriptions[ind].inscription_idx; 
    1537         else return 0; 
    1538 
     1424        s16b idx = get_autoinscription_index(oid); 
     1425 
     1426        const char *no_insc = ", '{'"; 
     1427        const char *with_insc = ", '{', '}'"; 
     1428 
     1429 
     1430        /* Forget it if we've never seen the thing */ 
     1431        if (!k_ptr->everseen) 
     1432                return ""; 
     1433 
     1434        /* If it's already inscribed */ 
     1435        if (idx != -1) 
     1436                return with_insc; 
     1437 
     1438        return no_insc; 
     1439
     1440 
     1441/* 
     1442 * Special key actions for object inscription. 
     1443 */ 
     1444static void o_xtra_act(char ch, int oid) 
     1445
     1446        object_kind *k_ptr = &k_info[oid]; 
     1447        s16b idx = get_autoinscription_index(oid); 
     1448 
     1449        /* Forget it if we've never seen the thing */ 
     1450        if (!k_ptr->everseen) 
     1451                return; 
     1452 
     1453        /* Uninscribe */ 
     1454        if (ch == '}') 
     1455        { 
     1456                if (idx) remove_autoinscription(oid); 
     1457                return; 
     1458        } 
     1459 
     1460        /* Inscribe */ 
     1461        else if (ch == '{') 
     1462        { 
     1463                char note_text[80] = ""; 
     1464 
     1465                /* Avoid the prompt getting in the way */ 
     1466                screen_save(); 
     1467 
     1468                /* Prompt */ 
     1469                prt("Inscribe with: ", 0, 0); 
     1470 
     1471                /* Default note */ 
     1472                if (idx != -1) 
     1473                        strnfmt(note_text, sizeof(note_text), "%s", get_autoinscription(oid)); 
     1474 
     1475                /* Get an inscription */ 
     1476                if (askfor_aux(note_text, sizeof(note_text), NULL)) 
     1477                { 
     1478                        /* Remove old inscription if existent */ 
     1479                        if (idx != -1) 
     1480                                remove_autoinscription(oid); 
     1481 
     1482                        /* Add the autoinscription */ 
     1483                        add_autoinscription(oid, note_text); 
     1484 
     1485                        /* Notice stuff (later) */ 
     1486                        p_ptr->notice |= (PN_AUTOINSCRIBE); 
     1487                        p_ptr->window |= (PW_INVEN | PW_EQUIP); 
     1488                } 
     1489 
     1490                /* Reload the screen */ 
     1491                screen_load(); 
     1492        } 
     1493
     1494 
     1495 
    15391496 
    15401497/* 
     
    15431500static void do_cmd_knowledge_objects(void) 
    15441501{ 
    1545         group_funcs kind_f = {TV_GOLD, FALSE, kind_name, o_cmp_tval, obj2gid, 0, 0}; 
    1546         member_funcs obj_f = {display_object, desc_obj_fake, o_xchar, o_xattr,0 /* o_note*/}; 
     1502        group_funcs kind_f = {TV_GOLD, FALSE, kind_name, o_cmp_tval, obj2gid, 0}; 
     1503        member_funcs obj_f = {display_object, desc_obj_fake, o_xchar, o_xattr, o_xtra_prompt, o_xtra_act, 0}; 
    15471504 
    15481505        int *objects; 
     
    15601517                } 
    15611518        } 
    1562         display_knowledge("known objects", objects, o_count, kind_f, obj_f, "         Sym"); 
     1519 
     1520        display_knowledge("known objects", objects, o_count, kind_f, obj_f, "Inscribed          Sym"); 
     1521 
    15631522        FREE(objects); 
    15641523} 
     
    16161575{ 
    16171576        group_funcs fkind_f = {N_ELEMENTS(feature_group_text), FALSE, 
    1618                                                         fkind_name, f_cmp_fkind, feat_order, 0, 0}; 
    1619  
    1620         member_funcs feat_f = {display_feature, feat_lore, f_xchar, f_xattr, 0}; 
     1577                                                        fkind_name, f_cmp_fkind, feat_order, 0}; 
     1578 
     1579        member_funcs feat_f = {display_feature, feat_lore, f_xchar, f_xattr, 0, 0, 0}; 
    16211580 
    16221581        int *features; 
     
    16311590        } 
    16321591 
    1633         display_knowledge("features", features, f_count, fkind_f, feat_f, " Sym"); 
     1592        display_knowledge("features", features, f_count, fkind_f, feat_f, "           Sym"); 
    16341593        FREE(features); 
    16351594} 
  • trunk/src/squelch.c

    r189 r191  
    663663{ 
    664664        char buf[80]; 
    665         const char *inscrip; 
    666665        const u16b *choice = menu->menu_data; 
    667666        int idx = choice[oid]; 
     
    677676        if (k_info[idx].squelch) 
    678677                c_put_str(TERM_L_RED, "*", row, col + 1); 
    679  
    680         inscrip = get_autoinscription(choice[oid]); 
    681         if (!inscrip) inscrip = "(none)"; 
    682  
    683         c_put_str(attr, format("%-40s", inscrip), row, col + 40); 
    684678} 
    685679 
     
    689683static bool sval_action(char cmd, void *db, int oid) 
    690684{ 
    691         char buf[80] = ""; 
    692685        u16b *choice = db; 
    693686 
     
    697690                int idx = choice[oid]; 
    698691                k_info[idx].squelch = !k_info[idx].squelch; 
    699  
    700                 return TRUE; 
    701         } 
    702  
    703         /* Set inscription */ 
    704         else if (cmd == '\n' || cmd == '\r') 
    705         { 
    706                 s16b k_idx = choice[oid]; 
    707                 const char *inscrip; 
    708  
    709                 /* Obtain the current inscription */ 
    710                 inscrip = get_autoinscription(k_idx);    
    711  
    712                 /* Copy of the current inscription, or clear the buffer */ 
    713                 if (inscrip) 
    714                         my_strcpy(buf, inscrip, sizeof(buf)); 
    715  
    716                 /* Get a new inscription (possibly empty) */ 
    717                 if (get_string("Autoinscription: ", buf, sizeof(buf))) 
    718                 { 
    719                         /* Save the inscription */ 
    720                         add_autoinscription(k_idx, buf); 
    721  
    722                         /* Notice stuff (later) */ 
    723                         p_ptr->notice |= (PN_AUTOINSCRIBE); 
    724                         p_ptr->window |= (PW_INVEN | PW_EQUIP); 
    725                 } 
    726692 
    727693                return TRUE; 
     
    794760        text_out(" to return to the previous menu.  "); 
    795761        text_out_c(TERM_L_BLUE, "Space"); 
    796         text_out(" toggles the current setting, and "); 
    797         text_out_c(TERM_L_GREEN, "Enter"); 
    798         text_out(" will prompt you for a new autoinscription."); 
     762        text_out(" toggles the current setting."); 
    799763 
    800764        /* Set up the menu */