errr finish_parse_prefs(struct parser * p) { struct prefs_data *d = parser_priv(p); int i; /* Update sub-windows based on the newly read-in prefs. * * The op_ptr->window_flag[] array cannot be updated directly during * parsing since the changes between the existing flags and the new * are used to set/unset the event handlers that update the windows. * * Build a complete set to pass to subwindows_set_flags() by loading * any that weren't read in by the parser from the existing set. */ for (i = 0; i < ANGBAND_TERM_MAX; i++) { if (!d->loaded_window_flag[i]) d->window_flags[i] = op_ptr->window_flag[i]; } subwindows_set_flags(d->window_flags, ANGBAND_TERM_MAX); return PARSE_ERROR_NONE; }
/* * Read options * * Note that the normal options are stored as a set of 256 bit flags, * plus a set of 256 bit masks to indicate which bit flags were defined * at the time the savefile was created. This will allow new options * to be added, and old options to be removed, at any time, without * hurting old savefiles. * * The window options are stored in the same way, but note that each * window gets 32 options, and their order is fixed by certain defines. */ static int rd_options(void) { int i, n; byte b; u16b tmp16u; u32b flag[8]; u32b mask[8]; u32b window_flag[REPOSBAND_TERM_MAX]; u32b window_mask[REPOSBAND_TERM_MAX]; /*** Oops ***/ /* Ignore old options */ strip_bytes(16); /*** Special info */ /* Read "delay_factor" */ rd_byte(&b); op_ptr->delay_factor = b; /* Read "hitpoint_warn" */ rd_byte(&b); op_ptr->hitpoint_warn = b; /* Read lazy movement delay */ rd_u16b(&tmp16u); lazymove_delay = (tmp16u < 1000) ? tmp16u : 0; /*** Normal Options ***/ /* Read the option flags */ for (n = 0; n < 8; n++) rd_u32b(&flag[n]); /* Read the option masks */ for (n = 0; n < 8; n++) rd_u32b(&mask[n]); /* Analyze the options */ for (i = 0; i < OPT_MAX; i++) { int os = i / 32; int ob = i % 32; /* Process saved entries */ if (mask[os] & (1L << ob)) { /* Set flag */ if (flag[os] & (1L << ob)) op_ptr->opt[i] = TRUE; /* Clear flag */ else op_ptr->opt[i] = FALSE; } } /*** Window Options ***/ /* Read the window flags */ for (n = 0; n < REPOSBAND_TERM_MAX; n++) { rd_u32b(&window_flag[n]); } /* Read the window masks */ for (n = 0; n < REPOSBAND_TERM_MAX; n++) { rd_u32b(&window_mask[n]); } /* Analyze the options */ for (n = 0; n < REPOSBAND_TERM_MAX; n++) { /* Analyze the options */ for (i = 0; i < 32; i++) { /* Process valid flags */ if (window_flag_desc[i]) { /* Blank invalid flags */ if (!(window_mask[n] & (1L << i))) { window_flag[n] &= ~(1L << i); } } } } /* Set up the subwindows */ subwindows_set_flags(window_flag, REPOSBAND_TERM_MAX); return 0; }
/** * Modify the "window" options */ static void do_cmd_options_win(const char *name, int row) { int i, j, d; int y = 0; int x = 0; ui_event ke; u32b new_flags[ANGBAND_TERM_MAX]; /* Set new flags to the old values */ for (j = 0; j < ANGBAND_TERM_MAX; j++) new_flags[j] = window_flag[j]; /* Clear screen */ screen_save(); clear_from(0); /* Interact */ while (1) { /* Prompt */ prt("Window flags (<dir> to move, 't'/Enter to toggle, or ESC)", 0, 0); /* Display the windows */ for (j = 0; j < ANGBAND_TERM_MAX; j++) { byte a = COLOUR_WHITE; const char *s = angband_term_name[j]; /* Use color */ if (j == x) a = COLOUR_L_BLUE; /* Window name, staggered, centered */ Term_putstr(35 + j * 5 - strlen(s) / 2, 2 + j % 2, -1, a, s); } /* Display the options */ for (i = 0; i < PW_MAX_FLAGS; i++) { byte a = COLOUR_WHITE; const char *str = window_flag_desc[i]; /* Use color */ if (i == y) a = COLOUR_L_BLUE; /* Unused option */ if (!str) str = "(Unused option)"; /* Flag name */ Term_putstr(0, i + 5, -1, a, str); /* Display the windows */ for (j = 0; j < ANGBAND_TERM_MAX; j++) { char c = '.'; a = COLOUR_WHITE; /* Use color */ if ((i == y) && (j == x)) a = COLOUR_L_BLUE; /* Active flag */ if (new_flags[j] & (1L << i)) c = 'X'; /* Flag value */ Term_putch(35 + j * 5, i + 5, a, c); } } /* Place Cursor */ Term_gotoxy(35 + x * 5, y + 5); /* Get key */ ke = inkey_ex(); /* Mouse or keyboard interaction */ if (ke.type == EVT_MOUSE) { int choicey = ke.mouse.y - 5; int choicex = (ke.mouse.x - 35)/5; if (ke.mouse.button == 2) break; if ((choicey >= 0) && (choicey < PW_MAX_FLAGS) && (choicex > 0) && (choicex < ANGBAND_TERM_MAX) && !(ke.mouse.x % 5)) { if ((choicey == y) && (choicex == x)) { /* Toggle flag (off) */ if (new_flags[x] & (1L << y)) new_flags[x] &= ~(1L << y); /* Toggle flag (on) */ else new_flags[x] |= (1L << y); } else { y = choicey; x = (ke.mouse.x - 35)/5; } } } else if (ke.type == EVT_KBRD) { if (ke.key.code == ESCAPE || ke.key.code == 'q') break; /* Toggle */ else if (ke.key.code == '5' || ke.key.code == 't' || ke.key.code == KC_ENTER) { /* Hack -- ignore the main window */ if (x == 0) bell("Cannot set main window flags!"); /* Toggle flag (off) */ else if (new_flags[x] & (1L << y)) new_flags[x] &= ~(1L << y); /* Toggle flag (on) */ else new_flags[x] |= (1L << y); /* Continue */ continue; } /* Extract direction */ d = target_dir(ke.key); /* Move */ if (d != 0) { x = (x + ddx[d] + 8) % ANGBAND_TERM_MAX; y = (y + ddy[d] + 16) % PW_MAX_FLAGS; } } } /* Notice changes */ subwindows_set_flags(new_flags, ANGBAND_TERM_MAX); screen_load(); }
/* * Read options * * Note that the normal options are stored as a set of 256 bit flags, * plus a set of 256 bit masks to indicate which bit flags were defined * at the time the savefile was created. This will allow new options * to be added, and old options to be removed, at any time, without * hurting old savefiles. * * The window options are stored in the same way, but note that each * window gets 32 options, and their order is fixed by certain defines. */ static void rd_options(void) { int i, n; byte b; u16b tmp16u; u32b flag[8]; u32b mask[8]; u32b window_flag[ANGBAND_TERM_MAX]; u32b window_mask[ANGBAND_TERM_MAX]; /*** Oops ***/ /* Ignore old options */ strip_bytes(16); /*** Special info */ /* Read "delay_factor" */ rd_byte(&b); op_ptr->delay_factor = b; /* Read "hitpoint_warn" */ rd_byte(&b); op_ptr->hitpoint_warn = b; /* Old cheating options */ rd_u16b(&tmp16u); /*** Normal Options ***/ /* Read the option flags */ for (n = 0; n < 8; n++) rd_u32b(&flag[n]); /* Read the option masks */ for (n = 0; n < 8; n++) rd_u32b(&mask[n]); /* Analyze the options */ for (i = 0; i < OPT_MAX; i++) { int os = i / 32; int ob = i % 32; /* Process real entries */ if (!options[i].name) continue; /* Process saved entries */ if (mask[os] & (1L << ob)) { /* Set flag */ if (flag[os] & (1L << ob)) { /* Set */ op_ptr->opt[i] = TRUE; } /* Clear flag */ else { /* Set */ op_ptr->opt[i] = FALSE; } } } /*** Window Options ***/ /* Read the window flags */ for (n = 0; n < ANGBAND_TERM_MAX; n++) { rd_u32b(&window_flag[n]); } /* Read the window masks */ for (n = 0; n < ANGBAND_TERM_MAX; n++) { rd_u32b(&window_mask[n]); } /* Analyze the options */ for (n = 0; n < ANGBAND_TERM_MAX; n++) { /* Analyze the options */ for (i = 0; i < 32; i++) { /* Process valid flags */ if (window_flag_desc[i]) { /* Blank invalid flags */ if (!(window_mask[n] & (1L << i))) { window_flag[n] &= ~(1L << i); } } } } /* Set up the subwindows */ subwindows_set_flags(window_flag, ANGBAND_TERM_MAX); }