int nds_key_config_init() { u16 chord_keys_config; u16 cmd_key_config; char *direction_keys = nds_get_direction_keys(); if (nds_load_key_config() < 0) { char tmp[INPUT_BUFFER_SIZE]; NULLFREE(keymap); numkeys = 0; chord_keys = KEY_R; tmp[1] = '\0'; nds_add_keymap_entry(KEY_A, ","); nds_add_keymap_entry(KEY_B, "s"); nds_add_keymap_entry(KEY_X, "o"); nds_add_keymap_entry(KEY_Y, "\x4"); tmp[0] = direction_keys[DIR_UP]; nds_add_keymap_entry(KEY_UP, tmp); tmp[0] = direction_keys[DIR_DOWN]; nds_add_keymap_entry(KEY_DOWN, tmp); tmp[0] = direction_keys[DIR_LEFT]; nds_add_keymap_entry(KEY_LEFT, tmp); tmp[0] = direction_keys[DIR_RIGHT]; nds_add_keymap_entry(KEY_RIGHT, tmp); nds_add_keymap_entry(KEY_RIGHT | KEY_R, "\xFE"); nds_add_keymap_entry(KEY_LEFT | KEY_R, "\xFD"); nds_add_keymap_entry(KEY_UP | KEY_R, "\xFC"); nds_add_keymap_entry(KEY_DOWN | KEY_R, "\xFB"); } /* * If the configured chordkey set doesn't match what we read from file, or * set as the default, then we use the new chordkey, and blank the key * config... the user has to rebind. */ if ((chord_keys_config = nds_key_string_to_mask(iflags.chordkeys)) != chord_keys) { NULLFREE(keymap); numkeys = 0; chord_keys = chord_keys_config; } if (nds_count_bits(cmd_key_config = nds_key_string_to_mask(iflags.cmdkey)) == 1) { cmd_key = cmd_key_config; } else { DEBUG_PRINT("Invalid command key: %s\n", iflags.cmdkey); return -1; } return 0; }
/* * Generic yes/no function. 'def' is the default (returned by space or * return; 'esc' returns 'q', or 'n', or the default, depending on * what's in the string. The 'query' string is printed before the user * is asked about the string. * If resp is NULL, any single character is accepted and returned. * If not-NULL, only characters in it are allowed (exceptions: the * quitchars are always allowed, and if it contains '#' then digits * are allowed); if it includes an <esc>, anything beyond that won't * be shown in the prompt to the user but will be acceptable as input. */ char nds_yn_function(const char *ques, const char *cstr, CHAR_P def) { char buffer[INPUT_BUFFER_SIZE]; char *choices; ANY_P header_id; ANY_P *ids; winid win; menu_item *sel = NULL; int ret; int yn = 0; int ynaq = 0; char *direction_keys = nds_get_direction_keys(); if ((strstr(ques, "In what direction") != NULL) || (strstr(ques, "in what direction") != NULL)) { /* * We're going to use nh_poskey to get a command from the user. However, * we must handle clicks specially. Unlike normal movement, you can't * just click anywhere to pick a direction. Instead, the user will be * expected to click in one of the adjacent squares around the player, * and the click will then be translated into a movement character. */ while (1) { int x, y, mod; int sym; nds_draw_prompt("Tap an adjacent square or press a direction key."); nds_flush(0); sym = nds_get_input(&x, &y, &mod); nds_clear_prompt(); if (mod == CLICK_1) { if ((x == u.ux - 1) && (y == u.uy - 1)) { return direction_keys[DIR_UP_LEFT]; } else if ((x == u.ux) && (y == u.uy - 1)) { return direction_keys[DIR_UP]; } else if ((x == u.ux + 1) && (y == u.uy - 1)) { return direction_keys[DIR_UP_RIGHT]; } else if ((x == u.ux - 1) && (y == u.uy)) { return direction_keys[DIR_LEFT]; } else if ((x == u.ux) && (y == u.uy)) { return direction_keys[DIR_WAIT]; } else if ((x == u.ux + 1) && (y == u.uy)) { return direction_keys[DIR_RIGHT]; } else if ((x == u.ux - 1) && (y == u.uy + 1)) { return direction_keys[DIR_DOWN_LEFT]; } else if ((x == u.ux) && (y == u.uy + 1)) { return direction_keys[DIR_DOWN]; } else if ((x == u.ux + 1) && (y == u.uy + 1)) { return direction_keys[DIR_DOWN_RIGHT]; } } else if (mod == CLICK_2) { if ((x == u.ux) && (y == u.uy)) { return '>'; } } else { return sym; } } } else if (! iflags.cmdwindow) { return nds_prompt_char(ques, cstr, 0); } else if (strstr(ques, "Adjust letter to what") != NULL) { return nds_prompt_char(ques, cstr, 0); } else if (strstr(ques, "What command?") != NULL) { nds_cmd_t cmd; nds_draw_prompt("Select a command."); nds_flush(0); cmd = nds_cmd_loop(CMDLOOP_WHATDOES); nds_clear_prompt(); return cmd.f_char; } else if (strstr(ques, "What do you look for?") != NULL) { return nds_prompt_char(ques, cstr, 0); } else if (strstr(ques, "adjust?") != NULL) { cstr = ynchars; } if ((index(ques, '[') == NULL) && (cstr == NULL)) { nds_draw_prompt(ques); return '*'; } win = create_nhwindow(NHW_MENU); start_menu(win); if ((cstr != NULL) && ((strcasecmp(cstr, ynchars) == 0) || (strcasecmp(cstr, ynqchars) == 0) || ((ynaq = strcasecmp(cstr, ynaqchars)) == 0))) { ids = (ANY_P *)malloc(sizeof(ANY_P) * 2); yn = 1; ids[0].a_int = 'y'; ids[1].a_int = 'n'; add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Yes", 0); add_menu(win, NO_GLYPH, &(ids[1]), 0, 0, 0, "No", 0); if (ynaq) { ids[2].a_int = 'a'; add_menu(win, NO_GLYPH, &(ids[2]), 0, 0, 0, "All", 0); } } else if ((cstr != NULL) && (strcasecmp(cstr, "rl") == 0)) { ids = (ANY_P *)malloc(sizeof(ANY_P) * 2); ids[0].a_int = 'r'; ids[1].a_int = 'l'; add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Right Hand", 0); add_menu(win, NO_GLYPH, &(ids[1]), 0, 0, 0, "Left Hand", 0); } else { int i; char curclass = -1; choices = _nds_parse_choices(ques); ids = (ANY_P *)malloc(sizeof(ANY_P) * strlen(choices)); header_id.a_int = 0; for (i = 0; i < strlen(choices); i++) { ids[i].a_int = choices[i]; if (choices[i] == ' ') { add_menu(win, NO_GLYPH, &(header_id), 0, 0, 0, "Other", 0); } else if (choices[i] == '*') { add_menu(win, NO_GLYPH, &(ids[i]), 0, 0, 0, "Something from your inventory", 0); } else if ((choices[i] == '-') || (choices[i] == '.')) { add_menu(win, NO_GLYPH, &(ids[i]), 0, 0, 0, "Nothing/your finger", 0); } else if (choices[i] == '?') { continue; } else { int oclass; char oname[BUFSZ]; if (choices[i] == '$') { oclass = COIN_CLASS; sprintf(oname, "%ld gold piece%s", u.ugold, plur(u.ugold)); } else { struct obj *otmp = obj_for_let(choices[i]); oclass = otmp->oclass; strcpy(oname, doname(otmp)); } if (oclass != curclass) { add_menu(win, NO_GLYPH, &(header_id), 0, 0, 0, let_to_name(oclass, FALSE), 0); curclass = oclass; } add_menu(win, NO_GLYPH, &(ids[i]), 0, 0, 0, oname, 0); } } } end_menu(win, ques); int mode = ((cstr == NULL) || (index(cstr, '#') != NULL)) ? PICK_ONE_TYPE : PICK_ONE; int cnt = select_menu(win, mode, &sel); if (cnt <= 0) { ret = yn ? 'n' : '\033'; } else if ((mode == PICK_ONE) || (sel->count < 0)) { ret = sel->item.a_int; } else if (mode == PICK_ONE_TYPE) { sprintf(buffer, "%d%c", sel->count, sel->item.a_int); nds_input_buffer_append(buffer + 1); ret = *buffer; } if (sel != NULL) { free(sel); } free(ids); destroy_nhwindow(win); return ret; }
nds_cmd_t nds_get_direction() { winid win; menu_item *sel; ANY_P ids[25]; nds_cmd_t cmd; int i, j, k; int res; char tmp[2]; char *direction_keys = nds_get_direction_keys(); win = create_nhwindow(NHW_MENU); start_menu(win); ids[0].a_int = 0; for (i = 0, j = 1; i < 3; i++) { switch (i) { case 0: add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Walk", 0); break; case 1: add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Run", 0); break; case 2: add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Fight", 0); break; } for (k = 0; k < 8; j++, k++) { tmp[0] = direction_keys[k]; tmp[1] = '\0'; ids[j].a_int = j; add_menu(win, NO_GLYPH, &(ids[j]), 0, 0, 0, nds_command_to_string(tmp), 0); } } end_menu(win, "What Type of Movement?"); res = select_menu(win, PICK_ONE, &sel); destroy_nhwindow(win); if (res <= 0) { cmd.f_char = -1; cmd.name = NULL; } else if (sel->item.a_int < 9) { tmp[0] = direction_keys[sel->item.a_int - 1]; tmp[1] = '\0'; cmd.f_char = direction_keys[sel->item.a_int - 1]; cmd.name = nds_command_to_string(tmp); } else if (sel->item.a_int < 17) { nds_input_buffer_push(direction_keys[sel->item.a_int - 9]); cmd.f_char = 'g'; cmd.name = nds_command_to_string(nds_input_buffer_shiftall()); } else { nds_input_buffer_push(direction_keys[sel->item.a_int - 17]); cmd.f_char = 'F'; cmd.name = nds_command_to_string(nds_input_buffer_shiftall()); } NULLFREE(sel); return cmd; }
char *nds_command_to_string(char *command) { int i; char *direction_keys = nds_get_direction_keys(); nds_cmd_t *cmdlist = nds_get_cmdlist(); if (strlen(command) != 1) { return command; } switch (*command) { case CMD_CONFIG: return "Key Config"; case CMD_PAN_RIGHT: return "Pan R"; case CMD_PAN_LEFT: return "Pan L"; case CMD_PAN_UP: return "Pan U"; case CMD_PAN_DOWN: return "Pan D"; case CMD_SHOW_KEYS: return "Show Keys"; } for (i = 0; i < NUMDIRS; i++) { if (direction_keys[i] == *command) { switch (i) { case DIR_UP_LEFT: return "Up-Left"; case DIR_UP: return "Up"; case DIR_UP_RIGHT: return "Up-Right"; case DIR_LEFT: return "Left"; case DIR_WAIT: return "Wait"; case DIR_RIGHT: return "Right"; case DIR_DOWN_LEFT: return "Down-Left"; case DIR_DOWN: return "Down"; case DIR_DOWN_RIGHT: return "Down-Right"; } } } for (i = 0; cmdlist[i].f_char; i++) { if (cmdlist[i].f_char == *command) { return cmdlist[i].name; } } return ""; }