static void ping_port() { int size = 0; ports_num = &size; port = init_ports(ports_num); print_menu_items(); add_designer_label(); print_port_items(); monit_keys(); clear(); print_frame(); add_menu_label(); print_menu_items(); add_designer_label(); }
void menu_rc_setup(void) { uint8_t cursor = LINE0; uint8_t top = RCSTART; uint8_t temp = 0; int8_t values[RCITEMS]; menu_range_t range; uint8_t i = 0; uint8_t text_link; while(button != BACK) { // Load values from eeprom memcpy(&values[0],&Config.TxSeq,sizeof(int8_t) * RCITEMS); // Print menu print_menu_items(top, RCSTART, &values[0], RCITEMS, (prog_uchar*)rc_menu_ranges, RCOFFSET, (prog_uchar*)RCMenuText, cursor); // Handle menu changes update_menu(RCITEMS, RCSTART, button, &cursor, &top, &temp); range = get_menu_range ((prog_uchar*)rc_menu_ranges, temp - RCSTART); if (button == ENTER) { text_link = pgm_read_byte(&RCMenuText[temp - RCSTART]); values[temp - RCSTART] = do_menu_item(temp, values[temp - RCSTART], range, 0, text_link); } // Update value in config structure memcpy(&Config.TxSeq,&values[0],sizeof(int8_t) * RCITEMS); // Update Ch7. mixer with source from Config.FlapChan if in Aeroplane mode if (Config.MixMode == AEROPLANE) { Config.Channel[CH7].source_a = Config.FlapChan; } if (button == ENTER) { // Update channel sequence for (i = 0; i < MAX_RC_CHANNELS; i++) { if (Config.TxSeq == JRSEQ) { Config.ChannelOrder[i] = pgm_read_byte(&JR[i]); } else if (Config.TxSeq == FUTABASEQ) { Config.ChannelOrder[i] = pgm_read_byte(&FUTABA[i]); } } Save_Config_to_EEPROM(); // Save value and return } } }
static void print_menu() { int array_size = 0; menu_size = &array_size; m_item = init_menu(menu_size); print_frame(); add_menu_label(); print_menu_items(); add_designer_label(); main_loop(); endwin(); attroff(COLOR_PAIR(1)); }
void menu_offsets(void) { int8_t *value_ptr; uint16_t reference = OFFSETSSTART; // If sub-menu item has changed, reset sub-menu positions if (menu_flag) { sub_top = OFFSETSSTART; menu_flag = 0; } while(button != BACK) { value_ptr = &Config.Offsets[0].Point1; // Print top level menu print_menu_items(sub_top, reference, value_ptr, (const unsigned char*)Offsets_menu_ranges, 0, (const uint16_t*)OffsetsMenuOffsets, (const uint16_t*)OffsetsMenuText, cursor); // Handle menu navigation update_menu(MAX_OUTPUTS, reference, 0, button, &cursor, &sub_top, &menu_temp); // Edit selected curve if (button == ENTER) { edit_curve_item(menu_temp - reference, OFFSET); // Curves after NUMBEROFCURVES are offsets } // Stop unwanted exit to main menu if (button == ABORT) { Wait_BUTTON1(); // Wait for user's finger off the button button = NONE; } // Update limits when exiting if (button == ENTER) { Save_Config_to_EEPROM(); // Save value and return Wait_BUTTON4(); // Wait for user's finger off the button Wait_BUTTON1(); } } }
void menu_mixer(uint8_t i) { uint8_t cursor = LINE0; uint8_t top = MIXERSTART; int8_t values[MIXERITEMS]; menu_range_t range; uint8_t temp = 0; uint8_t text_link = 0; while(button != BACK) { // Load values from eeprom memcpy(&values[0],&Config.Channel[i].source_a,sizeof(int8_t) * MIXERITEMS); // Print menu print_menu_items(top, MIXERSTART, &values[0], MIXERITEMS,(prog_uchar*)mixer_menu_ranges, MIXOFFSET, (prog_uchar*)MixerMenuText, cursor); // Handle menu changes update_menu(MIXERITEMS, MIXERSTART, button, &cursor, &top, &temp); range = get_menu_range ((prog_uchar*)mixer_menu_ranges, temp - MIXERSTART); if (button == ENTER) { text_link = pgm_read_byte(&MixerMenuText[temp - MIXERSTART]); values[temp - MIXERSTART] = do_menu_item(temp, values[temp - MIXERSTART], range, 0, text_link); } // Update value in config structure memcpy(&Config.Channel[i].source_a,&values[0],sizeof(int8_t) * MIXERITEMS); if (button == ENTER) { UpdateLimits(); // Update travel limits based on percentages Save_Config_to_EEPROM(); // Save value and return } } menu_beep(1); _delay_ms(200); }
void menu_al_control(void) { uint8_t cursor = LINE0; uint8_t top = AUTOSTART; uint8_t temp = 0; int8_t values[AUTOITEMS]; menu_range_t range; uint8_t text_link = 0; while(button != BACK) { // Load values from eeprom memcpy(&values[0],&Config.AutoMode,sizeof(int8_t) * AUTOITEMS); // Print menu print_menu_items(top, AUTOSTART, &values[0], AUTOITEMS, (prog_uchar*)auto_menu_ranges, AUTOOFFSET, (prog_uchar*)AutoMenuText, cursor); // Handle menu changes update_menu(AUTOITEMS, AUTOSTART, button, &cursor, &top, &temp); range = get_menu_range ((prog_uchar*)auto_menu_ranges, temp - AUTOSTART); if (button == ENTER) { text_link = pgm_read_byte(&AutoMenuText[temp - AUTOSTART]); values[temp - AUTOSTART] = do_menu_item(temp, values[temp - AUTOSTART], range, 0, text_link); } // Update value in config structure memcpy(&Config.AutoMode,&values[0],sizeof(int8_t) * AUTOITEMS); if (button == ENTER) { UpdateLimits(); // Update I-term limits and triggers based on percentages Save_Config_to_EEPROM(); // Save value and return } } }
void game::print_menu(WINDOW *w_open, int iSel, const int iMenuOffsetX, int iMenuOffsetY, bool bShowDDA) { // Clear Lines werase(w_open); // Define window size int window_width = getmaxx(w_open); int window_height = getmaxy(w_open); // Draw horizontal line for (int i = 1; i < window_width - 1; ++i) { mvwputch(w_open, window_height - 2, i, c_white, LINE_OXOX); } center_print(w_open, window_height - 1, c_red, _("Please report bugs to [email protected] or post on the forums.")); int iLine = 0; const int iOffsetX1 = 3 + (window_width - FULL_SCREEN_WIDTH) / 2; const int iOffsetX2 = 4 + (window_width - FULL_SCREEN_WIDTH) / 2; const int iOffsetX3 = 18 + (window_width - FULL_SCREEN_WIDTH) / 2; const nc_color cColor1 = c_ltcyan; const nc_color cColor2 = c_ltblue; const nc_color cColor3 = c_ltblue; mvwprintz(w_open, iLine++, iOffsetX1, cColor1, "_________ __ .__ "); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, "\\_ ___ \\ _____ _/ |_ _____ ____ | | ___.__ ______ _____ "); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, "/ \\ \\/ \\__ \\ \\ __\\\\__ \\ _/ ___\\ | | < | | / ___/ / \\ "); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, "\\ \\____ / __ \\_ | | / __ \\_\\ \\___ | |__ \\___ | \\___ \\ | Y Y \\"); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, " \\______ /(____ / |__| (____ / \\___ >|____/ / ____|/____ >|__|_| /"); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, " \\/ \\/ \\/ \\/ \\/ \\/ \\/ "); if (bShowDDA) { if (FULL_SCREEN_HEIGHT > 24) { ++iLine; } mvwprintz(w_open, iLine++, iOffsetX2, cColor2, "________ .__ ________ "); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, "\\______ \\ _____ _______ | | __ \\______ \\ _____ ___.__ ______"); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, " | | \\ \\__ \\ \\_ __ \\| |/ / | | \\ \\__ \\ < | | / ___/"); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, " | ` \\ / __ \\_ | | \\/| < | ` \\ / __ \\_ \\___ | \\___ \\ "); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, "/_______ /(____ / |__| |__|_ \\ /_______ /(____ / / ____|/____ >"); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, " \\/ \\/ \\/ \\/ \\/ \\/ \\/ "); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, " _____ .__ .___"); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, " / _ \\ | |__ ____ _____ __| _/"); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, " / /_\\ \\ | | \\ _/ __ \\ \\__ \\ / __ | "); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, "/ | \\| Y \\\\ ___/ / __ \\_/ /_/ | "); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, "\\____|__ /|___| / \\___ >(____ /\\____ | "); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, " \\/ \\/ \\/ \\/ \\/ "); iLine++; center_print(w_open, iLine++, cColor3, _("Version: %s"), getVersionString()); } std::vector<std::string> vMenuItems; vMenuItems.push_back(pgettext("Main Menu", "<M>OTD")); vMenuItems.push_back(pgettext("Main Menu", "<N>ew Game")); vMenuItems.push_back(pgettext("Main Menu", "Lo<a>d")); vMenuItems.push_back(pgettext("Main Menu", "<W>orld")); vMenuItems.push_back(pgettext("Main Menu", "<S>pecial")); vMenuItems.push_back(pgettext("Main Menu", "<O>ptions")); vMenuItems.push_back(pgettext("Main Menu", "H<e>lp")); vMenuItems.push_back(pgettext("Main Menu", "<C>redits")); vMenuItems.push_back(pgettext("Main Menu", "<Q>uit")); int menu_length = 0; for (int pos = 0; pos < vMenuItems.size(); pos++) { // adds (width + 2) if there are no shortcut symbols "<" & ">", and just width otherwise menu_length += utf8_width(vMenuItems[pos].c_str()) + (vMenuItems[pos].find_first_of("<") == std::string::npos ? 2 : 0); } int spacing = (window_width - menu_length) / vMenuItems.size() - 1; spacing = (spacing < 1 ? 1 : spacing); const int adj_offset = (window_width - menu_length - spacing * vMenuItems.size() ) / 2 - 1; print_menu_items(w_open, vMenuItems, iSel, iMenuOffsetY, iMenuOffsetX + adj_offset, spacing); refresh(); wrefresh(w_open); refresh(); }
bool game::opening_screen() { world_generator->set_active_world(NULL); // This actually _loads_ what worlds exist. world_generator->get_all_worlds(); WINDOW *w_background = newwin(TERMY, TERMX, 0, 0); werase(w_background); wrefresh(w_background); // main window should also expand to use available display space. // expanding to evenly use up half of extra space, for now. int extra_w = ((TERMX - FULL_SCREEN_WIDTH) / 2) - 1; int extra_h = ((TERMY - FULL_SCREEN_HEIGHT) / 2) - 1; extra_w = (extra_w > 0 ? extra_w : 0); extra_h = (extra_h > 0 ? extra_h : 0); const int total_w = FULL_SCREEN_WIDTH + extra_w; const int total_h = FULL_SCREEN_HEIGHT + extra_h; // position of window within main display const int x0 = (TERMX - total_w) / 2; const int y0 = (TERMY - total_h) / 2; WINDOW *w_open = newwin(total_h, total_w, y0, x0); const int iMenuOffsetX = 2; int iMenuOffsetY = total_h - 3; std::vector<std::string> vSubItems; vSubItems.push_back(pgettext("Main Menu|New Game", "<C>ustom Character")); vSubItems.push_back(pgettext("Main Menu|New Game", "<P>reset Character")); vSubItems.push_back(pgettext("Main Menu|New Game", "<R>andom Character")); vSubItems.push_back(pgettext("Main Menu|New Game", "Play <N>ow!")); std::vector<std::string> vWorldSubItems; vWorldSubItems.push_back(pgettext("Main Menu|World", "<C>reate World")); vWorldSubItems.push_back(pgettext("Main Menu|World", "<D>elete World")); vWorldSubItems.push_back(pgettext("Main Menu|World", "<R>eset World")); print_menu(w_open, 0, iMenuOffsetX, iMenuOffsetY); std::vector<std::string> savegames, templates; dirent *dp; DIR *dir; if (!assure_dir_exist("save")) { popup(_("Unable to make save directory. Check permissions.")); return false; } dir = opendir("data"); while ((dp = readdir(dir))) { std::string tmp = dp->d_name; if (tmp.find(".template") != std::string::npos) { templates.push_back(tmp.substr(0, tmp.find(".template"))); } } closedir(dir); int sel1 = 1, sel2 = 1, sel3 = 1, layer = 1; InputEvent input; int chInput; bool start = false; // Load MOTD and store it in a string // Only load it once, it shouldn't change for the duration of the application being open static std::vector<std::string> motd; if (motd.empty()) { std::ifstream motd_file; motd_file.open("data/motd"); if (!motd_file.is_open()) { motd.push_back(_("No message today.")); } else { while (!motd_file.eof()) { std::string tmp; getline(motd_file, tmp); if (!tmp.length() || tmp[0] != '#') { motd.push_back(tmp); } } } } // Load Credits and store it in a string // Only load it once, it shouldn't change for the duration of the application being open static std::vector<std::string> credits; if (credits.empty()) { std::ifstream credits_file; credits_file.open("data/credits"); if (!credits_file.is_open()) { credits.push_back(_("No message today.")); } else { while (!credits_file.eof()) { std::string tmp; getline(credits_file, tmp); if (!tmp.length() || tmp[0] != '#') { credits.push_back(tmp); } } } } u = player(); while(!start) { print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY, (sel1 == 0 || sel1 == 7) ? false : true); if (layer == 1) { if (sel1 == 0) { // Print the MOTD. for (int i = 0; i < motd.size() && i < 16; i++) { mvwprintz(w_open, i + 6, 8 + extra_w / 2, c_ltred, motd[i].c_str()); } wrefresh(w_open); refresh(); } else if (sel1 == 7) { // Print the Credits. for (int i = 0; i < credits.size() && i < 16; i++) { mvwprintz(w_open, i + 6, 8 + extra_w / 2, c_ltred, credits[i].c_str()); } wrefresh(w_open); refresh(); } chInput = getch(); if (chInput == 'm' || chInput == 'M') { // MOTD sel1 = 0; chInput = '\n'; } else if (chInput == 'n' || chInput == 'N') { // New Game sel1 = 1; chInput = '\n'; } else if (chInput == 'a' || chInput == 'A') { // Load Game sel1 = 2; chInput = '\n'; } else if (chInput == 'w' || chInput == 'W') { // World sel1 = 3; chInput = '\n'; } else if (chInput == 's' || chInput == 'S') { // Special Game sel1 = 4; chInput = '\n'; } else if (chInput == 'o' || chInput == 'O') { // Options sel1 = 5; chInput = '\n'; } else if (chInput == 'e' || chInput == 'E' || chInput == '?') { // Help sel1 = 6; chInput = '\n'; } else if (chInput == 'c' || chInput == 'C') { // Credits sel1 = 7; chInput = '\n'; } else if (chInput == 'q' || chInput == 'Q' || chInput == KEY_ESCAPE) { // Quit sel1 = 8; chInput = '\n'; } if (chInput == KEY_LEFT || chInput == 'h') { if (sel1 > 0) { sel1--; } else { sel1 = 8; } } else if (chInput == KEY_RIGHT || chInput == 'l') { if (sel1 < 8) { sel1++; } else { sel1 = 0; } } else if ((chInput == KEY_UP || chInput == 'k' || chInput == '\n') && sel1 > 0 && sel1 != 7) { if (sel1 == 5) { show_options(); } else if (sel1 == 6) { display_help(); } else if (sel1 == 8) { uquit = QUIT_MENU; delwin(w_open); delwin(w_background); return false; } else { sel2 = 0; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY, (sel1 == 0 || sel1 == 7) ? false : true); } } } else if (layer == 2) { if (sel1 == 1) { // New Character print_menu_items(w_open, vSubItems, sel2, iMenuOffsetY - 2, iMenuOffsetX); wrefresh(w_open); refresh(); chInput = getch(); if (chInput == 'c' || chInput == 'C') { sel2 = 0; chInput = '\n' ; } else if (chInput == 'p' || chInput == 'P') { sel2 = 1; chInput = '\n'; } else if (chInput == 'r' || chInput == 'R') { sel2 = 2; chInput = '\n'; } else if (chInput == 'n' || chInput == 'N') { sel2 = 3; chInput = '\n'; } if (chInput == KEY_LEFT || chInput == 'h') { sel2--; if (sel2 < 0) { sel2 = vSubItems.size() - 1; } } if (chInput == KEY_RIGHT || chInput == 'l') { sel2++; if (sel2 >= vSubItems.size()) { sel2 = 0; } } else if (chInput == KEY_DOWN || chInput == 'j' || chInput == KEY_ESCAPE) { layer = 1; sel1 = 1; } if (chInput == KEY_UP || chInput == 'k' || chInput == '\n') { if (sel2 == 0 || sel2 == 2 || sel2 == 3) { // First load the mods, this is done by // loading the world. // Pick a world, supressing prompts if it's "play now" mode. WORLDPTR world = world_generator->pick_world( sel2 != 3 ); if (world == NULL) { continue; } world_generator->set_active_world(world); setup(); if (!u.create((sel2 == 0) ? PLTYPE_CUSTOM : ((sel2 == 2) ? PLTYPE_RANDOM : PLTYPE_NOW))) { u = player(); continue; } werase(w_background); wrefresh(w_background); MAPBUFFER.load(world->world_name); start_game(world->world_name); start = true; } else if (sel2 == 1) { layer = 3; sel3 = 0; } } } else if (sel1 == 2) { // Load Character if (world_generator->all_worldnames.empty()) { mvwprintz(w_open, iMenuOffsetY - 2, 15 + iMenuOffsetX + extra_w / 2, c_red, _("No Worlds found!")); } else { for (int i = 0; i < world_generator->all_worldnames.size(); ++i) { int line = iMenuOffsetY - 2 - i; std::string world_name = world_generator->all_worldnames[i]; int savegames_count = world_generator->all_worlds[world_name]->world_saves.size(); mvwprintz(w_open, line, 15 + iMenuOffsetX + extra_w / 2, (sel2 == i ? h_white : c_white), "%s (%d)", world_name.c_str(), savegames_count); } } wrefresh(w_open); refresh(); input = get_input(); if (world_generator->all_worldnames.empty() && (input == DirectionS || input == Confirm)) { layer = 1; } else if (input == DirectionS) { if (sel2 > 0) { sel2--; } else { sel2 = world_generator->all_worldnames.size() - 1; } } else if (input == DirectionN) { if (sel2 < world_generator->all_worldnames.size() - 1) { sel2++; } else { sel2 = 0; } } else if (input == DirectionW || input == Cancel) { layer = 1; } if (input == DirectionE || input == Confirm) { if (sel2 >= 0 && sel2 < world_generator->all_worldnames.size()) { layer = 3; sel3 = 0; } } } else if (sel1 == 3) { // World Menu // Show options for Create, Destroy, Reset worlds. // Create world goes directly to Make World screen. // Reset and Destroy ask for world to modify. // Reset empties world of everything but options, then makes new world within it. // Destroy asks for confirmation, then destroys everything in world and then removes world folder. // only show reset / destroy world if there is at least one valid world existing! int world_subs_to_display = (world_generator->all_worldnames.size() > 0)? vWorldSubItems.size(): 1; std::vector<std::string> world_subs; int xoffset = 25 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2; int xlen = 0; for (int i = 0; i < world_subs_to_display; ++i) { world_subs.push_back(vWorldSubItems[i]); xlen += vWorldSubItems[i].size() + 2; // Open and close brackets added } xlen += world_subs.size() - 1; if (world_subs.size() > 1) { xoffset -= 6; } print_menu_items(w_open, world_subs, sel2, yoffset, xoffset - (xlen / 4)); wrefresh(w_open); refresh(); chInput = getch(); input = get_input(chInput); //shortcuts if (chInput == 'c' || chInput == 'C') { sel2 = 0; input = Confirm; } else if ((chInput == 'd' || chInput == 'D') && (world_subs_to_display > 1)) { sel2 = 1; input = Confirm; } else if ((chInput == 'r' || chInput == 'R') && (world_subs_to_display > 1)) { sel2 = 2; input = Confirm; } if (input == DirectionW) { if (sel2 > 0) { --sel2; } else { sel2 = world_subs_to_display - 1; } } else if (input == DirectionE) { if (sel2 < world_subs_to_display - 1) { ++sel2; } else { sel2 = 0; } } else if (input == DirectionS || input == Cancel) { layer = 1; } if (input == DirectionN || input == Confirm) { if (sel2 == 0) { // Create world // Open up world creation screen! if (world_generator->make_new_world()) { return opening_screen(); } else { layer = 1; } } else if (sel2 == 1 || sel2 == 2) { // Delete World | Reset World layer = 3; sel3 = 0; } } } else if (sel1 == 4) { // Special game std::vector<std::string> special_names; int xoffset = 32 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2; int xlen = 0; for (int i = 1; i < NUM_SPECIAL_GAMES; i++) { std::string spec_name = special_game_name(special_game_id(i)); special_names.push_back(spec_name); xlen += spec_name.size() + 2; } xlen += special_names.size() - 1; print_menu_items(w_open, special_names, sel2, yoffset, xoffset - (xlen / 4)); wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionW) { if (sel2 > 0) { sel2--; } else { sel2 = NUM_SPECIAL_GAMES - 2; } } else if (input == DirectionE) { if (sel2 < NUM_SPECIAL_GAMES - 2) { sel2++; } else { sel2 = 0; } } else if (input == DirectionS || input == Cancel) { layer = 1; } if (input == DirectionN || input == Confirm) { if (sel2 >= 0 && sel2 < NUM_SPECIAL_GAMES - 1) { delete gamemode; gamemode = get_special_game( special_game_id(sel2 + 1) ); // check world WORLDPTR world = world_generator->make_new_world(special_game_id(sel2 + 1)); if (world == NULL) { continue; } world_generator->set_active_world(world); setup(); if (!gamemode->init()) { delete gamemode; gamemode = NULL; u = player(); continue; } start = true; } } } } else if (layer == 3) { if (sel1 == 2) { // Load Game savegames = world_generator->all_worlds[world_generator->all_worldnames[sel2]]->world_saves; if (savegames.empty()) { mvwprintz(w_open, iMenuOffsetY - 2, 19 + 19 + iMenuOffsetX + extra_w / 2, c_red, _("No save games found!")); } else { for (int i = 0; i < savegames.size(); i++) { int line = iMenuOffsetY - 2 - i; mvwprintz(w_open, line, 19 + 19 + iMenuOffsetX + extra_w / 2, (sel3 == i ? h_white : c_white), base64_decode(savegames[i]).c_str()); } } wrefresh(w_open); refresh(); input = get_input(); if (savegames.size() == 0 && (input == DirectionS || input == Confirm)) { layer = 2; } else if (input == DirectionS) { if (sel3 > 0) { sel3--; } else { sel3 = savegames.size() - 1; } } else if (input == DirectionN) { if (sel3 < savegames.size() - 1) { sel3++; } else { sel3 = 0; } } else if (input == DirectionW || input == Cancel) { layer = 2; sel3 = 0; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } if (input == DirectionE || input == Confirm) { if (sel3 >= 0 && sel3 < savegames.size()) { werase(w_background); wrefresh(w_background); WORLDPTR world = world_generator->all_worlds[world_generator->all_worldnames[sel2]]; world_generator->set_active_world(world); setup(); MAPBUFFER.load(world->world_name); load(world->world_name, savegames[sel3]); start = true; } } } else if (sel1 == 3) { // Show world names int i = 0; for (std::vector<std::string>::iterator it = world_generator->all_worldnames.begin(); it != world_generator->all_worldnames.end(); ++it) { int savegames_count = world_generator->all_worlds[*it]->world_saves.size(); int line = iMenuOffsetY - 4 - i; mvwprintz(w_open, line, 26 + iMenuOffsetX + extra_w / 2, (sel3 == i ? h_white : c_white), "%s (%d)", (*it).c_str(), savegames_count); ++i; } wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionS) { if (sel3 > 0) { --sel3; } else { sel3 = world_generator->all_worldnames.size() - 1; } } else if (input == DirectionN) { if (sel3 < world_generator->all_worldnames.size() - 1) { ++sel3; } else { sel3 = 0; } } else if (input == DirectionW || input == Cancel) { layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } if (input == DirectionE || input == Confirm) { if (sel3 >= 0 && sel3 < world_generator->all_worldnames.size()) { bool query_yes = false; bool do_delete = false; if (sel2 == 1) { // Delete World if (query_yn(_("Delete the world and all saves?"))) { query_yes = true; do_delete = true; } } else if (sel2 == 2) { // Reset World if (query_yn(_("Remove all saves and regenerate world?"))) { query_yes = true; do_delete = false; } } if (query_yes) { delete_world(world_generator->all_worldnames[sel3], do_delete); savegames.clear(); MAPBUFFER.reset(); MAPBUFFER.make_volatile(); overmap_buffer.clear(); layer = 2; if (do_delete) { // delete world and all contents world_generator->remove_world(world_generator->all_worldnames[sel3]); } else { // clear out everything but worldoptions from this world world_generator->all_worlds[world_generator->all_worldnames[sel3]]->world_saves.clear(); } if (world_generator->all_worldnames.size() == 0) { sel2 = 0; // reset to create world selection } } else { // hacky resolution to the issue of persisting world names on the screen return opening_screen(); } } print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } } else { // Character Templates if (templates.size() == 0) { mvwprintz(w_open, iMenuOffsetY - 4, iMenuOffsetX + 20 + extra_w / 2, c_red, _("No templates found!")); } else { for (int i = 0; i < templates.size(); i++) { int line = iMenuOffsetY - 4 - i; mvwprintz(w_open, line, 20 + iMenuOffsetX + extra_w / 2, (sel3 == i ? h_white : c_white), templates[i].c_str()); } } wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionS) { if (sel3 > 0) { sel3--; } else { sel3 = templates.size() - 1; } } else if (templates.size() == 0 && (input == DirectionN || input == Confirm)) { sel1 = 1; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } else if (input == DirectionN) { if (sel3 < templates.size() - 1) { sel3++; } else { sel3 = 0; } } else if (input == DirectionW || input == Cancel || templates.size() == 0) { sel1 = 1; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } else if (input == DirectionE || input == Confirm) { WORLDPTR world = world_generator->pick_world(); if (world == NULL) { u = player(); continue; } world_generator->set_active_world(world); setup(); if (!u.create(PLTYPE_TEMPLATE, templates[sel3])) { u = player(); continue; } werase(w_background); wrefresh(w_background); MAPBUFFER.load(world_generator->active_world->world_name); start_game(world_generator->active_world->world_name); start = true; } } } } delwin(w_open); delwin(w_background); if (start == false) { uquit = QUIT_MENU; } else { refresh_all(); draw(); } return start; }
bool game::opening_screen() { WINDOW* w_background = newwin(TERMY, TERMX, 0, 0); werase(w_background); wrefresh(w_background); WINDOW* w_open = newwin(25, 80, (TERMY > 25) ? (TERMY-25)/2 : 0, (TERMX > 80) ? (TERMX-80)/2 : 0); const int iMenuOffsetX = 2; int iMenuOffsetY = 22; std::vector<std::string> vSubItems; vSubItems.push_back("Custom Character"); vSubItems.push_back("Preset Character"); vSubItems.push_back("Random Character"); print_menu(w_open, 0, iMenuOffsetX, iMenuOffsetY); std::vector<std::string> savegames, templates; dirent *dp; DIR *dir = opendir("save"); if (!dir) { #if (defined _WIN32 || defined __WIN32__) mkdir("save"); #else mkdir("save", 0777); #endif dir = opendir("save"); } if (!dir) { dbg(D_ERROR) << "game:opening_screen: Unable to make save directory."; debugmsg("Could not make './save' directory"); endwin(); exit(1); } while ((dp = readdir(dir))) { std::string tmp = dp->d_name; if (tmp.find(".sav") != std::string::npos) savegames.push_back(tmp.substr(0, tmp.find(".sav"))); } closedir(dir); dir = opendir("data"); while ((dp = readdir(dir))) { std::string tmp = dp->d_name; if (tmp.find(".template") != std::string::npos) templates.push_back(tmp.substr(0, tmp.find(".template"))); } int sel1 = 1, sel2 = 1, layer = 1; InputEvent input; int chInput; bool start = false; // Load MOTD and store it in a string std::vector<std::string> motd; std::ifstream motd_file; motd_file.open("data/motd"); if (!motd_file.is_open()) motd.push_back("No message today."); else { while (!motd_file.eof()) { std::string tmp; getline(motd_file, tmp); if (!tmp.length() || tmp[0] != '#') motd.push_back(tmp); } } // Load Credits and store it in a string std::vector<std::string> credits; std::ifstream credits_file; credits_file.open("data/credits"); if (!credits_file.is_open()) credits.push_back("No message today."); else { while (!credits_file.eof()) { std::string tmp; getline(credits_file, tmp); if (!tmp.length() || tmp[0] != '#') credits.push_back(tmp); } } while(!start) { if (layer == 1) { print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY, (sel1 == 0 || sel1 == 7) ? false : true); if (sel1 == 0) { // Print the MOTD. for (int i = 0; i < motd.size() && i < 16; i++) mvwprintz(w_open, i + 7, 8, c_ltred, motd[i].c_str()); wrefresh(w_open); refresh(); } else if (sel1 == 7) { // Print the Credits. for (int i = 0; i < credits.size() && i < 16; i++) mvwprintz(w_open, i + 7, 8, c_ltred, credits[i].c_str()); wrefresh(w_open); refresh(); } chInput = getch(); if (chInput == 'm' || chInput == 'M') { sel1 = 0; chInput = '\n'; } else if (chInput == 'n' || chInput == 'N') { sel1 = 1; chInput = '\n'; } else if (chInput == 'L') { sel1 = 2; chInput = '\n'; } else if (chInput == 'r' || chInput == 'R') { sel1 = 3; chInput = '\n'; } else if (chInput == 's' || chInput == 'S') { sel1 = 4; chInput = '\n'; } else if (chInput == 'o' || chInput == 'O') { sel1 = 5; chInput = '\n'; } else if (chInput == 'H') { sel1 = 6; chInput = '\n'; } else if (chInput == 'c' || chInput == 'C') { sel1 = 7; chInput = '\n'; } else if (chInput == 'q' || chInput == 'Q' || chInput == KEY_ESCAPE) { sel1 = 8; chInput = '\n'; } if (chInput == KEY_LEFT || chInput == 'h') { if (sel1 > 0) sel1--; else sel1 = 8; } else if (chInput == KEY_RIGHT || chInput == 'l') { if (sel1 < 8) sel1++; else sel1 = 0; } else if ((chInput == KEY_UP || chInput == 'k' || chInput == '\n') && sel1 > 0 && sel1 != 7) { if (sel1 == 5) { show_options(); } else if (sel1 == 6) { help(); } else if (sel1 == 8) { uquit = QUIT_MENU; return false; } else { sel2 = 0; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY, (sel1 == 0 || sel1 == 7) ? false : true); } } } else if (layer == 2) { if (sel1 == 1) { // New Character print_menu_items(w_open, vSubItems, sel2, iMenuOffsetY-2, iMenuOffsetX+7); wrefresh(w_open); refresh(); chInput = getch(); if (chInput == 'c' || chInput == 'C') { sel2 = 0; chInput = '\n' ; } else if (chInput == 'p' || chInput == 'P') { sel2 = 1; chInput = '\n'; } else if (chInput == 'r' || chInput == 'R') { sel2 = 2; chInput = '\n'; } if (chInput == KEY_LEFT || chInput == 'h') { if (sel2 > 0) sel2--; else sel2 = 2; } if (chInput == KEY_RIGHT || chInput == 'l') { if (sel2 < 2) sel2++; else sel2 = 0; } else if (chInput == KEY_DOWN || chInput == 'j' || chInput == KEY_ESCAPE) { layer = 1; sel1 = 1; } if (chInput == KEY_UP || chInput == 'k' || chInput == '\n') { if (sel2 == 0 || sel2 == 2) { if (!u.create(this, (sel2 == 0) ? PLTYPE_CUSTOM : PLTYPE_RANDOM)) { u = player(); delwin(w_open); return (opening_screen()); } werase(w_background); wrefresh(w_background); start_game(); start = true; } else if (sel2 == 1) { layer = 3; sel1 = 0; print_menu_items(w_open, vSubItems, sel2, iMenuOffsetY-2, iMenuOffsetX+7); } } } else if (sel1 == 2) { // Load Character if (savegames.size() == 0) mvwprintz(w_open, iMenuOffsetY - 2, 19 + iMenuOffsetX, c_red, "No save games found!"); else { for (int i = 0; i < savegames.size(); i++) { int line = iMenuOffsetY - 2 - i; mvwprintz(w_open, line, 19 + iMenuOffsetX, (sel2 == i ? h_white : c_white), savegames[i].c_str()); } } wrefresh(w_open); refresh(); input = get_input(); if (savegames.size() == 0 && (input == DirectionS || input == Confirm)) { layer = 1; } else if (input == DirectionS) { if (sel2 > 0) sel2--; else sel2 = savegames.size() - 1; } else if (input == DirectionN) { if (sel2 < savegames.size() - 1) sel2++; else sel2 = 0; } else if (input == DirectionW || input == Cancel) { layer = 1; } if (input == DirectionE || input == Confirm) { if (sel2 >= 0 && sel2 < savegames.size()) { werase(w_background); wrefresh(w_background); load(savegames[sel2]); start = true; } } } else if (sel1 == 3) { // Delete world if (query_yn("Delete the world and all saves?")) { delete_save(); savegames.clear(); MAPBUFFER.reset(); MAPBUFFER.make_volatile(); overmap_buffer.clear(); } layer = 1; } else if (sel1 == 4) { // Special game for (int i = 1; i < NUM_SPECIAL_GAMES; i++) { mvwprintz(w_open, iMenuOffsetY-i-1, 34 + iMenuOffsetX, (sel2 == i-1 ? h_white : c_white), special_game_name( special_game_id(i) ).c_str()); } wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionS) { if (sel2 > 0) sel2--; else sel2 = NUM_SPECIAL_GAMES - 2; } else if (input == DirectionN) { if (sel2 < NUM_SPECIAL_GAMES - 2) sel2++; else sel2 = 0; } else if (input == DirectionW || input == Cancel) { layer = 1; } if (input == DirectionE || input == Confirm) { if (sel2 >= 0 && sel2 < NUM_SPECIAL_GAMES - 1) { delete gamemode; gamemode = get_special_game( special_game_id(sel2+1) ); if (!gamemode->init(this)) { delete gamemode; gamemode = new special_game; u = player(); delwin(w_open); return (opening_screen()); } start = true; } } } } else if (layer == 3) { // Character Templates if (templates.size() == 0) mvwprintz(w_open, iMenuOffsetY-4, iMenuOffsetX+27, c_red, "No templates found!"); else { for (int i = 0; i < templates.size(); i++) { int line = iMenuOffsetY - 4 - i; mvwprintz(w_open, line, 27 + iMenuOffsetX, (sel1 == i ? h_white : c_white), templates[i].c_str()); } } wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionS) { if (sel1 > 0) sel1--; else sel1 = templates.size() - 1; } else if (templates.size() == 0 && (input == DirectionN || input == Confirm)) { sel1 = 1; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } else if (input == DirectionN) { if (sel1 < templates.size() - 1) sel1++; else sel1 = 0; } else if (input == DirectionW || input == Cancel || templates.size() == 0) { sel1 = 1; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } else if (input == DirectionE || input == Confirm) { if (!u.create(this, PLTYPE_TEMPLATE, templates[sel1])) { u = player(); delwin(w_open); return (opening_screen()); } werase(w_background); wrefresh(w_background); start_game(); start = true; } } } delwin(w_open); if (start == false) uquit = QUIT_MENU; return start; }
void game::print_menu(WINDOW* w_open, int iSel, const int iMenuOffsetX, int iMenuOffsetY, bool bShowDDA) { //Clear Lines werase(w_open); for (int i = 1; i < 79; i++) mvwputch(w_open, 23, i, c_white, LINE_OXOX); mvwprintz(w_open, 24, 5, c_red, "Please report bugs to [email protected] or post on the forums."); int iLine = 0; const int iOffsetX1 = 3; const int iOffsetX2 = 4; const int iOffsetX3 = 18; const nc_color cColor1 = c_ltcyan; const nc_color cColor2 = c_ltblue; const nc_color cColor3 = c_ltblue; mvwprintz(w_open, iLine++, iOffsetX1, cColor1, "_________ __ .__ "); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, "\\_ ___ \\ _____ _/ |_ _____ ____ | | ___.__ ______ _____ "); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, "/ \\ \\/ \\__ \\ \\ __\\\\__ \\ _/ ___\\ | | < | | / ___/ / \\ "); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, "\\ \\____ / __ \\_ | | / __ \\_\\ \\___ | |__ \\___ | \\___ \\ | Y Y \\"); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, " \\______ /(____ / |__| (____ / \\___ >|____/ / ____|/____ >|__|_| /"); mvwprintz(w_open, iLine++, iOffsetX1, cColor1, " \\/ \\/ \\/ \\/ \\/ \\/ \\/ "); if (bShowDDA) { iLine++; mvwprintz(w_open, iLine++, iOffsetX2, cColor2, "________ .__ ________ "); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, "\\______ \\ _____ _______ | | __ \\______ \\ _____ ___.__ ______"); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, " | | \\ \\__ \\ \\_ __ \\| |/ / | | \\ \\__ \\ < | | / ___/"); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, " | ` \\ / __ \\_ | | \\/| < | ` \\ / __ \\_ \\___ | \\___ \\ "); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, "/_______ /(____ / |__| |__|_ \\ /_______ /(____ / / ____|/____ >"); mvwprintz(w_open, iLine++, iOffsetX2, cColor2, " \\/ \\/ \\/ \\/ \\/ \\/ \\/ "); iLine++; mvwprintz(w_open, iLine++, iOffsetX3, cColor3, " _____ .__ .___"); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, " / _ \\ | |__ ____ _____ __| _/"); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, " / /_\\ \\ | | \\ _/ __ \\ \\__ \\ / __ | "); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, "/ | \\| Y \\\\ ___/ / __ \\_/ /_/ | "); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, "\\____|__ /|___| / \\___ >(____ /\\____ | "); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, " \\/ \\/ \\/ \\/ \\/ "); mvwprintz(w_open, iLine++, iOffsetX3, cColor3, "Version: %s",getVersionString()); } std::vector<std::string> vMenuItems; vMenuItems.push_back("MOTD"); vMenuItems.push_back("New Game"); vMenuItems.push_back("Load"); vMenuItems.push_back("Reset"); vMenuItems.push_back("Special"); vMenuItems.push_back("Options"); vMenuItems.push_back("Help"); vMenuItems.push_back("Credits"); vMenuItems.push_back("Quit"); print_menu_items(w_open, vMenuItems, iSel, iMenuOffsetY, iMenuOffsetX); refresh(); wrefresh(w_open); refresh(); }
void menu_flight(uint8_t mode) { int8_t *value_ptr; menu_range_t range; uint8_t text_link; int8_t temp_gyro_roll = 0; int8_t temp_gyro_pitch = 0; int8_t temp_gyro_yaw = 0; // If submenu item has changed, reset submenu positions if (menu_flag) { sub_top = FLIGHTSTART; menu_flag = 0; } while(button != BACK) { value_ptr = &Config.FlightMode[mode-1].StabMode; // Save pre-edited value for gyro types temp_gyro_roll = Config.FlightMode[mode - 1].Roll_type; temp_gyro_pitch = Config.FlightMode[mode - 1].Pitch_type; temp_gyro_yaw = Config.FlightMode[mode - 1].Yaw_type; // Print menu print_menu_items(sub_top, FLIGHTSTART, value_ptr, 1, (const unsigned char*)flight_menu_ranges, 0, FLIGHTOFFSET, (const unsigned char*)FlightMenuText, cursor); // Handle menu changes update_menu(FLIGHTITEMS, FLIGHTSTART, 0, button, &cursor, &sub_top, &menu_temp); range = get_menu_range ((const unsigned char*)flight_menu_ranges, (menu_temp - FLIGHTSTART)); if (button == ENTER) { text_link = pgm_read_byte(&FlightMenuText[menu_temp - FLIGHTSTART]); do_menu_item(menu_temp, value_ptr + (menu_temp - FLIGHTSTART), 1, range, 0, text_link, false, 0); } // Preset I-limits when gyro mode changes if (button == ENTER) { // If roll gyro type has changed, reset to an appropriate start point if (temp_gyro_roll != Config.FlightMode[mode-1].Roll_type) { // Use Gyro type value to preset limits if(Config.FlightMode[mode-1].Roll_type == LOCK) { Config.FlightMode[mode - 1].Roll_limit = 125; } else { Config.FlightMode[mode - 1].Roll_limit = 0; } } if (temp_gyro_pitch != Config.FlightMode[mode-1].Pitch_type) { if(Config.FlightMode[mode-1].Pitch_type == LOCK) { Config.FlightMode[mode - 1].Pitch_limit = 125; } else { Config.FlightMode[mode - 1].Pitch_limit = 0; } } if (temp_gyro_yaw != Config.FlightMode[mode-1].Yaw_type) { if(Config.FlightMode[mode-1].Yaw_type == LOCK) { Config.FlightMode[mode - 1].Yaw_limit = 125; } else { Config.FlightMode[mode - 1].Yaw_limit = 0; } } UpdateLimits(); // Update I-term limits and triggers based on percentages Save_Config_to_EEPROM(); // Save value and return Wait_BUTTON4(); // Wait for user's finger off the button } } }
bool game::opening_screen() { // Play title music, whoo! play_music( "title" ); world_generator->set_active_world( NULL ); // This actually _loads_ what worlds exist. world_generator->get_all_worlds(); WINDOW *w_background = newwin( TERMY, TERMX, 0, 0 ); WINDOW_PTR w_backgroundptr( w_background ); werase( w_background ); wrefresh( w_background ); // main window should also expand to use available display space. // expanding to evenly use up half of extra space, for now. int extra_w = ( ( TERMX - FULL_SCREEN_WIDTH ) / 2 ) - 1; int extra_h = ( ( TERMY - FULL_SCREEN_HEIGHT ) / 2 ) - 1; extra_w = ( extra_w > 0 ? extra_w : 0 ); extra_h = ( extra_h > 0 ? extra_h : 0 ); const int total_w = FULL_SCREEN_WIDTH + extra_w; const int total_h = FULL_SCREEN_HEIGHT + extra_h; // position of window within main display const int x0 = ( TERMX - total_w ) / 2; const int y0 = ( TERMY - total_h ) / 2; WINDOW *w_open = newwin( total_h, total_w, y0, x0 ); WINDOW_PTR w_openptr( w_open ); const int iMenuOffsetX = 0; int iMenuOffsetY = total_h - 3; // note: if iMenuOffset is changed, // please update MOTD and credits to indicate how long they can be. // fill menu with translated menu items vMenuItems.clear(); vMenuItems.push_back( pgettext( "Main Menu", "<M|m>OTD" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<N|n>ew Game" ) ); vMenuItems.push_back( pgettext( "Main Menu", "Lo<a|A>d" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<W|w>orld" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<S|s>pecial" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<O|o>ptions" ) ); vMenuItems.push_back( pgettext( "Main Menu", "H<e|E|?>lp" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<C|c>redits" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<Q|q>uit" ) ); // determine hotkeys from (possibly translated) menu item text vMenuHotkeys.clear(); for( auto item : vMenuItems ) { vMenuHotkeys.push_back( get_hotkeys( item ) ); } std::vector<std::string> vSubItems; vSubItems.push_back( pgettext( "Main Menu|New Game", "<C|c>ustom Character" ) ); vSubItems.push_back( pgettext( "Main Menu|New Game", "<P|p>reset Character" ) ); vSubItems.push_back( pgettext( "Main Menu|New Game", "<R|r>andom Character" ) ); if( !MAP_SHARING::isSharing() ) { // "Play Now" function doesn't play well together with shared maps vSubItems.push_back( pgettext( "Main Menu|New Game", "Play <N|n>ow!" ) ); } std::vector<std::vector<std::string>> vNewGameHotkeys; for( auto item : vSubItems ) { vNewGameHotkeys.push_back( get_hotkeys( item ) ); } std::vector<std::string> vWorldSubItems; vWorldSubItems.push_back( pgettext( "Main Menu|World", "<C|c>reate World" ) ); vWorldSubItems.push_back( pgettext( "Main Menu|World", "<D|d>elete World" ) ); vWorldSubItems.push_back( pgettext( "Main Menu|World", "<R|r>eset World" ) ); std::vector<std::vector<std::string>> vWorldHotkeys; for( auto item : vWorldSubItems ) { vWorldHotkeys.push_back( get_hotkeys( item ) ); } mmenu_refresh_title(); print_menu( w_open, 0, iMenuOffsetX, iMenuOffsetY ); std::vector<std::string> savegames, templates; dirent *dp; DIR *dir; if( !assure_dir_exist( FILENAMES["config_dir"] ) ) { popup( _( "Unable to make config directory. Check permissions." ) ); return false; } if( !assure_dir_exist( FILENAMES["savedir"] ) ) { popup( _( "Unable to make save directory. Check permissions." ) ); return false; } if( !assure_dir_exist( FILENAMES["templatedir"] ) ) { popup( _( "Unable to make templates directory. Check permissions." ) ); return false; } dir = opendir( FILENAMES["templatedir"].c_str() ); while( ( dp = readdir( dir ) ) ) { std::string tmp = dp->d_name; if( tmp.find( ".template" ) != std::string::npos ) { templates.push_back( tmp.substr( 0, tmp.find( ".template" ) ) ); } } closedir( dir ); int sel1 = 1, sel2 = 1, sel3 = 1, layer = 1; input_context ctxt( "MAIN_MENU" ); ctxt.register_cardinal(); ctxt.register_action( "QUIT" ); ctxt.register_action( "CONFIRM" ); ctxt.register_action( "DELETE_TEMPLATE" ); // for the menu shortcuts ctxt.register_action( "ANY_INPUT" ); bool start = false; // Load MOTD and Credits, load it once as it shouldn't change for the duration of the application being open mmenu_refresh_motd(); mmenu_refresh_credits(); u = player(); while( !start ) { print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY, ( sel1 == 0 || sel1 == 7 ) ? false : true ); if( layer == 1 ) { if( sel1 == 0 ) { // Print the MOTD. const int motdy = ( iMenuOffsetY - mmenu_motd.size() ) * 2 / 3; const int motdx = 8 + extra_w / 2; for( size_t i = 0; i < mmenu_motd.size(); i++ ) { mvwprintz( w_open, motdy + i, motdx, c_ltred, mmenu_motd[i].c_str() ); } wrefresh( w_open ); refresh(); } else if( sel1 == 7 ) { // Print the Credits. const int credy = ( iMenuOffsetY - mmenu_credits.size() ) * 2 / 3; const int credx = 8 + extra_w / 2; for( size_t i = 0; i < mmenu_credits.size(); i++ ) { mvwprintz( w_open, credy + i, credx, c_ltred, mmenu_credits[i].c_str() ); } wrefresh( w_open ); refresh(); } std::string action = ctxt.handle_input(); std::string sInput = ctxt.get_raw_input().text; // check automatic menu shortcuts for( size_t i = 0; i < vMenuHotkeys.size(); ++i ) { for( auto hotkey : vMenuHotkeys[i] ) { if( sInput == hotkey ) { sel1 = i; action = "CONFIRM"; } } } // also check special keys if( action == "QUIT" ) { // Quit sel1 = 8; action = "CONFIRM"; } else if( action == "LEFT" ) { if( sel1 > 0 ) { sel1--; } else { sel1 = 8; } sfx::play_variant_sound( "menu_move", "default", 100 ); } else if( action == "RIGHT" ) { if( sel1 < 8 ) { sel1++; } else { sel1 = 0; } sfx::play_variant_sound( "menu_move", "default", 100 ); } if( ( action == "UP" || action == "CONFIRM" ) && sel1 > 0 && sel1 != 7 ) { if( sel1 == 5 ) { get_options().show(); } else if( sel1 == 6 ) { display_help(); } else if( sel1 == 8 ) { uquit = QUIT_MENU; return false; } else { sel2 = 0; layer = 2; print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY, ( sel1 == 0 || sel1 == 7 ) ? false : true ); } } } else if( layer == 2 ) { if( sel1 == 1 ) { // New Character if( MAP_SHARING::isSharing() && world_generator->all_worlds.empty() ) { //don't show anything when there are no worlds (will not work if there are special maps) layer = 1; sel1 = 1; continue; } print_menu_items( w_open, vSubItems, sel2, iMenuOffsetY - 2, iMenuOffsetX ); wrefresh( w_open ); refresh(); std::string action = ctxt.handle_input(); std::string sInput = ctxt.get_raw_input().text; for( size_t i = 0; i < vNewGameHotkeys.size(); ++i ) { for( auto hotkey : vNewGameHotkeys[i] ) { if( sInput == hotkey ) { sel2 = i; action = "CONFIRM"; } } } if( action == "LEFT" ) { sel2--; if( sel2 < 0 ) { sel2 = vSubItems.size() - 1; } } else if( action == "RIGHT" ) { sel2++; if( sel2 >= ( int )vSubItems.size() ) { sel2 = 0; } } else if( action == "DOWN" || action == "QUIT" ) { layer = 1; sel1 = 1; } if( action == "UP" || action == "CONFIRM" ) { if( sel2 == 0 || sel2 == 2 || sel2 == 3 ) { // First load the mods, this is done by // loading the world. // Pick a world, suppressing prompts if it's "play now" mode. WORLDPTR world = world_generator->pick_world( sel2 != 3 ); if( world == NULL ) { continue; } world_generator->set_active_world( world ); setup(); if( !u.create( sel2 == 0 ? PLTYPE_CUSTOM : ( sel2 == 2 ? PLTYPE_RANDOM : PLTYPE_NOW ) ) ) { u = player(); continue; } werase( w_background ); wrefresh( w_background ); if( !start_game( world->world_name ) ) { u = player(); continue; } start = true; } else if( sel2 == 1 ) { layer = 3; sel3 = 0; } } } else if( sel1 == 2 ) { // Load Character if( world_generator->all_worldnames.empty() ) { mvwprintz( w_open, iMenuOffsetY - 2, 15 + iMenuOffsetX + extra_w / 2, c_red, _( "No Worlds found!" ) ); } else { for( int i = 0; i < ( int )world_generator->all_worldnames.size(); ++i ) { int line = iMenuOffsetY - 2 - i; std::string world_name = world_generator->all_worldnames[i]; int savegames_count = world_generator->all_worlds[world_name]->world_saves.size(); nc_color color1, color2; if( world_name == "TUTORIAL" || world_name == "DEFENSE" ) { color1 = c_ltcyan; color2 = h_ltcyan; } else { if( world_generator->world_need_lua_build( world_name ) ) { color1 = c_dkgray; color2 = h_dkgray; } else { color1 = c_white; color2 = h_white; } } mvwprintz( w_open, line, 15 + iMenuOffsetX + extra_w / 2, ( sel2 == i ? color2 : color1 ), "%s (%d)", world_name.c_str(), savegames_count ); } } wrefresh( w_open ); refresh(); const std::string action = ctxt.handle_input(); if( world_generator->all_worldnames.empty() && ( action == "DOWN" || action == "CONFIRM" ) ) { layer = 1; } else if( action == "DOWN" ) { if( sel2 > 0 ) { sel2--; } else { sel2 = world_generator->all_worldnames.size() - 1; } } else if( action == "UP" ) { if( sel2 < ( int )world_generator->all_worldnames.size() - 1 ) { sel2++; } else { sel2 = 0; } } else if( action == "LEFT" || action == "QUIT" ) { layer = 1; } else if( action == "RIGHT" || action == "CONFIRM" ) { if( sel2 >= 0 && sel2 < ( int )world_generator->all_worldnames.size() ) { layer = 3; sel3 = 0; } } } else if( sel1 == 3 ) { // World Menu // Show options for Create, Destroy, Reset worlds. // Create world goes directly to Make World screen. // Reset and Destroy ask for world to modify. // Reset empties world of everything but options, then makes new world within it. // Destroy asks for confirmation, then destroys everything in world and then removes world folder. // only show reset / destroy world if there is at least one valid world existing! if( MAP_SHARING::isSharing() && !MAP_SHARING::isWorldmenu() && !MAP_SHARING::isAdmin() ) { layer = 1; popup( _( "Only the admin can change worlds." ) ); continue; } int world_subs_to_display = ( !world_generator->all_worldnames.empty() ) ? vWorldSubItems.size() : 1; std::vector<std::string> world_subs; int xoffset = 25 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2; int xlen = 0; for( int i = 0; i < world_subs_to_display; ++i ) { world_subs.push_back( vWorldSubItems[i] ); xlen += vWorldSubItems[i].size() + 2; // Open and close brackets added } xlen += world_subs.size() - 1; if( world_subs.size() > 1 ) { xoffset -= 6; } print_menu_items( w_open, world_subs, sel2, yoffset, xoffset - ( xlen / 4 ) ); wrefresh( w_open ); refresh(); std::string action = ctxt.handle_input(); std::string sInput = ctxt.get_raw_input().text; for( int i = 0; i < world_subs_to_display; ++i ) { for( auto hotkey : vWorldHotkeys[i] ) { if( sInput == hotkey ) { sel2 = i; action = "CONFIRM"; } } } if( action == "LEFT" ) { if( sel2 > 0 ) { --sel2; } else { sel2 = world_subs_to_display - 1; } } else if( action == "RIGHT" ) { if( sel2 < world_subs_to_display - 1 ) { ++sel2; } else { sel2 = 0; } } else if( action == "DOWN" || action == "QUIT" ) { layer = 1; } if( action == "UP" || action == "CONFIRM" ) { if( sel2 == 0 ) { // Create world // Open up world creation screen! if( world_generator->make_new_world() ) { return opening_screen(); } else { layer = 1; } } else if( sel2 == 1 || sel2 == 2 ) { // Delete World | Reset World layer = 3; sel3 = 0; } } } else if( sel1 == 4 ) { // Special game if( MAP_SHARING::isSharing() ) { // Thee can't save special games, therefore thee can't share them layer = 1; popup( _( "Special games don't work with shared maps." ) ); continue; } std::vector<std::string> special_names; int xoffset = 32 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2; int xlen = 0; for( int i = 1; i < NUM_SPECIAL_GAMES; i++ ) { std::string spec_name = special_game_name( special_game_id( i ) ); special_names.push_back( spec_name ); xlen += spec_name.size() + 2; } xlen += special_names.size() - 1; print_menu_items( w_open, special_names, sel2, yoffset, xoffset - ( xlen / 4 ) ); wrefresh( w_open ); refresh(); std::string action = ctxt.handle_input(); if( action == "LEFT" ) { if( sel2 > 0 ) { sel2--; } else { sel2 = NUM_SPECIAL_GAMES - 2; } } else if( action == "RIGHT" ) { if( sel2 < NUM_SPECIAL_GAMES - 2 ) { sel2++; } else { sel2 = 0; } } else if( action == "DOWN" || action == "QUIT" ) { layer = 1; } if( action == "UP" || action == "CONFIRM" ) { if( sel2 >= 0 && sel2 < NUM_SPECIAL_GAMES - 1 ) { gamemode = get_special_game( special_game_id( sel2 + 1 ) ); // check world WORLDPTR world = world_generator->make_new_world( special_game_id( sel2 + 1 ) ); if( world == NULL ) { continue; } world_generator->set_active_world( world ); setup(); if( !gamemode->init() ) { gamemode.reset(); u = player(); continue; } start = true; } } } } else if( layer == 3 ) { bool available = false; if( sel1 == 2 ) { // Load Game savegames = world_generator->all_worlds[world_generator->all_worldnames[sel2]]->world_saves; std::string wn = world_generator->all_worldnames[sel2]; //hide savegames if lua is not available for a lua-built world if( ( wn != "TUTORIAL" && wn != "DEFENSE" ) && world_generator->world_need_lua_build( wn ) ) { savegames.clear(); mvwprintz( w_open, iMenuOffsetY - 2, 15 + iMenuOffsetX + extra_w / 2, c_red, _( "This world requires the game to be compiled with Lua." ) ); } else if( savegames.empty() ) { mvwprintz( w_open, iMenuOffsetY - 2, 19 + 19 + iMenuOffsetX + extra_w / 2, c_red, _( "No save games found!" ) ); } else { for( std::vector<std::string>::iterator it = savegames.begin(); it != savegames.end(); ) { std::string savename = base64_decode( *it ); if( MAP_SHARING::isSharing() && savename != MAP_SHARING::getUsername() ) { it = savegames.erase( it ); } else { // calculates the index from distance between it and savegames.begin() int i = it - savegames.begin(); available = true; int line = iMenuOffsetY - 2 - i; mvwprintz( w_open, line, 19 + 19 + iMenuOffsetX + extra_w / 2, ( sel3 == i ? h_white : c_white ), base64_decode( *it ).c_str() ); ++it; } } if( !available ) { mvwprintz( w_open, iMenuOffsetY - 2, 19 + 19 + iMenuOffsetX + extra_w / 2, c_red, _( "No save games found!" ) ); } } wrefresh( w_open ); refresh(); std::string action = ctxt.handle_input(); if( savegames.empty() && ( action == "DOWN" || action == "CONFIRM" ) ) { layer = 2; } else if( action == "DOWN" ) { if( sel3 > 0 ) { sel3--; } else { sel3 = savegames.size() - 1; } } else if( action == "UP" ) { if( sel3 < ( int )savegames.size() - 1 ) { sel3++; } else { sel3 = 0; } } else if( action == "LEFT" || action == "QUIT" ) { layer = 2; sel3 = 0; print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY ); } if( action == "RIGHT" || action == "CONFIRM" ) { if( sel3 >= 0 && sel3 < ( int )savegames.size() ) { werase( w_background ); wrefresh( w_background ); WORLDPTR world = world_generator->all_worlds[world_generator->all_worldnames[sel2]]; world_generator->set_active_world( world ); setup(); load( world->world_name, savegames[sel3] ); start = true; } } } else if( sel1 == 3 ) { // Show world names int i = 0; for( std::vector<std::string>::iterator it = world_generator->all_worldnames.begin(); it != world_generator->all_worldnames.end(); ++it ) { int savegames_count = world_generator->all_worlds[*it]->world_saves.size(); int line = iMenuOffsetY - 4 - i; nc_color color1, color2; if( *it == "TUTORIAL" || *it == "DEFENSE" ) { color1 = c_ltcyan; color2 = h_ltcyan; } else { color1 = c_white; color2 = h_white; } mvwprintz( w_open, line, 26 + iMenuOffsetX + extra_w / 2, ( sel3 == i ? color2 : color1 ), "%s (%d)", ( *it ).c_str(), savegames_count ); ++i; } wrefresh( w_open ); refresh(); std::string action = ctxt.handle_input(); if( action == "DOWN" ) { if( sel3 > 0 ) { --sel3; } else { sel3 = world_generator->all_worldnames.size() - 1; } } else if( action == "UP" ) { if( sel3 < ( int )world_generator->all_worldnames.size() - 1 ) { ++sel3; } else { sel3 = 0; } } else if( action == "LEFT" || action == "QUIT" ) { layer = 2; print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY ); } if( action == "RIGHT" || action == "CONFIRM" ) { if( sel3 >= 0 && sel3 < ( int )world_generator->all_worldnames.size() ) { bool query_yes = false; bool do_delete = false; if( sel2 == 1 ) { // Delete World if( query_yn( _( "Delete the world and all saves?" ) ) ) { query_yes = true; do_delete = true; } } else if( sel2 == 2 ) { // Reset World if( query_yn( _( "Remove all saves and regenerate world?" ) ) ) { query_yes = true; do_delete = false; } } if( query_yes ) { delete_world( world_generator->all_worldnames[sel3], do_delete ); savegames.clear(); MAPBUFFER.reset(); overmap_buffer.clear(); layer = 2; if( do_delete ) { // delete world and all contents world_generator->remove_world( world_generator->all_worldnames[sel3] ); } else { // clear out everything but worldoptions from this world world_generator->all_worlds[world_generator->all_worldnames[sel3]]->world_saves.clear(); } if( world_generator->all_worldnames.empty() ) { sel2 = 0; // reset to create world selection } } else { // hacky resolution to the issue of persisting world names on the screen return opening_screen(); } } print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY ); } } else { // Character Templates if( templates.empty() ) { mvwprintz( w_open, iMenuOffsetY - 4, iMenuOffsetX + 20 + extra_w / 2, c_red, _( "No templates found!" ) ); } else { mvwprintz( w_open, iMenuOffsetY - 2, iMenuOffsetX + 20 + extra_w / 2, c_white, _( "Press 'd' to delete a preset." ) ); for( int i = 0; i < ( int )templates.size(); i++ ) { int line = iMenuOffsetY - 4 - i; mvwprintz( w_open, line, 20 + iMenuOffsetX + extra_w / 2, ( sel3 == i ? h_white : c_white ), templates[i].c_str() ); } } wrefresh( w_open ); refresh(); std::string action = ctxt.handle_input(); if( action == "DOWN" ) { if( sel3 > 0 ) { sel3--; } else { sel3 = templates.size() - 1; } } else if( templates.empty() && ( action == "UP" || action == "CONFIRM" ) ) { sel1 = 1; layer = 2; print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY ); } else if( action == "UP" ) { if( sel3 < ( int )templates.size() - 1 ) { sel3++; } else { sel3 = 0; } } else if( action == "LEFT" || action == "QUIT" || templates.empty() ) { sel1 = 1; layer = 2; print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY ); } else if( !templates.empty() && action == "DELETE_TEMPLATE" ) { if( query_yn( _( "Are you sure you want to delete %s?" ), templates[sel3].c_str() ) ) { const auto path = FILENAMES["templatedir"] + templates[sel3] + ".template"; if( std::remove( path.c_str() ) != 0 ) { popup( _( "Sorry, something went wrong." ) ); } else { templates.erase( templates.begin() + sel3 ); if( ( size_t )sel3 > templates.size() - 1 ) { sel3--; } } } } else if( action == "RIGHT" || action == "CONFIRM" ) { WORLDPTR world = world_generator->pick_world(); if( world == NULL ) { u = player(); continue; } world_generator->set_active_world( world ); setup(); if( !u.create( PLTYPE_TEMPLATE, templates[sel3] ) ) { u = player(); continue; } werase( w_background ); wrefresh( w_background ); if( !start_game( world_generator->active_world->world_name ) ) { u = player(); continue; } start = true; } } } } w_openptr.reset(); w_backgroundptr.reset(); if( start == false ) { uquit = QUIT_MENU; } else { refresh_all(); draw(); } return start; }
void menu_rc_setup(uint8_t section) { static uint8_t rc_top = RCSTART; int8_t *value_ptr; menu_range_t range; uint8_t text_link; uint8_t i = 0; uint8_t mult = 1; // Multiplier uint8_t offset; // Index into channel structure uint8_t items; // Items in group uint16_t temp16_1; // If submenu item has changed, reset submenu positions if (menu_flag) { rc_top = RCSTART; menu_flag = 0; } while(button != BACK) { // Get menu offsets and load values from eeprom // 1 = RC, 2 = Failsafe, 3 = General, 4 = Battery switch(section) { case 1: // RC setup menu offset = 0; items = RCITEMS; value_ptr = &Config.RxMode; mult = 1; break; case 2: // Failsafe menu offset = RCITEMS; items = FSITEMS; value_ptr = &Config.FailsafeType; mult = 1; break; case 3: // General menu offset = RCITEMS + FSITEMS; items = GENERALITEMS; value_ptr = &Config.MixMode; mult = 1; break; case 4: // Battery menu offset = RCITEMS + FSITEMS + GENERALITEMS; items = BATTITEMS; value_ptr = &Config.BatteryType; mult = 4; break; default: offset = 0; items = RCITEMS; value_ptr = &Config.RxMode; mult = 1; break; } // Save pre-edited values int8_t temp_type = Config.MixMode; int8_t temp_cells = Config.BatteryCells; int8_t temp_minvoltage = Config.MinVoltage; int8_t temp_flapchan = Config.FlapChan; // Print menu print_menu_items(rc_top + offset, RCSTART + offset, value_ptr, mult, (prog_uchar*)rc_menu_ranges[section - 1], 0, RCOFFSET, (prog_uchar*)RCMenuText[section - 1], cursor); // Handle menu changes update_menu(items, RCSTART, offset, button, &cursor, &rc_top, &menu_temp); range = get_menu_range ((prog_uchar*)rc_menu_ranges[section - 1], (menu_temp - RCSTART - offset)); if (button == ENTER) { text_link = pgm_read_byte(&RCMenuText[section - 1][menu_temp - RCSTART - offset]); do_menu_item(menu_temp, value_ptr + (menu_temp - RCSTART - offset), mult, range, 0, text_link, false, 0); } if (button == ENTER) { // Update Ch7. mixer with source from Config.FlapChan if in Aeroplane mode and source changed if ((Config.MixMode == AEROPLANE) && (Config.FlapChan != temp_flapchan)) { Config.Channel[CH7].source_a = Config.FlapChan; } // See if cell number or min_volts has changed if ((temp_cells != Config.BatteryCells) || (temp_minvoltage != Config.MinVoltage)) { // Recalculate if more cells temp16_1 = Config.MinVoltage; temp16_1 = temp16_1 * Config.BatteryCells; temp16_1 = temp16_1 / 10; Config.PowerTrigger = (int8_t)temp16_1; } // If model type has changed, reload preset if ((section == 3) && (temp_type != Config.MixMode)) { switch(Config.MixMode) // Load selected mix { case AEROPLANE: get_preset_mix(AEROPLANE_MIX); break; case FWING: get_preset_mix(FLYING_WING_MIX); break; case CAMSTAB: get_preset_mix(CAM_STAB); break; case MANUAL: // Clear all channel info memset(&Config.Channel[0].value,0,(sizeof(channel_t) * PSUEDO_OUTPUTS)); // Preset important settings for (i = 0; i < PSUEDO_OUTPUTS; i++) { Config.Channel[i].source_a = NOCHAN; Config.Channel[i].source_b = NOCHAN; Config.Channel[i].output_b = UNUSED; Config.Channel[i].output_c = UNUSED; Config.Channel[i].output_d = UNUSED; } break; default: break; } } init_int(); // In case RC type has changed, reinitialise interrupts init_uart(); // and UART UpdateIMUvalues(); // Update IMU variables UpdateLimits(); // Update I-term limits and triggers based on percentages #ifdef KK21 // Update MPU6050 LPF writeI2Cbyte(MPU60X0_DEFAULT_ADDRESS, MPU60X0_RA_CONFIG, Config.MPU6050_LPF); #endif // Update channel sequence for (i = 0; i < MAX_RC_CHANNELS; i++) { if (Config.TxSeq == FUTABASEQ) { Config.ChannelOrder[i] = (uint8_t)pgm_read_byte(&FUTABA[i]); } else { Config.ChannelOrder[i] = (uint8_t)pgm_read_byte(&JR[i]); } } Save_Config_to_EEPROM(); // Save value and return } } }
void menu_servo_setup(uint8_t section) { int8_t *value_ptr = &Config.Servo_reverse[0]; menu_range_t range; uint8_t text_link; uint8_t i = 0; bool servo_enable = false; bool zero_setting = false; // If submenu item has changed, reset submenu positions if (menu_flag) { sub_top = SERVOSTART; menu_flag = 0; } // Get menu offsets // 1 = Reverse, 2 = Min, 3 = Max while(button != BACK) { // Load values from eeprom for (i = 0; i < SERVOITEMS; i++) { switch(section) { case 1: break; case 2: value_ptr = &Config.min_travel[0]; servo_enable = true; zero_setting = true; break; case 3: value_ptr = &Config.max_travel[0]; servo_enable = true; zero_setting = true; break; default: break; } } // Print menu print_menu_items(sub_top, SERVOSTART, value_ptr, 1, (const unsigned char*)servo_menu_ranges[section - 1], 1, SERVOOFFSET, (const unsigned char*)ServoMenuText[section - 1], cursor); // Handle menu changes update_menu(SERVOITEMS, SERVOSTART, 0, button, &cursor, &sub_top, &menu_temp); range = get_menu_range ((const unsigned char*)servo_menu_ranges[section - 1], 0); if (button == ENTER) { text_link = pgm_read_byte(&ServoMenuText[section - 1][menu_temp - SERVOSTART]); // Zero limits if adjusting if (zero_setting) { value_ptr[menu_temp - SERVOSTART] = 0; } // Do not allow servo enable for throttle if in CPPM mode if ((Config.Channel[menu_temp - SERVOSTART].P1_source_a == THROTTLE) && (Config.RxMode == CPPM_MODE)) { servo_enable = false; } do_menu_item(menu_temp, value_ptr + (menu_temp - SERVOSTART), 1, range, 0, text_link, servo_enable, (menu_temp - SERVOSTART)); } // Disable servos servo_enable = false; if (button == ENTER) { UpdateLimits(); // Update actual servo trims Save_Config_to_EEPROM(); // Save value and return } } }
bool main_menu::opening_screen() { // Play title music, whoo! play_music( "title" ); world_generator->set_active_world( NULL ); world_generator->init(); init_windows(); init_strings(); print_menu( w_open, 0, iMenuOffsetX, iMenuOffsetY ); if( !assure_dir_exist( FILENAMES["config_dir"] ) ) { popup( _( "Unable to make config directory. Check permissions." ) ); return false; } if( !assure_dir_exist( FILENAMES["savedir"] ) ) { popup( _( "Unable to make save directory. Check permissions." ) ); return false; } if( !assure_dir_exist( FILENAMES["templatedir"] ) ) { popup( _( "Unable to make templates directory. Check permissions." ) ); return false; } for( std::string path : get_files_from_path( ".template", FILENAMES["templatedir"], false, true ) ) { path = native_to_utf8( path ); path.erase( path.find( ".template" ), std::string::npos ); path.erase( 0, path.find_last_of( "\\//" ) + 1 ); templates.push_back( path ); } std::sort( templates.begin(), templates.end(), std::greater<std::string>() ); ctxt.register_cardinal(); ctxt.register_action( "QUIT" ); ctxt.register_action( "CONFIRM" ); ctxt.register_action( "DELETE_TEMPLATE" ); // for the menu shortcuts ctxt.register_action( "ANY_INPUT" ); bool start = false; g->u = player(); // Make [Load Game] the default cursor position if there's game save available if( !world_generator->all_worldnames().empty() ) { sel1 = 2; } while( !start ) { print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY, ( sel1 != 0 ) ); if( layer == 1 ) { if( sel1 == 0 ) { // Print the MOTD. const int motdy = ( iMenuOffsetY - mmenu_motd.size() ) * 2 / 3; const int motdx = 8 + extra_w / 2; for( size_t i = 0; i < mmenu_motd.size(); i++ ) { mvwprintz( w_open, motdy + i, motdx, c_light_red, mmenu_motd[i].c_str() ); } wrefresh( w_open ); catacurses::refresh(); } std::string action = handle_input_timeout( ctxt ); std::string sInput = ctxt.get_raw_input().text; // check automatic menu shortcuts for( size_t i = 0; i < vMenuHotkeys.size(); ++i ) { for( auto hotkey : vMenuHotkeys[i] ) { if( sInput == hotkey ) { sel1 = i; action = "CONFIRM"; } } } // also check special keys if( action == "QUIT" ) { if( query_yn( _( "Really quit?" ) ) ) { sel1 = 8; action = "CONFIRM"; } } else if( action == "LEFT" ) { if( sel1 > 0 ) { sel1--; } else { sel1 = 8; } on_move(); } else if( action == "RIGHT" ) { if( sel1 < 8 ) { sel1++; } else { sel1 = 0; } on_move(); } if( ( action == "UP" || action == "CONFIRM" ) && sel1 > 0 ) { if( sel1 == 6 ) { display_help(); } else if( sel1 == 7 ) { display_credits(); } else if( sel1 == 8 ) { return false; } else { sel2 = 0; layer = 2; print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY, ( sel1 != 0 ) ); switch( sel1 ) { case 1: start = new_character_tab(); break; case 2: start = load_character_tab(); break; case 3: world_tab(); break; default: break; } } } } else if( layer == 2 ) { if( sel1 == 4 ) { // Special game if( MAP_SHARING::isSharing() ) { // Thee can't save special games, therefore thee can't share them layer = 1; popup( _( "Special games don't work with shared maps." ) ); continue; } std::vector<std::string> special_names; int xoffset = 32 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2; int xlen = 0; for( int i = 1; i < NUM_SPECIAL_GAMES; i++ ) { std::string spec_name = special_game_name( special_game_id( i ) ); special_names.push_back( spec_name ); xlen += spec_name.size() + 2; } xlen += special_names.size() - 1; print_menu_items( w_open, special_names, sel2, yoffset, xoffset - ( xlen / 4 ) ); wrefresh( w_open ); catacurses::refresh(); std::string action = handle_input_timeout( ctxt ); if( action == "LEFT" ) { if( sel2 > 0 ) { sel2--; } else { sel2 = NUM_SPECIAL_GAMES - 2; } on_move(); } else if( action == "RIGHT" ) { if( sel2 < NUM_SPECIAL_GAMES - 2 ) { sel2++; } else { sel2 = 0; } on_move(); } else if( action == "DOWN" || action == "QUIT" ) { layer = 1; } if( action == "UP" || action == "CONFIRM" ) { if( sel2 >= 0 && sel2 < NUM_SPECIAL_GAMES - 1 ) { g->gamemode = get_special_game( special_game_id( sel2 + 1 ) ); // check world WORLDPTR world = world_generator->make_new_world( special_game_id( sel2 + 1 ) ); if( world == NULL ) { continue; } world_generator->set_active_world( world ); try { g->setup(); } catch( const std::exception &err ) { debugmsg( "Error: %s", err.what() ); g->gamemode.reset(); g->u = player(); continue; } if( !g->gamemode->init() ) { g->gamemode.reset(); g->u = player(); continue; } start = true; } } } else if( sel1 == 5 ) { // Settings Menu int settings_subs_to_display = vSettingsSubItems.size(); std::vector<std::string> settings_subs; int xoffset = 46 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2; int xlen = 0; for( int i = 0; i < settings_subs_to_display; ++i ) { settings_subs.push_back( vSettingsSubItems[i] ); xlen += vSettingsSubItems[i].size() + 2; // Open and close brackets added } xlen += settings_subs.size() - 1; if( settings_subs.size() > 1 ) { xoffset -= 6; } print_menu_items( w_open, settings_subs, sel2, yoffset, xoffset - ( xlen / 4 ) ); wrefresh( w_open ); catacurses::refresh(); std::string action = handle_input_timeout( ctxt ); std::string sInput = ctxt.get_raw_input().text; for( int i = 0; i < settings_subs_to_display; ++i ) { for( auto hotkey : vSettingsHotkeys[i] ) { if( sInput == hotkey ) { sel2 = i; action = "CONFIRM"; } } } if( action == "LEFT" ) { if( sel2 > 0 ) { --sel2; } else { sel2 = settings_subs_to_display - 1; } on_move(); } else if( action == "RIGHT" ) { if( sel2 < settings_subs_to_display - 1 ) { ++sel2; } else { sel2 = 0; } on_move(); } else if( action == "DOWN" || action == "QUIT" ) { layer = 1; } if( action == "UP" || action == "CONFIRM" ) { if( sel2 == 0 ) { get_options().show( true ); // The language may have changed- gracefully handle this. init_strings(); print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY, ( sel1 != 0 ) ); } else if( sel2 == 1 ) { input_context ctxt_default = get_default_mode_input_context(); ctxt_default.display_menu(); } else if( sel2 == 2 ) { get_auto_pickup().show(); } else if( sel2 == 3 ) { get_safemode().show(); } else if( sel2 == 4 ) { all_colors.show_gui(); } } } } } if( start ) { g->refresh_all(); g->draw(); } return start; }
bool main_menu::new_character_tab() { std::vector<std::string> vSubItems; vSubItems.push_back( pgettext( "Main Menu|New Game", "<C|c>ustom Character" ) ); vSubItems.push_back( pgettext( "Main Menu|New Game", "<P|p>reset Character" ) ); vSubItems.push_back( pgettext( "Main Menu|New Game", "<R|r>andom Character" ) ); if( !MAP_SHARING::isSharing() ) { // "Play Now" function doesn't play well together with shared maps vSubItems.push_back( pgettext( "Main Menu|New Game", "Play Now! (<F|f>ixed Scenario)" ) ); vSubItems.push_back( pgettext( "Main Menu|New Game", "Play <N|n>ow!" ) ); } std::vector<std::vector<std::string>> vNewGameHotkeys; for( auto item : vSubItems ) { vNewGameHotkeys.push_back( get_hotkeys( item ) ); } bool start = false; while( !start && sel1 == 1 && ( layer == 2 || layer == 3 ) ) { print_menu( w_open, 1, iMenuOffsetX, iMenuOffsetY, true ); if( layer == 2 && sel1 == 1 ) { // Then choose custom character, random character, preset, etc if( MAP_SHARING::isSharing() && world_generator->all_worldnames().empty() ) { //don't show anything when there are no worlds (will not work if there are special maps) layer = 1; sel1 = 1; continue; } print_menu_items( w_open, vSubItems, sel2, iMenuOffsetY - 2, iMenuOffsetX ); wrefresh( w_open ); catacurses::refresh(); std::string action = handle_input_timeout( ctxt ); std::string sInput = ctxt.get_raw_input().text; for( size_t i = 0; i < vNewGameHotkeys.size(); ++i ) { for( auto hotkey : vNewGameHotkeys[i] ) { if( sInput == hotkey ) { sel2 = i; action = "CONFIRM"; } } } if( action == "LEFT" ) { sel2--; if( sel2 < 0 ) { sel2 = vSubItems.size() - 1; } on_move(); } else if( action == "RIGHT" ) { sel2++; if( sel2 >= ( int )vSubItems.size() ) { sel2 = 0; } on_move(); } else if( action == "DOWN" || action == "QUIT" ) { layer = 1; sel1 = 1; } if( action == "UP" || action == "CONFIRM" ) { if( sel2 == 0 || sel2 == 2 || sel2 == 3 || sel2 == 4 ) { // First load the mods, this is done by // loading the world. // Pick a world, suppressing prompts if it's "play now" mode. WORLDPTR world = world_generator->pick_world( sel2 != 3 && sel2 != 4 ); if( world == NULL ) { continue; } world_generator->set_active_world( world ); try { g->setup(); } catch( const std::exception &err ) { debugmsg( "Error: %s", err.what() ); g->u = player(); continue; } character_type play_type = PLTYPE_CUSTOM; switch( sel2 ) { case 0: play_type = PLTYPE_CUSTOM; break; case 2: play_type = PLTYPE_RANDOM; break; case 3: play_type = PLTYPE_NOW; break; case 4: play_type = PLTYPE_FULL_RANDOM; break; } if( !g->u.create( play_type ) ) { g->u = player(); werase( w_background ); wrefresh( w_background ); continue; } werase( w_background ); wrefresh( w_background ); if( !g->start_game() ) { g->u = player(); continue; } start = true; } else if( sel2 == 1 ) { layer = 3; sel3 = 0; } } } else if( layer == 3 && sel1 == 1 ) { // Then view presets if( templates.empty() ) { mvwprintz( w_open, iMenuOffsetY - 4, iMenuOffsetX + 20 + extra_w / 2, c_red, _( "No templates found!" ) ); sfx::play_variant_sound( "menu_error", "default", 100 ); } else { mvwprintz( w_open, iMenuOffsetY - 2, iMenuOffsetX + 20 + extra_w / 2, c_white, _( "Press 'd' to delete a preset." ) ); for( int i = 0; i < ( int )templates.size(); i++ ) { int line = iMenuOffsetY - 4 - i; mvwprintz( w_open, line, 20 + iMenuOffsetX + extra_w / 2, ( sel3 == i ? h_white : c_white ), templates[i].c_str() ); } } wrefresh( w_open ); catacurses::refresh(); std::string action = handle_input_timeout( ctxt ); if( action == "DOWN" ) { if( sel3 > 0 ) { sel3--; } else { sel3 = templates.size() - 1; } } else if( templates.empty() && ( action == "UP" || action == "CONFIRM" ) ) { sel1 = 1; layer = 2; print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY ); } else if( action == "UP" ) { if( sel3 < ( int )templates.size() - 1 ) { sel3++; } else { sel3 = 0; } } else if( action == "LEFT" || action == "QUIT" || templates.empty() ) { sel1 = 1; layer = 2; print_menu( w_open, sel1, iMenuOffsetX, iMenuOffsetY ); } else if( !templates.empty() && action == "DELETE_TEMPLATE" ) { if( query_yn( _( "Are you sure you want to delete %s?" ), templates[sel3].c_str() ) ) { const auto path = FILENAMES["templatedir"] + utf8_to_native( templates[sel3] ) + ".template"; if( std::remove( path.c_str() ) != 0 ) { popup( _( "Sorry, something went wrong." ) ); } else { templates.erase( templates.begin() + sel3 ); if( ( size_t )sel3 > templates.size() - 1 ) { sel3--; } } } } else if( action == "RIGHT" || action == "CONFIRM" ) { WORLDPTR world = world_generator->pick_world(); if( world == NULL ) { g->u = player(); continue; } world_generator->set_active_world( world ); try { g->setup(); } catch( const std::exception &err ) { debugmsg( "Error: %s", err.what() ); g->u = player(); continue; } if( !g->u.create( PLTYPE_TEMPLATE, templates[sel3] ) ) { g->u = player(); werase( w_background ); wrefresh( w_background ); continue; } werase( w_background ); wrefresh( w_background ); if( !g->start_game() ) { g->u = player(); continue; } start = true; } } } // end while return start; }
void menu_rc_setup(uint8_t section) { int8_t *value_ptr; menu_range_t range; uint8_t text_link; uint8_t i = 0; uint8_t mult = 1; // Multiplier uint8_t offset; // Index into channel structure uint8_t items; // Items in group // If submenu item has changed, reset submenu positions if (menu_flag) { sub_top = RCSTART; menu_flag = 0; } while(button != BACK) { // Get menu offsets and load values from eeprom // 1 = RC, 2 = Failsafe, 3 = General switch(section) { case 1: // RC setup menu offset = 0; items = RCITEMS; value_ptr = &Config.RxModeIn; mult = 1; break; case 2: // Failsafe menu offset = RCITEMS; items = FSITEMS; value_ptr = &Config.FailsafeType; mult = 1; break; case 3: // General menu offset = RCITEMS + FSITEMS; items = GENERALITEMS; value_ptr = &Config.MixMode; mult = 1; break; default: offset = 0; items = RCITEMS; value_ptr = &Config.RxModeIn; mult = 1; break; } // Save pre-edited values int8_t temp_type = Config.MixMode; int8_t temp_flapchan = Config.FlapChan; int8_t temp_RxModeIn = Config.RxModeIn; // Print menu print_menu_items(sub_top + offset, RCSTART + offset, value_ptr, mult, (const unsigned char*)rc_menu_ranges[section - 1], 0, RCOFFSET, (const unsigned char*)RCMenuText[section - 1], cursor); // Handle menu changes update_menu(items, RCSTART, offset, button, &cursor, &sub_top, &menu_temp); range = get_menu_range ((const unsigned char*)rc_menu_ranges[section - 1], (menu_temp - RCSTART - offset)); if (button == ENTER) { text_link = pgm_read_byte(&RCMenuText[section - 1][menu_temp - RCSTART - offset]); do_menu_item(menu_temp, value_ptr + (menu_temp - RCSTART - offset), mult, range, 0, text_link, false, 0); } if (button == ENTER) { // Update Ch5. mixer with source from Config.FlapChan if in Aeroplane mode and source changed if ((Config.MixMode == AEROPLANE) && (Config.FlapChan != temp_flapchan)) { Config.Channel[CH5].source_a = Config.FlapChan; } // Reset serial in channel masks every time the input type is changed if (temp_RxModeIn != Config.RxModeIn) { Xtreme_Chanmask = 0; Xtreme_RSS = 0; Spektrum_Chanmask_0 = 0; Spektrum_Chanmask_1 = 0; Spektrum_frameloss = 0; SBUS_Flags = 0; // Clear channel data for (i = 0; i < MAX_RC_CHANNELS; i++) { RxChannel[i] = 0; // Unused Spektrum channels set to NULL if (Config.RxModeOut == SPEKTRUM) { ExtChannel[i] = 0xFFFF; } // Unused channels set to mid-way else if (Config.RxModeOut == SBUS) { ExtChannel[i] = 0x400; } // Xtreme doesn't care else { ExtChannel[i] = 0; } } } // If model type has changed, reload preset if ((section == 3) && (temp_type != Config.MixMode)) { switch(Config.MixMode) // Load selected mix { case AEROPLANE: get_preset_mix(AEROPLANE_MIX); break; case FWING: get_preset_mix(FLYING_WING_MIX); break; case MANUAL: // Clear all channel info memset(&Config.Channel[0].value,0,(sizeof(channel_t) * MAX_OUTPUTS)); // Preset important settings for (i = 0; i < MAX_OUTPUTS; i++) { Config.Channel[i].source_a = i; // Set to mirror the inputs Config.Channel[i].source_a_volume = 100; Config.Channel[i].source_b = NOCHAN; Config.Channel[i].output_b = UNUSED; Config.Channel[i].output_c = UNUSED; } break; default: break; } } init_int(); // In case RC type has changed, reinitialise interrupts init_uart(); // and UART UpdateLimits(); // Update I-term limits and triggers based on percentages #ifdef KK21 // Update MPU6050 LPF writeI2Cbyte(MPU60X0_DEFAULT_ADDRESS, MPU60X0_RA_CONFIG, (6 - Config.MPU6050_LPF)); #endif // Update channel sequence for (i = 0; i < MAX_RC_CHANNELS; i++) { if (Config.TxSeq == FUTABASEQ) { Config.ChannelOrder[i] = pgm_read_byte(&FUTABA[i]); } else { Config.ChannelOrder[i] = pgm_read_byte(&JR[i]); } } Save_Config_to_EEPROM(); // Save value and return Wait_BUTTON4(); // Wait for user's finger off the button } } }
void game::print_menu( WINDOW *w_open, int iSel, const int iMenuOffsetX, int iMenuOffsetY, bool bShowDDA ) { // Clear Lines werase( w_open ); // Define window size int window_width = getmaxx( w_open ); int window_height = getmaxy( w_open ); // Draw horizontal line for( int i = 1; i < window_width - 1; ++i ) { mvwputch( w_open, window_height - 2, i, c_white, LINE_OXOX ); } center_print( w_open, window_height - 1, c_red, _( "Please report bugs to [email protected] or post on the forums." ) ); int iLine = 0; const int iOffsetX = ( window_width - FULL_SCREEN_WIDTH ) / 2; const nc_color cColor1 = c_ltcyan; const nc_color cColor2 = c_ltblue; const nc_color cColor3 = c_ltblue; if( mmenu_title.size() > 1 ) { for( size_t i = 0; i < mmenu_title.size(); ++i ) { if( i == 6 ) { if( !bShowDDA ) { break; } if( FULL_SCREEN_HEIGHT > 24 ) { ++iLine; } } mvwprintz( w_open, iLine++, iOffsetX, i < 6 ? cColor1 : cColor2, mmenu_title[i].c_str() ); } } else { center_print( w_open, iLine++, cColor1, mmenu_title[0].c_str() ); } if( bShowDDA ) { iLine++; center_print( w_open, iLine++, cColor3, _( "Version: %s" ), getVersionString() ); } int menu_length = 0; for( size_t i = 0; i < vMenuItems.size(); ++i ) { menu_length += utf8_width( vMenuItems[i], true ) + 2; if( !vMenuHotkeys[i].empty() ) { menu_length += utf8_width( vMenuHotkeys[i][0] ); } } const int free_space = std::max( 0, window_width - menu_length - iMenuOffsetX ); const int spacing = free_space / ( ( int )vMenuItems.size() + 1 ); const int width_of_spacing = spacing * ( vMenuItems.size() + 1 ); const int adj_offset = std::max( 0, ( free_space - width_of_spacing ) / 2 ); const int final_offset = iMenuOffsetX + adj_offset + spacing; print_menu_items( w_open, vMenuItems, iSel, iMenuOffsetY, final_offset, spacing ); refresh(); wrefresh( w_open ); refresh(); }
void menu_mixer(uint8_t section) { static uint8_t mix_top = MIXERSTART; static uint8_t old_section; int8_t *value_ptr; int8_t values[INPUTITEMS+1]; menu_range_t range; uint8_t text_link = 0; uint8_t offset; // Index into channel structure uint8_t items; // Items in group // If submenu item has changed, reset submenu positions if (section != old_section) { mix_top = MIXERSTART; old_section = section; } // Get mixer menu offsets // 1 = input mixer data, 2 = output mixer data switch(section) { case 1: items = INPUTITEMS+1; offset = 0; value_ptr = &values[0]; break; case 2: items = OUTPUTITEMS+1; offset = INPUTITEMS+1; value_ptr = &values[0]; break; default: items = INPUTITEMS+1; offset = 0; value_ptr = &values[0]; break; } while(button != BACK) { // Load values from eeprom and insert channel number at the top of each - messy values[0] = Config.MenuChannel; if (section == 1) { memcpy(&values[1],&Config.Channel[Config.MenuChannel].source_a,(sizeof(int8_t) * INPUTITEMS)); } else { memcpy(&values[1],&Config.Channel[Config.MenuChannel].switcher,(sizeof(int8_t) * OUTPUTITEMS)); } // Print menu print_menu_items(mix_top + offset, MIXERSTART + offset, value_ptr, 1, (prog_uchar*)mixer_menu_ranges[section - 1], 0, MIXOFFSET, (prog_uchar*)MixerMenuText[section - 1], cursor); // Handle menu changes update_menu(items, MIXERSTART, offset, button, &cursor, &mix_top, &menu_temp); range = get_menu_range ((prog_uchar*)mixer_menu_ranges[section - 1], menu_temp - MIXERSTART - offset); if (button == ENTER) { text_link = pgm_read_byte(&MixerMenuText[section - 1][menu_temp - MIXERSTART - offset]); do_menu_item(menu_temp, value_ptr + (menu_temp - MIXERSTART - offset), 1, range, 0, text_link, false, 0); } // Save modified data back to Config // Copy channel number back to global switch(section) { case 1: memcpy(&Config.Channel[Config.MenuChannel].source_a,&values[1],(sizeof(int8_t) * INPUTITEMS)); Config.MenuChannel = values[0]; break; case 2: memcpy(&Config.Channel[Config.MenuChannel].switcher,&values[1],(sizeof(int8_t) * OUTPUTITEMS)); Config.MenuChannel = values[0]; break; default: break; } // Save and exit if (button == ENTER) { UpdateLimits(); // Update travel limits based on percentages Save_Config_to_EEPROM(); // Save value and return } } _delay_ms(200); }