/** * Process a textui keypress. */ static bool textui_process_key(struct keypress kp, int count) { struct cmd_info *cmd; int mode = OPT(rogue_like_commands) ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG; /* XXXmacro this needs rewriting */ keycode_t c = kp.code; if (c == '\0' || c == ESCAPE || c == ' ' || c == '\a') return TRUE; if (c == KC_ENTER) { cmd = textui_action_menu_choose(); } else { if (c > UCHAR_MAX) return FALSE; cmd = converted_list[mode][c]; } if (!cmd) return FALSE; if (key_confirm_command(c) && (!cmd->prereq || cmd->prereq())) { if (cmd->hook) cmd->hook(); else if (cmd->cmd) cmd_insert_repeated(cmd->cmd, count); } return TRUE; }
/** * Parse and execute the current command * Give "Warning" on illegal commands. */ void textui_process_command(void) { int count = 0; bool done = TRUE; ui_event e = textui_get_command(&count); struct cmd_info *cmd = NULL; unsigned char key = '\0'; int mode = OPT(rogue_like_commands) ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG; switch (e.type) { case EVT_RESIZE: do_cmd_redraw(); return; case EVT_MOUSE: textui_process_click(e); return; case EVT_BUTTON: case EVT_KBRD: done = textui_process_key(e.key, &key, count); break; default: ; } /* Null command */ if (!key && done) return; if (key == KC_ENTER) { /* Use command menus */ cmd = textui_action_menu_choose(); } else { /* Command key */ cmd = converted_list[mode][key]; } if (cmd && done) { /* Confirm for worn equipment inscriptions, check command prereqs */ if (!key_confirm_command(key) || (cmd->prereq && !cmd->prereq())) cmd = NULL; /* Split on type of command */ if (cmd && cmd->hook) /* UI command */ cmd->hook(); else if (cmd && cmd->cmd) /* Game command */ cmdq_push_repeat(cmd->cmd, count); } else /* Error */ do_cmd_unknown(); }