void mod_ui::draw_shift_information(WINDOW *win, int sy, int sx, const std::vector<std::string> mod_list, const int selection) { const std::string can_shift_true = "<color_cyan>"; const std::string can_shift_false = "<color_magenta>"; const std::string can_shift_close = "</color>"; std::string shift_string = ""; if (can_shift_up(selection, mod_list)) { shift_string += can_shift_true; } else { shift_string += can_shift_false; } shift_string += "+" + can_shift_close; shift_string += " "; if (can_shift_down(selection, mod_list)) { shift_string += can_shift_true; } else { shift_string += can_shift_false; } shift_string += "-" + can_shift_close; fold_and_print(win, sy, sx, 4, c_black, shift_string.c_str()); }
void mod_ui::try_shift( char direction, int &selection, std::vector<std::string> &active_list ) { // error catch for out of bounds if( selection < 0 || selection >= ( int )active_list.size() ) { return; } int newsel; int oldsel; std::string selstring; std::string modstring; int selshift = 0; // shift up (towards 0) if( direction == '+' && can_shift_up( selection, active_list ) ) { // see if the mod at selection-1 is a) a core, or b) is depended on by this mod newsel = selection - 1; oldsel = selection; selshift = -1; } // shift down (towards active_list.size()-1) else if( direction == '-' && can_shift_down( selection, active_list ) ) { newsel = selection; oldsel = selection + 1; selshift = +1; } if( !selshift ) { // false if selshift is 0, true if selshift is +/- 1: bool(int(0)) evaluates to false and bool(int(!0)) evaluates to true return; } modstring = active_list[newsel]; selstring = active_list[oldsel]; // we can shift! // switch values! active_list[newsel] = selstring; active_list[oldsel] = modstring; selection += selshift; }