From f93b2732500d8d5a1b2236b0ae61d02fd9f61c22 Mon Sep 17 00:00:00 2001 From: mogami Date: Mon, 13 Oct 2003 01:39:48 +0000 Subject: [PATCH] =?utf8?q?=E8=87=AA=E5=8B=95=E6=8B=BE=E3=81=84=E3=82=A8?= =?utf8?q?=E3=83=87=E3=82=A3=E3=82=BF=E3=81=A7=E4=BD=BF=E3=81=A3=E3=81=A6?= =?utf8?q?=E3=81=84=E3=81=9F=E3=82=AB=E3=83=BC=E3=82=BD=E3=83=AB=E7=A7=BB?= =?utf8?q?=E5=8B=95=E3=82=AD=E3=83=BC=E3=82=92=E8=AA=AD=E3=81=BF=E5=8F=96?= =?utf8?q?=E3=82=8BHack=E3=82=92=E4=B8=80=E8=88=AC=E5=8C=96=E3=81=97?= =?utf8?q?=E3=81=A6=E3=80=81=20=E9=96=A2=E6=95=B0inkey=5Fspecial()?= =?utf8?q?=E3=81=AB=E3=81=BE=E3=81=A8=E3=82=81=E3=81=A6=E3=80=81=E9=80=9A?= =?utf8?q?=E5=B8=B8=E3=81=AE=E6=96=87=E5=AD=97=E5=88=97=E5=85=A5=E5=8A=9B?= =?utf8?q?=E3=81=A8=E7=94=9F=E3=81=84=E7=AB=8B=E3=81=A1=E5=85=A5=E5=8A=9B?= =?utf8?q?=E3=81=AB=E5=BF=9C=E7=94=A8=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/autopick.c | 318 +++++++++++++++++++++++++---------------------- src/birth.c | 26 ++-- src/defines.h | 18 +++ src/externs.h | 2 +- src/util.c | 384 +++++++++++++++++++++++++++++++++++++++++++++------------ src/variable.c | 1 - 6 files changed, 505 insertions(+), 244 deletions(-) diff --git a/src/autopick.c b/src/autopick.c index 478a38175..9ed9d6057 100644 --- a/src/autopick.c +++ b/src/autopick.c @@ -3098,10 +3098,11 @@ static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search static byte get_string_for_search(object_type **o_handle, cptr *search_strp) { int pos = 0; + byte color = TERM_YELLOW; char buf[MAX_NLEN+20]; + const size_t len = 80; #ifdef JP - int k_flag[MAX_NLEN+20]; char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): "; #else char prompt[] = "Search key(^I:inven ^L:destroyed): "; @@ -3114,47 +3115,76 @@ static byte get_string_for_search(object_type **o_handle, cptr *search_strp) /* Display prompt */ prt(prompt, 0, 0); - /* Display the default answer */ - Term_erase(col, 0, 255); - Term_putstr(col, 0, -1, TERM_YELLOW, buf); /* Process input */ - while (1) + while (TRUE) { bool back = FALSE; - int key; - size_t trig_len; + int skey; + + /* Display the string */ + Term_erase(col, 0, 255); + Term_putstr(col, 0, -1, color, buf); /* Place cursor */ Term_gotoxy(col + pos, 0); - /* Get a key */ - key = inkey(); + /* Get a special key code */ + skey = inkey_special(); - /* Count length of macro trigger which induced this key */ - trig_len = strlen(inkey_macro_trigger_string); + /* Analyze the key */ + switch (skey) + { + case SKEY_LEFT: + case KTRL('b'): + { + int i = 0; + + /* No effect at biggining of line */ + if (0 == pos) break; + + while (TRUE) + { + int next_pos = i + 1; - /* HACK -- ignore macro defined on ASCII keys */ #ifdef JP - if (trig_len == 1 && !iskanji(inkey_macro_trigger_string[0])) -#else - if (trig_len == 1) + if (iskanji(buf[next_pos])) next_pos++; #endif - { - /* Get original key */ - key = inkey_macro_trigger_string[0]; - /* Kill further macro expansion */ - flush(); + /* Is there the cursor at next position? */ + if (next_pos >= pos) break; + + /* Move to next */ + i = next_pos; + } + + /* Get previous position */ + pos = i; + + /* Now on insert mode */ + color = TERM_WHITE; + + break; } - /* Delete key */ - if (key == 0x7F) key = KTRL('d'); + case SKEY_RIGHT: + case KTRL('f'): + /* No effect at end of line */ + if ('\0' == buf[pos]) break; +#ifdef JP + /* Move right */ + if (iskanji(buf[pos])) pos += 2; + else pos++; +#else + pos++; +#endif + + /* Now on insert mode */ + color = TERM_WHITE; + + break; - /* Analyze the key */ - switch (key) - { case ESCAPE: return 0; @@ -3181,57 +3211,112 @@ static byte get_string_for_search(object_type **o_handle, cptr *search_strp) return 1; break; - case 0x7F: case '\010': + /* Backspace */ + + /* No effect at biggining of line */ + if (!pos) break; + + /* Go left 1 unit */ + pos--; + + /* Fall through to 'Delete key' */ + + case 0x7F: + case KTRL('d'): + /* Delete key */ + { + + int dst = pos; + + /* Position of next character */ + int src = pos + 1; + #ifdef JP - if (pos > 0) - { - pos--; - if (k_flag[pos]) pos--; - } -#else - if (pos > 0) pos--; + /* Next character is one more byte away */ + if (iskanji(src)) src++; #endif + + /* Move characters at src to dst */ + while ('\0' != (buf[dst++] = buf[src++])) + /* loop */; + break; + } default: + { + /* Insert a character */ + + char tmp[100]; + char c; + + /* Ignore special keys */ + if (skey & SKEY_MASK) break; + + /* Get a character code */ + c = (char)skey; + + if (color == TERM_YELLOW) + { + /* Overwrite default string */ + buf[0] = '\0'; + + /* Go to insert mode */ + color = TERM_WHITE; + } + + /* Save right part of string */ + strcpy(tmp, buf + pos); #ifdef JP - if (iskanji(key)) + if (iskanji(c)) { - int next; + char next; + /* Bypass macro processing */ inkey_base = TRUE; - next = inkey (); - if (pos + 1 < MAX_NLEN) + next = inkey(); + + if (pos + 1 < len) { - buf[pos++] = key; - buf[pos] = next; - k_flag[pos++] = 1; + buf[pos++] = c; + buf[pos++] = next; + } + else + { + bell(); } - else bell(); } - else if (pos < MAX_NLEN && isprint(key)) + else +#endif { - buf[pos] = key; - k_flag[pos++] = 0; - } - else bell(); +#ifdef SJIS + if (pos < len && + (isprint(c) || (0xa0 <= c && c <= 0xdf))) #else - if (pos < MAX_NLEN && isprint(key)) buf[pos++] = key; - else bell(); + if (pos < len && isprint(c)) #endif - break; - } + { + buf[pos++] = c; + } + else + { + bell(); + } + } - /* Terminate */ - buf[pos] = '\0'; + /* Terminate */ + buf[pos] = '\0'; - /* Update the entry */ - Term_erase(col, 0, 255); - Term_putstr(col, 0, -1, TERM_WHITE, buf); - } + /* Write back the left part of string */ + my_strcat(buf, tmp, len + 1); - /* Never reached */ + break; + } /* default: */ + + } + + } /* while (TRUE) */ } @@ -3665,6 +3750,8 @@ command_menu_type menu_data[] = {MN_CL_QUERY, 1, -1, EC_CL_QUERY}, {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP}, + {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR}, + {NULL, -1, -1, 0} }; @@ -5371,76 +5458,34 @@ static void insert_single_letter(text_body_type *tb, int key) /* - * Mega-Hack: - * Get macro trigger string directly and translate it to the command id. + * Check special key code and get a movement command id */ -static int analyze_move_key(text_body_type *tb) +static int analyze_move_key(text_body_type *tb, int skey) { - static const struct { - cptr keyname; - int com_id; - } move_key_list[] = { - {"Down]", EC_DOWN}, - {"Left]", EC_LEFT}, - {"Right]", EC_RIGHT}, - {"Up]", EC_UP}, - {"Page_Up]", EC_PGUP}, - {"Page_Down]", EC_PGDOWN}, - {"Home]", EC_TOP}, - {"End]", EC_BOTTOM}, - {"KP_Down]", EC_DOWN}, - {"KP_Left]", EC_LEFT}, - {"KP_Right]", EC_RIGHT}, - {"KP_Up]", EC_UP}, - {"KP_Page_Up]", EC_PGUP}, - {"KP_Page_Down]", EC_PGDOWN}, - {"KP_Home]", EC_TOP}, - {"KP_End]", EC_BOTTOM}, - {"KP_2]", EC_DOWN}, - {"KP_4]", EC_LEFT}, - {"KP_6]", EC_RIGHT}, - {"KP_8]", EC_UP}, - {"KP_9]", EC_PGUP}, - {"KP_3]", EC_PGDOWN}, - {"KP_7]", EC_TOP}, - {"KP_1]", EC_BOTTOM}, - {NULL, 0}, - }; - - static const char shiftstr[] = "shift-"; - bool shifted = FALSE; - char buf[1024]; - cptr str = buf; - int com_id = 0; - int i; - - /* Get ascii form */ - ascii_to_text(buf, inkey_macro_trigger_string); + int com_id; - /* Skip "\[" */ - str += 2; + /* Not a special key */ + if (!(skey & SKEY_MASK)) return 0; - if (prefix(str, shiftstr)) + /* Convert from a special key code to an editor command */ + switch(skey & ~SKEY_MOD_MASK) { - str += sizeof(shiftstr) - 1; - shifted = TRUE; - } + case SKEY_DOWN: com_id = EC_DOWN; break; + case SKEY_LEFT: com_id = EC_LEFT; break; + case SKEY_RIGHT: com_id = EC_RIGHT; break; + case SKEY_UP: com_id = EC_UP; break; + case SKEY_PGUP: com_id = EC_PGUP; break; + case SKEY_PGDOWN: com_id = EC_PGDOWN; break; + case SKEY_TOP: com_id = EC_TOP; break; + case SKEY_BOTTOM: com_id = EC_BOTTOM; break; - for (i = 0; move_key_list[i].keyname; i++) - { - if (streq(str, move_key_list[i].keyname)) - { - com_id = move_key_list[i].com_id; - break; - } + default: + /* Not a special movement key */ + return 0; } - if (!com_id) return 0; - - /* Kill further macro expansion */ - flush(); - - if (!shifted) + /* Without shift modifier */ + if (!(skey & SKEY_MOD_SHIFT)) { /* * Un-shifted cursor keys cancells @@ -5454,6 +5499,8 @@ static int analyze_move_key(text_body_type *tb) tb->dirty_flags |= DIRTY_ALL; } } + + /* With shift modifier */ else { /* Start selection by shift + cursor keys */ @@ -5561,7 +5608,6 @@ void do_cmd_edit_autopick(void) while (!quit) { int com_id = 0; - size_t trig_len; /* Draw_everythig */ draw_text_editor(tb); @@ -5598,35 +5644,13 @@ void do_cmd_edit_autopick(void) tb->old_hgt = tb->hgt; /* Get a command */ - key = inkey(); - - /* Count length of macro trigger which induced this key */ - trig_len = strlen(inkey_macro_trigger_string); - - /* HACK -- ignore macro defined on ASCII keys */ -#ifdef JP - if (trig_len == 1 && !iskanji(inkey_macro_trigger_string[0])) -#else - if (trig_len == 1) -#endif - { - /* Get original key */ - key = inkey_macro_trigger_string[0]; - - /* Kill further macro expansion */ - flush(); - } - - /* Delete key */ - if (key == 0x7F) key = KTRL('d'); - - - /* Movement special keys */ - if (trig_len > 1) com_id = analyze_move_key(tb); + key = inkey_special(); - if (com_id) + /* Special keys */ + if (key & SKEY_MASK) { - /* Already done */ + /* Get a movement command */ + com_id = analyze_move_key(tb, key); } /* Open the menu */ diff --git a/src/birth.c b/src/birth.c index ac77a924e..4c840ac45 100644 --- a/src/birth.c +++ b/src/birth.c @@ -5351,7 +5351,6 @@ static bool do_cmd_histpref(void) static void edit_history(void) { char old_history[4][60]; - char c; int y = 0, x = 0; int i, j; @@ -5379,6 +5378,9 @@ static void edit_history(void) while (TRUE) { + int skey; + char c; + for (i = 0; i < 4; i++) { put_str(p_ptr->history[i], i + 12, 10); @@ -5393,18 +5395,14 @@ static void edit_history(void) /* Place cursor just after cost of current stat */ Term_gotoxy(x + 10, y + 12); - c = inkey(); + /* Get special key code */ + skey = inkey_special(); - /* Cursor key macroes to direction command */ - if (strlen(inkey_macro_trigger_string) > 1) - { - if (c == '8') c = KTRL('P'); - else if (c == '2') c = KTRL('N'); - else if (c == '6') c = KTRL('F'); - else if (c == '4') c = KTRL('B'); - } + /* Get a character code */ + if (!(skey & SKEY_MASK)) c = (char)skey; + else c = 0; - if (c == KTRL('P')) + if (skey == SKEY_UP) { y--; if (y < 0) y = 3; @@ -5412,7 +5410,7 @@ static void edit_history(void) if ((x > 0) && (iskanji2(p_ptr->history[y], x-1))) x--; #endif } - else if (c == KTRL('N')) + else if (skey == SKEY_DOWN) { y++; if (y > 3) y = 0; @@ -5420,7 +5418,7 @@ static void edit_history(void) if ((x > 0) && (iskanji2(p_ptr->history[y], x-1))) x--; #endif } - else if (c == KTRL('F')) + else if (skey == SKEY_RIGHT) { #ifdef JP if (iskanji2(p_ptr->history[y], x)) x++; @@ -5432,7 +5430,7 @@ static void edit_history(void) if (y < 3) y++; } } - else if (c == KTRL('B')) + else if (skey == SKEY_LEFT) { x--; if (x < 0) diff --git a/src/defines.h b/src/defines.h index a4eefb0d3..e65a1520f 100644 --- a/src/defines.h +++ b/src/defines.h @@ -5344,3 +5344,21 @@ extern int PlayerUID; #define SCREEN_BUF_SIZE 65536 /* max screen dump buffer size */ + +/* + * Special key code used for inkey_special() + */ +#define SKEY_MOD_MASK 0x0f00 +#define SKEY_MOD_SHIFT 0x0100 +#define SKEY_MOD_CONTROL 0x0200 + +#define SKEY_MASK 0xf000 +#define SKEY_DOWN 0xf001 +#define SKEY_LEFT 0xf002 +#define SKEY_RIGHT 0xf003 +#define SKEY_UP 0xf004 +#define SKEY_PGUP 0xf005 +#define SKEY_PGDOWN 0xf006 +#define SKEY_TOP 0xf007 +#define SKEY_BOTTOM 0xf008 + diff --git a/src/externs.h b/src/externs.h index 459c4db8d..d7c49d3d7 100644 --- a/src/externs.h +++ b/src/externs.h @@ -179,7 +179,6 @@ extern bool inkey_base; extern bool inkey_xtra; extern bool inkey_scan; extern bool inkey_flag; -extern char inkey_macro_trigger_string[1024]; extern s16b coin_type; extern bool opening_chest; extern bool shimmer_monsters; @@ -1228,6 +1227,7 @@ extern void build_gamma_table(int gamma); extern size_t my_strcpy(char *buf, const char *src, size_t bufsize); extern size_t my_strcat(char *buf, const char *src, size_t bufsize); +extern int inkey_special(void); /* xtra1.c */ diff --git a/src/util.c b/src/util.c index 91f2c3593..67db09f1d 100644 --- a/src/util.c +++ b/src/util.c @@ -13,10 +13,11 @@ #include "angband.h" - - static int num_more = 0; +/* Save macro trigger string for use in inkey_special() */ +static char inkey_macro_trigger_string[1024]; + #if 0 #ifndef HAS_STRICMP @@ -3150,21 +3151,12 @@ void clear_from(int row) bool askfor_aux(char *buf, int len) { int y, x; + int pos = 0; + byte color = TERM_YELLOW; - int i = 0; - - int k = 0; - - bool done = FALSE; - - -#ifdef JP - int k_flag[128]; -#endif - /* Locate the cursor */ + /* Locate the cursor position */ Term_locate(&x, &y); - /* Paranoia -- check len */ if (len < 1) len = 1; @@ -3174,107 +3166,194 @@ bool askfor_aux(char *buf, int len) /* Restrict the length */ if (x + len > 80) len = 80 - x; - /* Paranoia -- Clip the default entry */ buf[len] = '\0'; - /* Display the default answer */ - Term_erase(x, y, len); - Term_putstr(x, y, -1, TERM_YELLOW, buf); - - /* Process input */ - while (!done) + while (TRUE) { + int skey; + + /* Display the string */ + Term_erase(x, y, len); + Term_putstr(x, y, -1, color, buf); + /* Place cursor */ - Term_gotoxy(x + k, y); + Term_gotoxy(x + pos, y); - /* Get a key */ - i = inkey(); + /* Get a special key code */ + skey = inkey_special(); /* Analyze the key */ - switch (i) + switch (skey) { - case ESCAPE: - k = 0; - done = TRUE; + case SKEY_LEFT: + case KTRL('b'): + { + int i = 0; + + /* No effect at biggining of line */ + if (0 == pos) break; + + while (TRUE) + { + int next_pos = i + 1; + +#ifdef JP + if (iskanji(buf[next_pos])) next_pos++; +#endif + + /* Is there the cursor at next position? */ + if (next_pos >= pos) break; + + /* Move to next */ + i = next_pos; + } + + /* Get previous position */ + pos = i; + + /* Now on insert mode */ + color = TERM_WHITE; + break; + } + + case SKEY_RIGHT: + case KTRL('f'): + /* No effect at end of line */ + if ('\0' == buf[pos]) break; + +#ifdef JP + /* Move right */ + if (iskanji(buf[pos])) pos += 2; + else pos++; +#else + pos++; +#endif + + /* Now on insert mode */ + color = TERM_WHITE; + + break; + + case ESCAPE: + /* Cancel input */ + buf[0] = '\0'; + return FALSE; case '\n': case '\r': - k = strlen(buf); - done = TRUE; - break; + /* Success */ + return TRUE; - case 0x7F: case '\010': + /* Backspace */ + + /* No effect at biggining of line */ + if (!pos) break; + + /* Go left 1 unit */ + pos--; + + /* Fall through to 'Delete key' */ + + case 0x7F: + case KTRL('d'): + /* Delete key */ + { + + int dst = pos; + + /* Position of next character */ + int src = pos + 1; + #ifdef JP - if (k > 0) - { - k--; - if (k_flag[k] != 0) - k--; - } -#else - if (k > 0) k--; + /* Next character is one more byte away */ + if (iskanji(src)) src++; #endif + /* Move characters at src to dst */ + while ('\0' != (buf[dst++] = buf[src++])) + /* loop */; + break; + } default: + { + /* Insert a character */ + + char tmp[100]; + char c; + + /* Ignore special keys */ + if (skey & SKEY_MASK) break; + + /* Get a character code */ + c = (char)skey; + + if (color == TERM_YELLOW) + { + /* Overwrite default string */ + buf[0] = '\0'; + + /* Go to insert mode */ + color = TERM_WHITE; + } + + /* Save right part of string */ + strcpy(tmp, buf + pos); #ifdef JP - { /* ÊÒ»³¤µ¤óºîÀ® */ - int next; - - if (iskanji (i)) { - inkey_base = TRUE; - next = inkey (); - if (k+1 < len) { - buf[k++] = i; - buf[k] = next; - k_flag[k++] = 1; - } else - bell(); - } else { -#ifdef SJIS - if(k