void game::show_options() { WINDOW* w_options_border = newwin(25, 80, (TERMY > 25) ? (TERMY-25)/2 : 0, (TERMX > 80) ? (TERMX-80)/2 : 0); WINDOW* w_options = newwin(23, 78, 1 + ((TERMY > 25) ? (TERMY-25)/2 : 0), 1 + ((TERMX > 80) ? (TERMX-80)/2 : 0)); int offset = 1; const int MAX_LINE = 22; int line = 0; char ch = ' '; bool changed_options = false; bool needs_refresh = true; wborder(w_options_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); mvwprintz(w_options_border, 0, 36, c_ltred, " OPTIONS "); wrefresh(w_options_border); do { // TODO: change instructions if(needs_refresh) { werase(w_options); mvwprintz(w_options, 0, 40, c_white, "Use up/down keys to scroll through"); mvwprintz(w_options, 1, 40, c_white, "available options."); mvwprintz(w_options, 2, 40, c_white, "Use left/right keys to toggle."); mvwprintz(w_options, 3, 40, c_white, "Press ESC or q to return. "); // highlight options for option descriptions std::string tmp = option_desc(option_key(offset + line)); std::string out; size_t pos; int displayline = 5; do { pos = tmp.find_first_of('\n'); out = tmp.substr(0, pos); mvwprintz(w_options, displayline, 40, c_white, out.c_str()); tmp = tmp.substr(pos + 1); displayline++; } while(pos != std::string::npos && displayline < 12); needs_refresh = false; } // Clear the lines for(int i = 0; i < 25; i++) { mvwprintz(w_options, i, 0, c_black, " "); } int valid_option_count = 0; // display options for(int i = 0; i < 26 && offset + i < NUM_OPTION_KEYS; i++) { valid_option_count++; mvwprintz(w_options, i, 0, c_white, "%s: ", option_name(option_key(offset + i)).c_str()); if(option_is_bool(option_key(offset + i))) { bool on = OPTIONS[ option_key(offset + i) ]; if(i == line) { mvwprintz(w_options, i, 30, hilite(c_ltcyan), (on ? "True" : "False")); } else { mvwprintz(w_options, i, 30, (on ? c_ltgreen : c_ltred), (on ? "True" : "False")); } } else { char option_val = OPTIONS[ option_key(offset + i) ]; if(i == line) { mvwprintz(w_options, i, 30, hilite(c_ltcyan), "%d", option_val); } else { mvwprintz(w_options, i, 30, c_ltgreen, "%d", option_val); } } } wrefresh(w_options); ch = input(); needs_refresh = true; switch(ch) { // move up and down case 'j': line++; if(line > MAX_LINE/2 && offset + 1 < NUM_OPTION_KEYS - MAX_LINE) { ++offset; --line; } if(line > MAX_LINE) { line = 0; offset = 1; } break; case 'k': line--; if(line < MAX_LINE/2 && offset > 1) { --offset; ++line; } if(line < 0) { line = MAX_LINE; offset = NUM_OPTION_KEYS - MAX_LINE - 1; } break; // toggle options with left/right keys case 'h': if(option_is_bool(option_key(offset + line))) { OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]); } else { OPTIONS[ option_key(offset + line) ]--; if((OPTIONS[ option_key(offset + line) ]) < option_min_options(option_key(offset + line))) { OPTIONS[ option_key(offset + line) ] = option_max_options(option_key(offset + line)) - 1; } } changed_options = true; break; case 'l': if(option_is_bool(option_key(offset + line))) { OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]); } else { OPTIONS[ option_key(offset + line) ]++; if((OPTIONS[ option_key(offset + line) ]) >= option_max_options(option_key(offset + line))) { OPTIONS[ option_key(offset + line) ] = option_min_options(option_key(offset + line)); } } changed_options = true; break; } if(changed_options && OPTIONS[OPT_SEASON_LENGTH] < 1) { OPTIONS[OPT_SEASON_LENGTH]=option_max_options(OPT_SEASON_LENGTH)-1; } } while(ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE); if(changed_options && query_yn("Save changes?")) { save_options(); trigdist=(OPTIONS[OPT_CIRCLEDIST] ? true : false); } werase(w_options); }
void game::show_options() { int iMaxX = (VIEWX < 12) ? 80 : (VIEWX*2)+56; int iMaxY = (VIEWY < 12) ? 25 : (VIEWY*2)+1; WINDOW* w_options_border = newwin(25, 80, (iMaxY > 25) ? (iMaxY-25)/2 : 0, (iMaxX > 80) ? (iMaxX-80)/2 : 0); WINDOW* w_options = newwin(23, 78, 1 + (int)((iMaxY > 25) ? (iMaxY-25)/2 : 0), 1 + (int)((iMaxX > 80) ? (iMaxX-80)/2 : 0)); int offset = 1; int line = 0; char ch = ' '; bool changed_options = false; bool needs_refresh = true; do { wborder(w_options_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); mvwprintz(w_options_border, 0, 36, c_ltred, " OPTIONS "); wrefresh(w_options_border); // TODO: change instructions if (needs_refresh) { werase(w_options); mvwprintz(w_options, 0, 40, c_white, "Use up/down keys to scroll through"); mvwprintz(w_options, 1, 40, c_white, "available options."); mvwprintz(w_options, 2, 40, c_white, "Use left/right keys to toggle."); mvwprintz(w_options, 3, 40, c_white, "Press ESC or q to return. "); // highlight options for option descriptions std::string tmp = option_desc(option_key(offset + line)); std::string out; size_t pos; int displayline = 5; do { pos = tmp.find_first_of('\n'); out = tmp.substr(0, pos); mvwprintz(w_options, displayline, 40, c_white, out.c_str()); tmp = tmp.substr(pos + 1); displayline++; } while (pos != std::string::npos && displayline < 12); needs_refresh = false; } // Clear the lines for (int i = 0; i < 25; i++) mvwprintz(w_options, i, 0, c_black, " "); int valid_option_count = 0; // display options for (int i = 0; i < 25 && offset + i < NUM_OPTION_KEYS; i++) { valid_option_count++; mvwprintz(w_options, i, 0, c_white, "%s: ", option_name( option_key(offset + i) ).c_str()); if (option_is_bool(option_key(offset + i))) { bool on = OPTIONS[ option_key(offset + i) ]; if (i == line) mvwprintz(w_options, i, 30, hilite(c_ltcyan), (on ? "True" : "False")); else mvwprintz(w_options, i, 30, (on ? c_ltgreen : c_ltred), (on ? "True" : "False")); } else { char option_val = OPTIONS[ option_key(offset + i) ]; if (i == line) mvwprintz(w_options, i, 30, hilite(c_ltcyan), "%d", option_val ); else mvwprintz(w_options, i, 30, c_ltgreen, "%d", option_val ); } } wrefresh(w_options); refresh(); ch = input(); needs_refresh = true; refresh(); switch (ch) { // move up and down case 'j': line++; if (line == NUM_OPTION_KEYS - 1) line = 0; break; case 'k': line--; if (line < 0) line = NUM_OPTION_KEYS - 2; break; // toggle options with left/right keys case 'h': if (option_is_bool(option_key(offset + line))) OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]); else { OPTIONS[ option_key(offset + line) ]--; if ((OPTIONS[ option_key(offset + line) ]) < 0 ) OPTIONS[ option_key(offset + line) ] = option_max_options(option_key(offset + line)) - 1; } changed_options = true; break; case 'l': if (option_is_bool(option_key(offset + line))) OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]); else { OPTIONS[ option_key(offset + line) ]++; if ((OPTIONS[ option_key(offset + line) ]) >= option_max_options(option_key(offset + line))) OPTIONS[ option_key(offset + line) ] = 0; } changed_options = true; break; } } while (ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE); if (changed_options && query_yn(this->VIEWX, this->VIEWY, "Save changes?")) save_options(); werase(w_options); }
void game::show_options() { // Remember what the options were originally so we can restore them if player cancels. option_table OPTIONS_OLD = OPTIONS; WINDOW* w_options_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0, (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0); WINDOW* w_options = newwin(FULL_SCREEN_HEIGHT-2, FULL_SCREEN_WIDTH-2, 1 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0), 1 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0)); int offset = 1; const int MAX_LINE = 22; int line = 0; char ch = ' '; bool changed_options = false; bool needs_refresh = true; wborder(w_options_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); mvwprintz(w_options_border, 0, 36, c_ltred, _(" OPTIONS ")); wrefresh(w_options_border); do { // TODO: change instructions if(needs_refresh) { werase(w_options); // because those texts use their own \n, do not fold so use a large enough width like 999 fold_and_print(w_options, 0, 40, 999, c_white, _("Use up/down keys to scroll through\navailable options.\nUse left/right keys to toggle.\nPress ESC or q to return.")); // highlight options for option descriptions fold_and_print(w_options, 5, 40, 999, c_white, option_desc(option_key(offset + line)).c_str()); needs_refresh = false; } // Clear the lines for(int i = 0; i < 25; i++) { mvwprintz(w_options, i, 0, c_black, " "); } int valid_option_count = 0; // display options for(int i = 0; i < 26 && offset + i < NUM_OPTION_KEYS; i++) { valid_option_count++; mvwprintz(w_options, i, 0, c_white, "%s: ", option_name(option_key(offset + i)).c_str()); if(option_is_bool(option_key(offset + i))) { bool on = OPTIONS[ option_key(offset + i) ]; if(i == line) { mvwprintz(w_options, i, 30, hilite(c_ltcyan), (on ? _("True") : _("False"))); } else { mvwprintz(w_options, i, 30, (on ? c_ltgreen : c_ltred), (on ? _("True") : _("False"))); } } else { char option_val = OPTIONS[ option_key(offset + i) ]; if(i == line) { mvwprintz(w_options, i, 30, hilite(c_ltcyan), "%d", option_val); } else { mvwprintz(w_options, i, 30, c_ltgreen, "%d", option_val); } } } wrefresh(w_options); ch = input(); needs_refresh = true; switch(ch) { // move up and down case 'j': line++; if(line > MAX_LINE/2 && offset + 1 < NUM_OPTION_KEYS - MAX_LINE) { ++offset; --line; } if(line > MAX_LINE) { line = 0; offset = 1; } break; case 'k': line--; if(line < MAX_LINE/2 && offset > 1) { --offset; ++line; } if(line < 0) { line = MAX_LINE; offset = NUM_OPTION_KEYS - MAX_LINE - 1; } break; // toggle options with left/right keys case 'h': if(option_is_bool(option_key(offset + line))) { OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]); } else { OPTIONS[ option_key(offset + line) ]--; if((OPTIONS[ option_key(offset + line) ]) < option_min_options(option_key(offset + line))) { OPTIONS[ option_key(offset + line) ] = option_max_options(option_key(offset + line)) - 1; } } changed_options = true; break; case 'l': if(option_is_bool(option_key(offset + line))) { OPTIONS[ option_key(offset + line) ] = !(OPTIONS[ option_key(offset + line) ]); } else { OPTIONS[ option_key(offset + line) ]++; if((OPTIONS[ option_key(offset + line) ]) >= option_max_options(option_key(offset + line))) { OPTIONS[ option_key(offset + line) ] = option_min_options(option_key(offset + line)); } } changed_options = true; break; } if(changed_options && OPTIONS[OPT_SEASON_LENGTH] < 1) { OPTIONS[OPT_SEASON_LENGTH]=option_max_options(OPT_SEASON_LENGTH)-1; } } while(ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE); if(changed_options) { if(query_yn(_("Save changes?"))) { save_options(); trigdist=(OPTIONS[OPT_CIRCLEDIST] ? true : false); } else { // Player wants to keep the old options. Revert! OPTIONS = OPTIONS_OLD; } } werase(w_options); }