Add toggle extended command

Allows the user to configure a key binding to toggle any boolean
option, for example:

BIND=':toggle(price_quotes)
BIND=v:toggle(autodig)

The option must be settable in-game.
This commit is contained in:
Pasi Kallinen
2026-03-21 11:52:36 +02:00
parent 62a50413d3
commit 63a78edcfa
7 changed files with 167 additions and 12 deletions

View File

@@ -371,6 +371,7 @@ extern void change_palette(void);
/* ### cmd.c ### */
extern void cmdbind_freeall(void);
extern int dotoggleoption(void);
extern void set_move_cmd(int, int);
extern int do_move_west(void);
extern int do_move_northwest(void);
@@ -2285,6 +2286,7 @@ extern char *get_option_value(const char *, boolean) NONNULLARG1;
extern int doset_simple(void);
extern int doset(void);
extern int dotogglepickup(void);
extern int toggle_bool_option(const char *);
extern void option_help(void);
extern void all_options_strbuf(strbuf_t *) NONNULLARG1;
extern void next_opt(winid, const char *) NONNULLARG2;

View File

@@ -22,6 +22,7 @@
#define MOUSECMD 0x0800 /* cmd allowed to be bound to mouse button */
#define CMD_INSANE 0x1000 /* suppress sanity check (for ^P and ^R) */
#define AUTOCOMP_ADJ 0x2000 /* user changed command autocompletion */
#define CMD_PARAM 0x4000 /* command requires a param from key bind */
/* flags for extcmds_match() */
#define ECM_NOFLAGS 0
@@ -33,6 +34,7 @@
struct Cmd_bind {
uchar key;
boolean userbind; /* added by user */
char *param;
const struct ext_func_tab *cmd;
struct Cmd_bind *next;
};