Mercurial > hg > early-roguelike
diff urogue/options.c @ 261:ac42afd962e4
UltraRogue: restrict changing name and save file.
When the -n option is in use, player name and save file location cannot
be changed. The score file is also restricted.
author | John "Elwin" Edwards |
---|---|
date | Sun, 12 Feb 2017 20:16:57 -0500 |
parents | c495a4f288c6 |
children | 2b452dbf0138 |
line wrap: on
line diff
--- a/urogue/options.c Thu Feb 09 20:13:25 2017 -0500 +++ b/urogue/options.c Sun Feb 12 20:16:57 2017 -0500 @@ -23,6 +23,8 @@ #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) +int get_restr(opt_arg *opt, WINDOW *win); + /* description of an option and what to do with it */ static OPTION optlist[] = { @@ -30,10 +32,10 @@ {"inven","Style of inventories (inven): ", &inv_type, put_inv, get_inv}, {"askme","Ask me about unidentified things (askme): ",&askme,put_bool,get_bool}, {"doorstop","Stop running when adjacent (doorstop): ",&doorstop,put_bool,get_bool}, -{"name", "Name (name): ", &whoami, put_str, get_str}, +{"name", "Name (name): ", &whoami, put_str, get_restr}, {"fruit", "Fruit (fruit): ", &fruit, put_str, get_str}, -{"file", "Save file (file): ", &file_name, put_str, get_str}, -{"score", "Score file (score): ", &score_file, put_str, get_str}, +{"file", "Save file (file): ", &file_name, put_str, get_restr}, +{"score", "Score file (score): ", &score_file, put_str, get_restr}, {"class", "Character class (class): ",&char_type, put_abil, get_abil} }; @@ -311,6 +313,7 @@ /* Look it up and deal with it */ for (op = optlist; op < &optlist[NUM_OPTS]; op++) + { if (EQSTR(str, op->o_name, len)) { if (op->o_putfunc == put_bool) @@ -334,6 +337,13 @@ strncpy(start, str, sp - str); + /* Some options can't be changed. */ + if (use_savedir && + (op->o_opt.str == whoami || + op->o_opt.str == file_name || + op->o_opt.str == score_file)) + break; + /* Put the value into the option field */ if (op->o_putfunc != put_abil && @@ -394,6 +404,7 @@ *op->o_opt.iarg = FALSE; break; } + } /* skip to start of next option name */ @@ -517,3 +528,56 @@ return(NORM); } + +/* + * get_restr() + * + * Gets strings that cannot be changed when use_savedir is set. + * get_abil() can't be repurposed to do this without ugliness. + * + */ +int +get_restr(opt_arg *opt, WINDOW *win) +{ + int oy, ox, ny, nx; + int keep_up; + + keep_up = TRUE; + getyx(win, oy, ox); + put_str(opt, win); + + if (!use_savedir) + return get_str(opt, win); + + getyx(win, ny, nx); + while(keep_up) + { + wmove(win, oy, ox); + wrefresh(win); + + switch(readcharw(win)) + { + case '\n': + case '\r': + keep_up = FALSE; + break; + + case '\033': + case '\007': + return(QUIT); + + case '-': + return(MINUS); + + default: + mvwaddstr(win, ny, nx + 5, "(no change allowed)"); + } + } + + wmove(win, ny, nx + 5); + wclrtoeol(win); + wmove(win, ny, nx); + waddch(win, '\n'); + + return(NORM); +}