void uimenu::addentry(int r, bool e, int k, const char *format, ...) { va_list ap; va_start(ap, format); const std::string text = vstring_format(format, ap); va_end(ap); entries.push_back(uimenu_entry(r, e, k, text)); }
void uimenu::addentry(int r, bool e, int k, const char *format, ...) { char buf[4096]; int rv=r; bool en=e; int ke=k; va_list ap; va_start(ap, format); int safe=vsnprintf(buf, sizeof(buf), format, ap); if ( safe >= 4096 || safe < 0 ) { popup("BUG: Increase buf[4096] in ui.cpp"); return; } entries.push_back(uimenu_entry(rv, en, ke, std::string(buf))); }
/** * here we emulate the old int ret=menu(bool, "header", "option1", "option2", ...); */ uimenu::uimenu(bool, const char * const mes, ...) { init(); va_list ap; va_start(ap, mes); int i = 0; while (char const *const tmp = va_arg(ap, char *)) { entries.push_back(uimenu_entry(i++, true, MENU_AUTOASSIGN, tmp )); } va_end(ap); query(); }
uimenu::uimenu(bool cancelable, const char *mes, std::vector<std::string> options) { // exact usage as menu_vec init(); if (options.empty()) { debugmsg("0-length menu (\"%s\")", mes); ret = -1; } else { text = mes; shift_retval = 1; return_invalid = cancelable; for (int i = 0; i < options.size(); i++) { entries.push_back(uimenu_entry(i, true, MENU_AUTOASSIGN, options[i] )); } query(); } }
uimenu::uimenu(bool cancelable, const char *mes, const std::vector<std::string> &options, const std::string &hotkeys_override) { init(); hotkeys = hotkeys_override; if (options.empty()) { debugmsg("0-length menu (\"%s\")", mes); ret = -1; } else { text = mes; shift_retval = 1; return_invalid = cancelable; for (size_t i = 0; i < options.size(); i++) { entries.push_back(uimenu_entry(i, true, MENU_AUTOASSIGN, options[i] )); } query(); } }
uimenu::uimenu(bool cancancel, const char *mes, ...) { // here we emulate the old int ret=menu(bool, "header", "option1", "option2", ...); init(); va_list ap; va_start(ap, mes); char *tmp; bool done = false; int i = 0; text = mes; shift_retval = 1; return_invalid = cancancel; while (!done) { tmp = va_arg(ap, char *); if (tmp != NULL) { std::string strtmp = tmp; entries.push_back(uimenu_entry(i, true, MENU_AUTOASSIGN, strtmp )); } else { done = true; } i++; } query(); }
void uimenu::addentry(int r, bool e, int k, std::string str) { entries.push_back(uimenu_entry(r, e, k, str)); }
void minesweeper_game::new_level(WINDOW *w_minesweeper) { iMaxY = getmaxy(w_minesweeper) - 2; iMaxX = getmaxx(w_minesweeper) - 2; werase(w_minesweeper); mLevel.clear(); mLevelReveal.clear(); auto set_num = [&](const std::string sType, int &iVal, const int iMin, const int iMax) { std::ostringstream ssTemp; ssTemp << _("Min:") << iMin << " " << _("Max:") << " " << iMax; do { if ( iVal < iMin || iVal > iMax ) { iVal = iMin; } iVal = std::atoi(string_input_popup(sType.c_str(), 5, to_string(iVal), ssTemp.str().c_str(), "", -1, true).c_str()); } while( iVal < iMin || iVal > iMax); }; uimenu difficulty; difficulty.text = _("Game Difficulty"); difficulty.entries.push_back(uimenu_entry(0, true, 'b', _("Beginner"))); difficulty.entries.push_back(uimenu_entry(1, true, 'i', _("Intermediate"))); difficulty.entries.push_back(uimenu_entry(2, true, 'e', _("Expert"))); difficulty.entries.push_back(uimenu_entry(3, true, 'c', _("Custom"))); difficulty.query(); switch (difficulty.ret) { case 0: iLevelY = 8; iLevelX = 8; iBombs = 10; break; case 1: iLevelY = 16; iLevelX = 16; iBombs = 40; break; case 2: iLevelY = 16; iLevelX = 30; iBombs = 99; break; case 3: default: iLevelY = iMinY; iLevelX = iMinX; set_num(_("Level width:"), iLevelX, iMinX, iMaxX); set_num(_("Level height:"), iLevelY, iMinY, iMaxY); iBombs = iLevelX * iLevelY * 0.1; set_num(_("Number of bombs:"), iBombs, iBombs, iLevelX * iLevelY * 0.6); break; } iOffsetX = ((iMaxX - iLevelX) / 2) + 1; iOffsetY = ((iMaxY - iLevelY) / 2) + 1; int iRandX; int iRandY; for ( int i = 0; i < iBombs; i++ ) { do { iRandX = rng(0, iLevelX - 1); iRandY = rng(0, iLevelY - 1); } while ( mLevel[iRandY][iRandX] == (int)bomb ); mLevel[iRandY][iRandX] = (int)bomb; } for ( int y = 0; y < iLevelY; y++ ) { for ( int x = 0; x < iLevelX; x++ ) { if (mLevel[y][x] == (int)bomb) { const auto circle = closest_tripoints_first( 1, {x, y, 0} ); for( const auto &p : circle ) { if ( p.x >= 0 && p.x < iLevelX && p.y >= 0 && p.y < iLevelY ) { if ( mLevel[p.y][p.x] != (int)bomb ) { mLevel[p.y][p.x]++; } } } } } } for (int y = 0; y < iLevelY; y++) { mvwputch(w_minesweeper, iOffsetY + y, iOffsetX, c_white, std::string(iLevelX, '#')); } mvwputch(w_minesweeper, iOffsetY, iOffsetX, hilite(c_white), "#"); draw_custom_border(w_minesweeper, true, true, true, true, true, true, true, true, BORDER_COLOR, iOffsetY - 1, iLevelY + 2, iOffsetX - 1, iLevelX + 2); }
void uimenu::addentry_col(int r, bool e, int k, const std::string &str, const std::string &column, const std::string &desc) { entries.push_back(uimenu_entry(r, e, k, str, desc, column)); }
void uimenu::addentry_desc(const std::string &str, const std::string &desc) { entries.push_back(uimenu_entry(str, desc)); }
// Handles interactions with a vehicle in the examine menu. // Returns the part number that will accept items if any, or -1 to indicate no cargo part. // Returns -2 if a special interaction was performed and the menu should exit. int Pickup::interact_with_vehicle( vehicle *veh, const tripoint &pos, int veh_root_part ) { bool from_vehicle = false; int k_part = 0; int wtr_part = 0; int w_part = 0; int craft_part = 0; int cargo_part = 0; int chempart = 0; int ctrl_part = 0; std::vector<std::string> menu_items; std::vector<uimenu_entry> options_message; const bool has_items_on_ground = g->m.sees_some_items( pos, g->u ); const bool items_are_sealed = g->m.has_flag( "SEALED", pos ); if( veh ) { k_part = veh->part_with_feature(veh_root_part, "KITCHEN"); wtr_part = veh->part_with_feature(veh_root_part, "FAUCET"); w_part = veh->part_with_feature(veh_root_part, "WELDRIG"); craft_part = veh->part_with_feature(veh_root_part, "CRAFTRIG"); chempart = veh->part_with_feature(veh_root_part, "CHEMLAB"); cargo_part = veh->part_with_feature(veh_root_part, "CARGO", false); ctrl_part = veh->part_with_feature(veh_root_part, "CONTROLS"); from_vehicle = veh && cargo_part >= 0 && !veh->get_items(cargo_part).empty(); const bool can_be_folded = veh->is_foldable(); const bool is_convertible = (veh->tags.count("convertible") > 0); const bool remotely_controlled = g->remoteveh() == veh; menu_items.push_back(_("Examine vehicle")); options_message.push_back(uimenu_entry(_("Examine vehicle"), 'e')); if (ctrl_part >= 0) { menu_items.push_back(_("Control vehicle")); options_message.push_back(uimenu_entry(_("Control vehicle"), 'v')); } if( from_vehicle ) { menu_items.push_back(_("Get items")); options_message.push_back(uimenu_entry(_("Get items"), 'g')); } if( has_items_on_ground && !items_are_sealed ) { menu_items.push_back(_("Get items on the ground")); options_message.push_back(uimenu_entry(_("Get items on the ground"), 'i')); } if( ( can_be_folded || is_convertible ) && !remotely_controlled ) { menu_items.push_back(_("Fold vehicle")); options_message.push_back(uimenu_entry(_("Fold vehicle"), 'f')); } if((k_part >= 0 || chempart >= 0) && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the hotplate")); options_message.push_back(uimenu_entry(_("Use the hotplate"), 'h')); } if((k_part >= 0 || wtr_part >= 0) && veh->fuel_left("water_clean") > 0) { menu_items.push_back(_("Fill a container with water")); options_message.push_back(uimenu_entry(_("Fill a container with water"), 'c')); menu_items.push_back(_("Have a drink")); options_message.push_back(uimenu_entry(_("Have a drink"), 'd')); } if(w_part >= 0 && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the welding rig?")); options_message.push_back(uimenu_entry(_("Use the welding rig?"), 'w')); } if(craft_part >= 0 && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the water purifier?")); options_message.push_back(uimenu_entry(_("Use the water purifier?"), 'p')); } int choice; if( menu_items.size() == 1 ) { choice = 0; } else { uimenu selectmenu; selectmenu.return_invalid = true; selectmenu.text = _("Select an action"); selectmenu.entries = options_message; selectmenu.selected = 0; selectmenu.query(); choice = selectmenu.ret; } if(choice < 0) { return -2; } if(menu_items[choice] == _("Use the hotplate")) { //Will be -1 if no battery at all item tmp_hotplate( "hotplate", 0 ); // Drain a ton of power tmp_hotplate.charges = veh->drain( "battery", 100 ); if( tmp_hotplate.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_hotplate)->type); if ( tmp_hotplate.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_hotplate ); tmp_hotplate.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_hotplate.charges ); } } return -2; } if(menu_items[choice] == _("Fill a container with water")) { int amt = veh->drain("water_clean", veh->fuel_left("water_clean")); item fill_water( "water_clean", calendar::turn ); fill_water.charges = amt; int back = g->move_liquid(fill_water); if (back >= 0) { veh->refill("water_clean", back); } else { veh->refill("water_clean", amt); } return -2; } if(menu_items[choice] == _("Have a drink")) { veh->drain("water_clean", 1); item water( "water_clean", 0 ); g->u.eat(&water, dynamic_cast<it_comest *>(water.type)); g->u.moves -= 250; return -2; } if(menu_items[choice] == _("Use the welding rig?")) { //Will be -1 if no battery at all item tmp_welder( "welder", 0 ); // Drain a ton of power tmp_welder.charges = veh->drain( "battery", 1000 ); if( tmp_welder.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_welder)->type); if ( tmp_welder.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_welder ); tmp_welder.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_welder.charges ); } } return -2; } if(menu_items[choice] == _("Use the water purifier?")) { //Will be -1 if no battery at all item tmp_purifier( "water_purifier", 0 ); // Drain a ton of power tmp_purifier.charges = veh->drain( "battery", veh->fuel_left("battery")); if( tmp_purifier.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_purifier)->type); if ( tmp_purifier.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_purifier ); tmp_purifier.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_purifier.charges ); } } return -2; } if(menu_items[choice] == _("Fold vehicle")) { veh->fold_up(); return -2; } if(menu_items[choice] == _("Control vehicle") && veh->interact_vehicle_locked()) { veh->use_controls(); return -2; } if(menu_items[choice] == _("Examine vehicle")) { g->exam_vehicle(*veh, pos ); return -2; } if(menu_items[choice] == _("Get items on the ground")) { from_vehicle = false; } } return from_vehicle ? cargo_part : -1; }
// Handles interactions with a vehicle in the examine menu. // Returns the part number that wil accept items if any, or -1 to indicate no cargo part. // Returns -2 if a special interaction was performed and the menu should exit. int Pickup::interact_with_vehicle( vehicle *veh, int posx, int posy, int veh_root_part ) { bool from_vehicle = false; int k_part = 0; int wtr_part = 0; int w_part = 0; int craft_part = 0; int cargo_part = 0; int chempart = 0; int ctrl_part = 0; std::vector<std::string> menu_items; std::vector<uimenu_entry> options_message; std::vector<item> here_ground = g->m.i_at(posx, posy); if( veh ) { k_part = veh->part_with_feature(veh_root_part, "KITCHEN"); wtr_part = veh->part_with_feature(veh_root_part, "FAUCET"); w_part = veh->part_with_feature(veh_root_part, "WELDRIG"); craft_part = veh->part_with_feature(veh_root_part, "CRAFTRIG"); chempart = veh->part_with_feature(veh_root_part, "CHEMLAB"); cargo_part = veh->part_with_feature(veh_root_part, "CARGO", false); ctrl_part = veh->part_with_feature(veh_root_part, "CONTROLS"); from_vehicle = veh && cargo_part >= 0 && !veh->parts[cargo_part].items.empty(); menu_items.push_back(_("Examine vehicle")); options_message.push_back(uimenu_entry(_("Examine vehicle"), 'e')); if (ctrl_part >= 0) { menu_items.push_back(_("Control vehicle")); options_message.push_back(uimenu_entry(_("Control vehicle"), 'v')); } if( from_vehicle ) { menu_items.push_back(_("Get items")); options_message.push_back(uimenu_entry(_("Get items"), 'g')); } if(!here_ground.empty()) { menu_items.push_back(_("Get items on the ground")); options_message.push_back(uimenu_entry(_("Get items on the ground"), 'i')); } if((k_part >= 0 || chempart >= 0) && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the hotplate")); options_message.push_back(uimenu_entry(_("Use the hotplate"), 'h')); } if((k_part >= 0 || wtr_part >= 0) && veh->fuel_left("water") > 0) { menu_items.push_back(_("Fill a container with water")); options_message.push_back(uimenu_entry(_("Fill a container with water"), 'c')); menu_items.push_back(_("Have a drink")); options_message.push_back(uimenu_entry(_("Have a drink"), 'd')); } if(w_part >= 0 && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the welding rig?")); options_message.push_back(uimenu_entry(_("Use the welding rig?"), 'w')); } if(craft_part >= 0 && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the water purifier?")); options_message.push_back(uimenu_entry(_("Use the water purifier?"), 'p')); } int choice; if( menu_items.size() == 1 ) { choice = 0; } else { uimenu selectmenu; selectmenu.return_invalid = true; selectmenu.text = _("Select an action"); selectmenu.entries = options_message; selectmenu.selected = 0; selectmenu.query(); choice = selectmenu.ret; } if(choice < 0) { return -2; } if(menu_items[choice] == _("Use the hotplate")) { //Will be -1 if no battery at all item tmp_hotplate( "hotplate", 0 ); // Drain a ton of power tmp_hotplate.charges = veh->drain( "battery", 100 ); if( tmp_hotplate.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_hotplate)->type); if ( tmp_hotplate.charges >= tmptool->charges_per_use ) { tmptool->invoke(&g->u, &tmp_hotplate, false); tmp_hotplate.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_hotplate.charges ); } } return -2; } if(menu_items[choice] == _("Fill a container with water")) { int amt = veh->drain("water", veh->fuel_left("water")); item fill_water( default_ammo("water"), calendar::turn ); fill_water.charges = amt; int back = g->move_liquid(fill_water); if (back >= 0) { veh->refill("water", back); } else { veh->refill("water", amt); } return -2; } if(menu_items[choice] == _("Have a drink")) { veh->drain("water", 1); item water( "water_clean", 0 ); g->u.eat(&water, dynamic_cast<it_comest *>(water.type)); g->u.moves -= 250; return -2; } if(menu_items[choice] == _("Use the welding rig?")) { //Will be -1 if no battery at all item tmp_welder( "welder", 0 ); // Drain a ton of power tmp_welder.charges = veh->drain( "battery", 1000 ); if( tmp_welder.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_welder)->type); if ( tmp_welder.charges >= tmptool->charges_per_use ) { tmptool->invoke( &g->u, &tmp_welder, false ); tmp_welder.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_welder.charges ); } } return -2; } if(menu_items[choice] == _("Use the water purifier?")) { //Will be -1 if no battery at all item tmp_purifier( "water_purifier", 0 ); // Drain a ton of power tmp_purifier.charges = veh->drain( "battery", 100 ); if( tmp_purifier.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_purifier)->type); if ( tmp_purifier.charges >= tmptool->charges_per_use ) { tmptool->invoke( &g->u, &tmp_purifier, false ); tmp_purifier.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_purifier.charges ); } } return -2; } if(menu_items[choice] == _("Control vehicle")) { veh->use_controls(); return -2; } if(menu_items[choice] == _("Examine vehicle")) { g->exam_vehicle(*veh, posx, posy); return -2; } if(menu_items[choice] == _("Get items on the ground")) { from_vehicle = false; } } return from_vehicle ? cargo_part : -1; }
void uimenu::addentry_desc(int r, bool e, int k, std::string str, std::string desc) { entries.push_back(uimenu_entry(r, e, k, str, desc)); }
void uimenu::addentry_desc(std::string str, std::string desc) { entries.push_back(uimenu_entry(str, desc)); }