Esempio n. 1
0
/*
 * Extract a direction (or zero) from a character
 */
int target_dir(struct keypress ch)
{
	int d = 0;


	/* Already a direction? */
	if (isdigit((unsigned char) ch.code)) {
		d = D2I(ch.code);
	} else if (isarrow(ch.code)) {
		switch (ch.code) {
		case ARROW_DOWN:
			d = 2;
			break;
		case ARROW_LEFT:
			d = 4;
			break;
		case ARROW_RIGHT:
			d = 6;
			break;
		case ARROW_UP:
			d = 8;
			break;
		}
	} else {
		int mode;
		const struct keypress *act;

		if (OPT(rogue_like_commands))
			mode = KEYMAP_MODE_ROGUE;
		else
			mode = KEYMAP_MODE_ORIG;

		/* XXX see if this key has a digit in the keymap we can use */
		act = keymap_find(mode, ch);
		if (act) {
			const struct keypress *cur;
			for (cur = act; cur->type == EVT_KBRD; cur++) {
				if (isdigit((unsigned char) cur->code))
					d = D2I(cur->code);
			}
		}
	}

	/* Paranoia */
	if (d == 5)
		d = 0;

	/* Return direction */
	return (d);
}
Esempio n. 2
0
/*
 * Extract a direction (or zero) from a character
 */
int target_dir(char ch)
{
    int d = 0;

    int mode;

    cptr act;

    cptr s;


    /* Already a direction? */
    if (isdigit((unsigned char) ch)) {
	d = D2I(ch);
    } else if (isarrow(ch)) {
	switch (ch) {
	case ARROW_DOWN:
	    d = 2;
	    break;
	case ARROW_LEFT:
	    d = 4;
	    break;
	case ARROW_RIGHT:
	    d = 6;
	    break;
	case ARROW_UP:
	    d = 8;
	    break;
	}
    } else {
	/* Roguelike */
	if (OPT(rogue_like_commands)) {
	    mode = KEYMAP_MODE_ROGUE;
	}

	/* Original */
	else {
	    mode = KEYMAP_MODE_ORIG;
	}

	/* Extract the action (if any) */
	act = keymap_act[mode][(byte) (ch)];

	/* Analyze */
	if (act) {
	    /* Convert to a direction */
	    for (s = act; *s; ++s) {
		/* Use any digits in keymap */
		if (isdigit((unsigned char) *s))
		    d = D2I(*s);
	    }
	}
    }

    /* Paranoia */
    if (d == 5)
	d = 0;

    /* Return direction */
    return (d);
}
Esempio n. 3
0
/*
 * Request a command from the user.
 *
 * Note that "caret" ("^") is treated specially, and is used to
 * allow manual input of control characters.  This can be used
 * on many machines to request repeated tunneling (Ctrl-H) and
 * on the Macintosh to request "Control-Caret".
 *
 * Note that "backslash" is treated specially, and is used to bypass any
 * keymap entry for the following character.  This is useful for macros.
 */
static ui_event_data textui_get_command(void)
{
	int mode = OPT(rogue_like_commands) ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG;

	char tmp[2] = { '\0', '\0' };

	ui_event_data ke = EVENT_EMPTY;

	cptr act = NULL;



	/* Get command */
	while (1)
	{
		/* Hack -- no flush needed */
		msg_flag = FALSE;

		/* Activate "command mode" */
		inkey_flag = TRUE;

		/* Get a command */
		ke = inkey_ex();


		/* Command Count */
		if (ke.key == '0')
		{
			int count = textui_get_count();

			if (count == -1 || !get_com_ex("Command: ", &ke))
				continue;
			else
				p_ptr->command_arg = count;
		}

		/* Allow "keymaps" to be bypassed */
		else if (ke.key == '\\')
		{
			/* Get a real command */
			(void)get_com("Command: ", &ke.key);

			/* Hack -- bypass keymaps */
			if (!inkey_next) inkey_next = "";
		}

		/* Allow "control chars" to be entered */
		else if (ke.key == '^')
		{
			/* Get a new command and controlify it */
			if (get_com("Control: ", &ke.key))
				ke.key = KTRL(ke.key);
		}

		/* Special case for the arrow keys */
		else if (isarrow(ke.key))
		{
			switch (ke.key)
			{
				case ARROW_DOWN:    ke.key = '2'; break;
				case ARROW_LEFT:    ke.key = '4'; break;
				case ARROW_RIGHT:   ke.key = '6'; break;
				case ARROW_UP:      ke.key = '8'; break;
			}
		}

		/* Erase the message line */
		prt("", 0, 0);


		if (ke.type == EVT_BUTTON)
		{
			/* Buttons are always specified in standard keyset */
			act = tmp;
			tmp[0] = ke.key;
		}
		else if (ke.type == EVT_KBRD)
		{
			/* Look up applicable keymap */
			act = keymap_act[mode][(byte)(ke.key)];
		}

		/* Apply keymap if not inside a keymap already */
		if (ke.key && act && !inkey_next)
		{
			/* Install the keymap */
			my_strcpy(request_command_buffer, act,
			          sizeof(request_command_buffer));

			/* Start using the buffer */
			inkey_next = request_command_buffer;

			/* Continue */
			continue;
		}

		/* Done */
		break;
	}

	return ke;
}