Allow binding mouse buttons

Instead of hardcoding mouse button actions, allow the user to
bind mouse buttons to extended commands.  For example the new
defaults are:

BIND=mouse1:therecmdmenu
BIND=mouse2:clicklook

Currently a bit rudimentary; the defaults should be OK, but
documentation is bit lacking, and in-game binding and option
saving are missing.

Allowed commands to bind are "nothing", "therecmdmenu", "clicklook",
and "mouseaction". Clicklook replaces the "clicklook" boolean option,
and mouseaction does what mouse 1 button used to do - a context sensitive
action.
This commit is contained in:
Pasi Kallinen
2022-08-23 23:06:26 +03:00
parent 3a255e86c4
commit c42e73fd9c
11 changed files with 135 additions and 78 deletions

View File

@@ -506,6 +506,7 @@ struct cmd {
const char *dirchars; /* current movement/direction characters */
const char *alphadirchars; /* same as dirchars if !numpad */
const struct ext_func_tab *commands[256]; /* indexed by input character */
const struct ext_func_tab *mousebtn[NUM_MOUSE_BUTTONS];
char spkeys[NUM_NHKF];
char extcmd_char; /* key that starts an extended command ('#') */
};

View File

@@ -279,6 +279,7 @@ extern void rhack(char *);
extern int doextlist(void);
extern int extcmd_via_menu(void);
extern int enter_explore_mode(void);
extern boolean bind_mousebtn(int, const char *);
extern boolean bind_key(uchar, const char *);
extern void dokeylist(void);
extern coordxy xytod(coordxy, coordxy);
@@ -291,7 +292,7 @@ extern const char *directionname(int);
extern int isok(coordxy, coordxy);
extern int get_adjacent_loc(const char *, const char *, coordxy, coordxy,
coord *);
extern const char *click_to_cmd(coordxy, coordxy, int);
extern void click_to_cmd(coordxy, coordxy, int);
extern char get_count(const char *, char, long, cmdcount_nht *, unsigned);
#ifdef HANGUPHANDLING
extern void hangup(int);

View File

@@ -318,7 +318,6 @@ struct instance_flags {
#ifdef TTY_SOUND_ESCCODES
boolean vt_sounddata; /* output console codes for sound support in TTY*/
#endif
boolean clicklook; /* allow right-clicking for look */
boolean cmdassist; /* provide detailed assistance for some comnds */
boolean fireassist; /* autowield launcher when using fire-command */
boolean time_botl; /* context.botl for 'time' (moves) only */

View File

@@ -19,6 +19,7 @@
#define CMD_MOVE_PREFIXES (CMD_M_PREFIX | CMD_gGF_PREFIX)
#define PREFIXCMD 0x0200 /* prefix command, requires another one after it */
#define MOVEMENTCMD 0x0400 /* used to move hero/cursor */
#define MOUSECMD 0x0800 /* cmd allowed to be bound to mouse button */
/* flags for extcmds_match() */
#define ECM_NOFLAGS 0

View File

@@ -162,8 +162,6 @@ static int optfn_##a(int, int, boolean, char *, char *);
NHOPTB(checkpoint, Advanced, 0, opt_out, set_in_config,
Off, No, No, No, NoAlias, (boolean *) 0)
#endif
NHOPTB(clicklook, Advanced, 0, opt_in, set_in_game,
Off, Yes, No, No, NoAlias, &iflags.clicklook)
NHOPTB(cmdassist, Behavior, 0, opt_out, set_in_game,
On, Yes, No, No, NoAlias, &iflags.cmdassist)
NHOPTB(color, Map, 0, opt_in, set_in_game,

View File

@@ -135,6 +135,7 @@ typedef struct gi {
/* nh_poskey() modifier types */
#define CLICK_1 1
#define CLICK_2 2
#define NUM_MOUSE_BUTTONS 2
/* invalid winid */
#define WIN_ERR ((winid) -1)