Changeset 120
- Timestamp:
- 05/07/07 12:00:03 (1 year ago)
- Files:
-
- trunk/src/birth.c (modified) (3 diffs)
- trunk/src/cmd4.c (modified) (11 diffs)
- trunk/src/dungeon.c (modified) (3 diffs)
- trunk/src/externs.h (modified) (2 diffs)
- trunk/src/files.c (modified) (5 diffs)
- trunk/src/object1.c (modified) (1 diff)
- trunk/src/squelch.c (modified) (3 diffs)
- trunk/src/store.c (modified) (1 diff)
- trunk/src/ui.h (modified) (1 diff)
- trunk/src/util.c (modified) (10 diffs)
- trunk/src/z-term.c (modified) (6 diffs)
- trunk/src/z-term.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/birth.c
r111 r120 1219 1219 1220 1220 /* Get a response (or escape) */ 1221 if (!askfor_aux(inp, 9 )) inp[0] = '\0';1221 if (!askfor_aux(inp, 9, NULL)) inp[0] = '\0'; 1222 1222 1223 1223 /* Hack -- add a fake slash */ … … 1497 1497 prt(" a) Use the point-based system", 2, 1); 1498 1498 prt(" b) Use the autoroller", 3, 1); 1499 prt(" c ) Use the basic roller", 4, 1);1499 prt(" c/*) Use the basic roller", 4, 1); 1500 1500 1501 1501 prt("", 6, 1); … … 1516 1516 case 'c': 1517 1517 case 'C': 1518 case '*': 1518 1519 done = TRUE; 1519 1520 break; trunk/src/cmd4.c
r116 r120 662 662 663 663 /* Get a filename */ 664 if (!askfor_aux(note_text, sizeof note_text )) continue;664 if (!askfor_aux(note_text, sizeof note_text, NULL)) continue; 665 665 666 666 /* Set the inscription */ … … 1613 1613 flush(); 1614 1614 1615 if(0 != character_dungeon)1615 if (0 != character_dungeon) 1616 1616 verify_panel(); 1617 1617 … … 1649 1649 1650 1650 /* Place the cursor on the player */ 1651 if (0 != character_dungeon)1651 if (0 != character_dungeon) 1652 1652 move_cursor_relative(p_ptr->px, p_ptr->py); 1653 1653 … … 1671 1671 Term_activate(old); 1672 1672 } 1673 }1674 1675 void do_cmd_resize()1676 {1677 /* Escape to main screen on resize */1678 Term_key_push(ESCAPE);1679 do_cmd_redraw();1680 1673 } 1681 1674 … … 1905 1898 1906 1899 /* Get a "shower" string, or continue */ 1907 if (!askfor_aux(shower, sizeof shower )) continue;1900 if (!askfor_aux(shower, sizeof shower, NULL)) continue; 1908 1901 1909 1902 /* Okay */ … … 1920 1913 1921 1914 /* Get a "finder" string, or continue */ 1922 if (!askfor_aux(finder, sizeof finder )) continue;1915 if (!askfor_aux(finder, sizeof finder, NULL)) continue; 1923 1916 1924 1917 /* Show it */ … … 2052 2045 2053 2046 /* Ask for a file (or cancel) */ 2054 if (!askfor_aux(ftmp, sizeof ftmp )) return;2047 if (!askfor_aux(ftmp, sizeof ftmp, NULL)) return; 2055 2048 2056 2049 /* Process the given filename */ … … 2514 2507 2515 2508 /* Get a filename */ 2516 if (!askfor_aux(ftmp, sizeof ftmp )) return;2509 if (!askfor_aux(ftmp, sizeof ftmp, NULL)) return; 2517 2510 2518 2511 /* Build the filename */ … … 3002 2995 3003 2996 /* Get an encoded action */ 3004 if (askfor_aux(tmp, sizeof tmp ))2997 if (askfor_aux(tmp, sizeof tmp, NULL)) 3005 2998 { 3006 2999 /* Convert to ascii */ … … 3100 3093 3101 3094 /* Get an encoded action */ 3102 if (askfor_aux(tmp, sizeof tmp ))3095 if (askfor_aux(tmp, sizeof tmp, NULL)) 3103 3096 { 3104 3097 /* Convert to ascii */ … … 3149 3142 3150 3143 /* Get an encoded action */ 3151 if (askfor_aux(tmp, sizeof tmp ))3144 if (askfor_aux(tmp, sizeof tmp, NULL)) 3152 3145 { 3153 3146 /* Extract an action */ trunk/src/dungeon.c
r119 r120 1388 1388 } 1389 1389 1390 /* Within these boundaries, the cast to unsigned char will have the desired effect */ 1391 assert(p_ptr->command_cmd >= CHAR_MIN && p_ptr->command_cmd <= CHAR_MAX); 1392 1393 /* Execute the command */ 1394 if (converted_list[(unsigned char) p_ptr->command_cmd]) 1395 converted_list[(unsigned char) p_ptr->command_cmd](); 1390 /* Handle resize events XXX */ 1391 if (p_ptr->command_cmd_ex.type == EVT_RESIZE) 1392 { 1393 do_cmd_redraw(); 1394 } 1395 else 1396 { 1397 /* Within these boundaries, the cast to unsigned char will have the desired effect */ 1398 assert(p_ptr->command_cmd >= CHAR_MIN && p_ptr->command_cmd <= CHAR_MAX); 1399 1400 /* Execute the command */ 1401 if (converted_list[(unsigned char) p_ptr->command_cmd]) 1402 converted_list[(unsigned char) p_ptr->command_cmd](); 1403 } 1396 1404 } 1397 1405 … … 1700 1708 move_cursor_relative(p_ptr->py, p_ptr->px); 1701 1709 1702 /* Get a command (normal) */ 1703 request_command(FALSE); 1704 1705 /* Process the command */ 1710 /* Get and process a command */ 1711 request_command(); 1706 1712 process_command(); 1707 1713 } … … 2246 2252 (void)Term_set_cursor(FALSE); 2247 2253 2248 /* Set screen resize hook */2249 Term_set_resize_hook(do_cmd_resize);2250 2251 2254 /* Attempt to load */ 2252 2255 if (!load_player()) trunk/src/externs.h
r119 r120 727 727 extern void text_out_c(byte a, cptr str); 728 728 extern void clear_from(int row); 729 extern bool askfor_aux(char *buf, size_t len );729 extern bool askfor_aux(char *buf, size_t len, bool keypress_h(char *, size_t, size_t *, size_t *, char, bool)); 730 730 extern bool get_string(cptr prompt, char *buf, size_t len); 731 731 extern s16b get_quantity(cptr prompt, int max); … … 735 735 extern bool get_com_ex(cptr prompt, event_type *command); 736 736 extern void pause_line(int row); 737 extern void request_command( bool shopping);737 extern void request_command(void); 738 738 extern int damroll(int num, int sides); 739 739 extern int maxroll(int num, int sides); trunk/src/files.c
r116 r120 2404 2404 /* Get "shower" */ 2405 2405 prt("Show: ", hgt - 1, 0); 2406 (void)askfor_aux(shower, sizeof(shower) );2406 (void)askfor_aux(shower, sizeof(shower), NULL); 2407 2407 2408 2408 /* Make the "shower" lowercase */ … … 2415 2415 /* Get "finder" */ 2416 2416 prt("Find: ", hgt - 1, 0); 2417 if (askfor_aux(finder, sizeof(finder) ))2417 if (askfor_aux(finder, sizeof(finder), NULL)) 2418 2418 { 2419 2419 /* Find it */ … … 2436 2436 prt("Goto Line: ", hgt - 1, 0); 2437 2437 strcpy(tmp, "0"); 2438 if (askfor_aux(tmp, sizeof(tmp) ))2438 if (askfor_aux(tmp, sizeof(tmp), NULL)) 2439 2439 { 2440 2440 line = atoi(tmp); … … 2448 2448 prt("Goto File: ", hgt - 1, 0); 2449 2449 strcpy(ftmp, "help.hlp"); 2450 if (askfor_aux(ftmp, sizeof(ftmp) ))2450 if (askfor_aux(ftmp, sizeof(ftmp), NULL)) 2451 2451 { 2452 2452 if (!show_file(ftmp, NULL, 0, mode)) ch = ESCAPE; … … 2612 2612 } 2613 2613 } 2614 2615 2616 /*2617 * Gets a name for the character, reacting to name changes.2618 *2619 * Perhaps we should NOT ask for a name (at "birth()") on2620 * Unix machines? XXX XXX XXX2621 *2622 * What a horrible name for a global function. XXX XXX XXX2623 */2624 void get_name(void)2625 {2626 char tmp[32];2627 2628 /* Save the player name */2629 my_strcpy(tmp, op_ptr->full_name, sizeof(tmp));2630 2631 /* Prompt for a new name */2632 if (get_string("Enter a name for your character: ", tmp, sizeof(tmp)))2633 {2634 /* Use the name */2635 my_strcpy(op_ptr->full_name, tmp, sizeof(op_ptr->full_name));2636 2637 /* Process the player name */2638 process_player_name(FALSE);2639 }2640 }2641 2642 2614 2643 2615 trunk/src/object1.c
r119 r120 650 650 char b1 = '[', b2 = ']'; 651 651 char c1 = '{', c2 = '}'; 652 653 char discount_buf[80];654 652 655 653 char tmp_buf[128]; trunk/src/squelch.c
r98 r120 614 614 615 615 /* Get a filename */ 616 if (askfor_aux(fname, sizeof fname ))616 if (askfor_aux(fname, sizeof fname, NULL)) 617 617 { 618 618 /* Build the filename */ … … 688 688 689 689 /* Get a filename */ 690 if (askfor_aux(fname, sizeof fname ))690 if (askfor_aux(fname, sizeof fname, NULL)) 691 691 { 692 692 /* Build the filename */ … … 743 743 744 744 /* Ask for a file (or cancel) */ 745 if (askfor_aux(fname, sizeof fname ))745 if (askfor_aux(fname, sizeof fname, NULL)) 746 746 { 747 747 /* Process the given filename, note success or failure */ trunk/src/store.c
r117 r120 2500 2500 /* 2501 2501 * Enter a store, and interact with it. 2502 *2503 * Note that we use the standard "request_command()" function2504 * to get a command, allowing us to use "p_ptr->command_arg" and all2505 * command macros and other nifty stuff, but we use the special2506 * "shopping" argument, to force certain commands to be converted2507 * into other commands, normally, we convert "p" (pray) and "m"2508 * (cast magic) into "g" (get), and "s" (search) into "d" (drop).2509 2502 */ 2510 2503 void do_cmd_store(void) trunk/src/ui.h
r95 r120 130 130 struct panel_type { 131 131 event_target target; 132 void (*refresh)( );132 void (*refresh)(void); 133 133 region boundary; 134 134 }; trunk/src/util.c
r112 r120 10 10 11 11 #include "angband.h" 12 12 #include "randname.h" 13 13 14 14 … … 2658 2658 } 2659 2659 2660 2661 2660 /* 2661 * The default "keypress handling function" for askfor_aux, this takes the 2662 * given keypress, input buffer, length, etc, and does the appropriate action 2663 * for each keypress, such as moving the cursor left or inserting a character. 2664 * 2665 * It should return TRUE when editing of the buffer is "complete" (e.g. on 2666 * the press of RETURN). 2667 */ 2668 bool askfor_aux_keypress(char *buf, size_t buflen, size_t *curs, size_t *len, char keypress, bool firsttime) 2669 { 2670 switch (keypress) 2671 { 2672 case ESCAPE: 2673 { 2674 *curs = 0; 2675 return TRUE; 2676 break; 2677 } 2678 2679 case '\n': 2680 case '\r': 2681 { 2682 *curs = *len; 2683 return TRUE; 2684 break; 2685 } 2686 2687 case ARROW_LEFT: 2688 { 2689 if (firsttime) *curs = 0; 2690 if (*curs > 0) (*curs)--; 2691 break; 2692 } 2693 2694 case ARROW_RIGHT: 2695 { 2696 if (firsttime) *curs = *len - 1; 2697 if (*curs < *len) (*curs)++; 2698 break; 2699 } 2700 2701 case 0x7F: 2702 case '\010': 2703 { 2704 /* If this is the first time round, backspace means "delete all" */ 2705 if (firsttime) 2706 { 2707 buf[0] = '\0'; 2708 *curs = 0; 2709 *len = 0; 2710 2711 break; 2712 } 2713 2714 /* Refuse to backspace into oblivion */ 2715 if (*curs == 0) break; 2716 2717 /* Move the string from k to nul along to the left by 1 */ 2718 memmove(&buf[*curs - 1], &buf[*curs], *len - *curs); 2719 2720 /* Decrement */ 2721 (*curs)--; 2722 (*len)--; 2723 2724 /* Terminate */ 2725 buf[*len] = '\0'; 2726 2727 break; 2728 } 2729 2730 default: 2731 { 2732 bool atnull = (buf[*curs] == 0); 2733 2734 2735 if (!isprint((unsigned char)keypress)) 2736 { 2737 bell("Illegal edit key!"); 2738 break; 2739 } 2740 2741 /* Clear the buffer if this is the first time round */ 2742 if (firsttime) 2743 { 2744 buf[0] = '\0'; 2745 *curs = 0; 2746 *len = 0; 2747 atnull = 1; 2748 } 2749 2750 if (atnull) 2751 { 2752 /* Make sure we have enough room for a new character */ 2753 if ((*curs + 1) >= buflen) break; 2754 } 2755 else 2756 { 2757 /* Make sure we have enough room to add a new character */ 2758 if ((*len + 1) >= buflen) break; 2759 2760 /* Move the rest of the buffer along to make room */ 2761 memmove(&buf[*curs+1], &buf[*curs], *len - *curs); 2762 } 2763 2764 /* Insert the character */ 2765 buf[(*curs)++] = keypress; 2766 (*len)++; 2767 2768 /* Terminate */ 2769 buf[*len] = '\0'; 2770 2771 break; 2772 } 2773 } 2774 2775 /* By default, we aren't done. */ 2776 return FALSE; 2777 } 2662 2778 2663 2779 /* … … 2677 2793 * Note that 'len' refers to the size of the buffer. The maximum length 2678 2794 * of the input is 'len-1'. 2679 */ 2680 bool askfor_aux(char *buf, size_t len) 2681 { 2795 * 2796 * 'keypress_h' is a pointer to a function to handle keypresses, altering 2797 * the input buffer, cursor position and suchlike as required. See 2798 * 'askfor_aux_keypress' (the default handler if you supply NULL for 2799 * 'keypress_h') for an example. 2800 */ 2801 bool askfor_aux(char *buf, size_t len, bool keypress_h(char *, size_t, size_t *, size_t *, char, bool)) 2802 { 2803 2682 2804 int y, x; 2683 2805 … … 2690 2812 bool firsttime = TRUE; 2691 2813 2814 if (keypress_h == NULL) 2815 { 2816 keypress_h = askfor_aux_keypress; 2817 } 2692 2818 2693 2819 /* Locate the cursor */ … … 2721 2847 ch = inkey(); 2722 2848 2723 /* Analyze the key */ 2724 switch (ch) 2725 { 2726 case ESCAPE: 2727 { 2728 k = 0; 2729 done = TRUE; 2730 break; 2731 } 2732 2733 case '\n': 2734 case '\r': 2735 { 2736 k = strlen(buf); 2737 done = TRUE; 2738 break; 2739 } 2740 2741 case ARROW_LEFT: 2742 { 2743 if (firsttime) k = 0; 2744 if (k > 0) k--; 2745 break; 2746 } 2747 2748 case ARROW_RIGHT: 2749 { 2750 if (firsttime) k = nul - 1; 2751 if (k < nul) k++; 2752 break; 2753 } 2754 2755 case 0x7F: 2756 case '\010': 2757 { 2758 /* If this is the first time round, backspace means "delete all" */ 2759 if (firsttime) 2760 { 2761 buf[0] = '\0'; 2762 k = 0; 2763 nul = 0; 2764 2765 break; 2766 } 2767 2768 /* Refuse to backspace into oblivion */ 2769 if (k == 0) break; 2770 2771 /* Move the string from k to nul along to the left by 1 */ 2772 memmove(&buf[k-1], &buf[k], nul - k); 2773 2774 /* Decrement */ 2775 k--; 2776 nul--; 2777 2778 /* Terminate */ 2779 buf[nul] = '\0'; 2780 2781 break; 2782 } 2783 2784 default: 2785 { 2786 bool atnull = (buf[k] == 0); 2787 2788 2789 if (!isprint((unsigned char)ch)) 2790 { 2791 bell("Illegal edit key!"); 2792 break; 2793 } 2794 2795 /* Clear the buffer if this is the first time round */ 2796 if (firsttime) 2797 { 2798 buf[0] = '\0'; 2799 k = 0; 2800 nul = 0; 2801 atnull = 1; 2802 } 2803 2804 if (atnull) 2805 { 2806 /* Make sure we have enough room for a new character */ 2807 if ((k + 1) >= len) break; 2808 } 2809 else 2810 { 2811 /* Make sure we have enough room to add a new character */ 2812 if ((nul + 1) >= len) break; 2813 2814 /* Move the rest of the buffer along to make room */ 2815 memmove(&buf[k+1], &buf[k], nul - k); 2816 } 2817 2818 /* Insert the character */ 2819 buf[k++] = ch; 2820 nul++; 2821 2822 /* Terminate */ 2823 buf[nul] = '\0'; 2824 2825 break; 2826 } 2827 } 2849 /* Let the keypress handler deal with the keypress */ 2850 done = keypress_h(buf, len, &k, &nul, ch, firsttime); 2828 2851 2829 2852 /* Update the entry */ … … 2839 2862 } 2840 2863 2864 /* 2865 * A "keypress" handling function for askfor_aux, that handles the special 2866 * case of '*' for a new random "name" and passes any other "keypress" 2867 * through to the default "editing" handler. 2868 */ 2869 bool get_name_keypress(char *buf, size_t buflen, size_t *curs, size_t *len, char keypress, bool firsttime) 2870 { 2871 bool result; 2872 2873 switch (keypress) 2874 { 2875 case '*': 2876 { 2877 *len = make_word(RANDNAME_TOLKIEN, 4, 8, buf, buflen); 2878 buf[0] = toupper((unsigned char) buf[0]); 2879 *curs = 0; 2880 result = FALSE; 2881 break; 2882 } 2883 2884 2885 default: 2886 { 2887 result = askfor_aux_keypress(buf, buflen, curs, len, keypress, firsttime); 2888 break; 2889 } 2890 } 2891 2892 return result; 2893 } 2894 2895 2896 /* 2897 * Gets a name for the character, reacting to name changes. 2898 * 2899 * What a horrible name for a global function. XXX XXX XXX 2900 */ 2901 void get_name(void) 2902 { 2903 bool res; 2904 char tmp[32]; 2905 2906 /* Paranoia XXX XXX XXX */ 2907 message_flush(); 2908 2909 /* Display prompt */ 2910 prt("Enter a name for your character (* for a random name): ", 0, 0); 2911 2912 /* Save the player name */ 2913 my_strcpy(tmp, op_ptr->full_name, sizeof(tmp)); 2914 2915 /* Ask the user for a string */ 2916 res = askfor_aux(tmp, sizeof(tmp), get_name_keypress); 2917 2918 /* Clear prompt */ 2919 prt("", 0, 0); 2920 2921 if (res) 2922 { 2923 /* Use the name */ 2924 my_strcpy(op_ptr->full_name, tmp, sizeof(op_ptr->full_name)); 2925 2926 /* Process the player name */ 2927 process_player_name(FALSE); 2928 } 2929 } 2930 2931 2841 2932 2842 2933 /* … … 2859 2950 2860 2951 /* Ask the user for a string */ 2861 res = askfor_aux(buf, len );2952 res = askfor_aux(buf, len, NULL); 2862 2953 2863 2954 /* Clear prompt */ … … 3134 3225 * Note that "p_ptr->command_new" may not work any more. XXX XXX XXX 3135 3226 */ 3136 void request_command( bool shopping)3227 void request_command(void) 3137 3228 { 3138 3229 int i; … … 3199 3290 /* Clear top line */ 3200 3291 prt("", 0, 0); 3292 3293 3294 /* Resize events XXX XXX */ 3295 if (ke.type == EVT_RESIZE) 3296 { 3297 p_ptr->command_cmd_ex = ke; 3298 p_ptr->command_new = ' '; 3299 } 3201 3300 3202 3301 … … 3365 3464 /* Repeat 99 times */ 3366 3465 p_ptr->command_arg = 99; 3367 }3368 }3369 3370 3371 /* Shopping */3372 if (shopping)3373 {3374 /* Hack -- Convert a few special keys */3375 switch (p_ptr->command_cmd)3376 {3377 /* Command "p" -> "purchase" (get) */3378 case 'p': p_ptr->command_cmd = 'g'; break;3379 3380 /* Command "m" -> "purchase" (get) */3381 case 'm': p_ptr->command_cmd = 'g'; break;3382 3383 /* Command "s" -> "sell" (drop) */3384 case 's': p_ptr->command_cmd = 'd'; break;3385 3466 } 3386 3467 } trunk/src/z-term.c
r98 r120 386 386 s->cv = f->cv; 387 387 388 /* Copy resize hook */389 s->resize_hook = f->resize_hook;390 391 388 /* Success */ 392 389 return (0); … … 2029 2026 2030 2027 /* 2031 * Set the resize hook for the current term.2032 */2033 errr Term_set_resize_hook(void (*hook)(void))2034 {2035 /* Ensure hook */2036 if (!hook) return (-1);2037 2038 /* Set hook */2039 Term->scr->resize_hook = hook;2040 2041 /* Success */2042 return (0);2043 }2044 2045 /*2046 2028 * Save the "requested" screen into the "memorized" screen 2047 2029 * … … 2068 2050 Term->mem = mem; 2069 2051 2070 /* Nuke the resize hook (safety) */2071 Term->scr->resize_hook = NULL;2072 2073 2052 /* Success */ 2074 2053 return (0); … … 2117 2096 Term->y1 = 0; 2118 2097 Term->y2 = h - 1; 2119 2120 /* Call the resize hook */2121 if (Term->scr->resize_hook && (w != Term->wid) && (h != Term->hgt))2122 Term->scr->resize_hook();2123 2098 2124 2099 /* Success */ … … 2145 2120 term_win *hold_tmp; 2146 2121 2122 event_type evt = { EVT_RESIZE, 0, 0, 0, 0 }; 2123 2147 2124 2148 2125 /* Resizing is forbidden */ … … 2297 2274 Term->y2 = h - 1; 2298 2275 2299 /* Call the resize hook */ 2300 if (Term->scr->resize_hook) 2301 { 2302 Term->scr->resize_hook(); 2303 } 2304 else 2305 { 2306 /* Push a resize event onto the stack */ 2307 event_type evt = { EVT_RESIZE, 0, 0, 0, 0 }; 2308 Term_event_push(&evt); 2309 } 2276 /* Push a resize event onto the stack */ 2277 Term_event_push(&evt); 2310 2278 2311 2279 /* Success */ trunk/src/z-term.h
r95 r120 55 55 56 56 term_win *next; 57 void (*resize_hook)(void);58 57 }; 59 58 … … 93 92 { 94 93 event_class type; 95 byte mousex, mousey;94 byte mousex, mousey; 96 95 char key; 97 short index;96 short index; 98 97 }; 99 98 … … 378 377 extern errr Term_inkey(event_type *ch, bool wait, bool take); 379 378 380 extern errr Term_set_resize_hook(void (*hook)(void));381 379 extern errr Term_save(void); 382 380 extern errr Term_load(void);
