static void enter_create_mode(game_display& disp, const config& game_config, game_state& state, bool local_players_only) { DBG_MP << "entering create mode" << std::endl; bool configure_canceled; bool connect_canceled; do { configure_canceled = false; connect_canceled = false; if (gui2::new_widgets) { gui2::tmp_create_game dlg(game_config); dlg.show(disp.video()); network::send_data(config("refresh_lobby"), 0); } else { mp::ui::result res; mp_game_settings new_params; { mp::create ui(disp, game_config, state, gamechat, gamelist); run_lobby_loop(disp, ui); res = ui.get_result(); new_params = ui.get_parameters(); } switch (res) { case mp::ui::CREATE: configure_canceled = !enter_configure_mode(disp, game_config, state, new_params, local_players_only); break; case mp::ui::LOAD_GAME: connect_canceled = !enter_connect_mode(disp, game_config, state, new_params, local_players_only); break; case mp::ui::QUIT: default: //update lobby content network::send_data(config("refresh_lobby"), 0); break; } } } while(configure_canceled || connect_canceled); }
bool enter_create_mode(game_display& disp, const config& game_config, saved_game& state, jump_to_campaign_info jump_to_campaign, bool local_players_only) { bool configure_canceled = false; do { ng::create_engine create_eng(disp, state); create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN); std::vector<ng::create_engine::level_ptr> campaigns( create_eng.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN)); if (campaigns.empty()) { gui2::show_error_message(disp.video(), _("No campaigns are available.\n")); return false; } bool use_deterministic_mode = false; // No campaign selected from command line if (jump_to_campaign.campaign_id_.empty() == true) { gui2::tcampaign_selection dlg(create_eng); try { dlg.show(disp.video()); } catch(twml_exception& e) { e.show(disp); return false; } if(dlg.get_retval() != gui2::twindow::OK) { return false; } use_deterministic_mode = dlg.get_deterministic(); } else { // don't reset the campaign_id_ so we can know // if we should quit the game or return to the main menu // checking for valid campaign name bool not_found = true; for(size_t i = 0; i < campaigns.size(); ++i) { if (campaigns[i]->data()["id"] == jump_to_campaign.campaign_id_) { create_eng.set_current_level(i); not_found = false; break; } } // didn't find any campaign with that id if (not_found) { //TODO: use ERR_NG or similar std::cerr<<"No such campaign id to jump to: ["<<jump_to_campaign.campaign_id_<<"]\n"; return false; } } std::string random_mode = use_deterministic_mode ? "deterministic" : ""; state.classification().random_mode = random_mode; std::string selected_difficulty = create_eng.select_campaign_difficulty(jump_to_campaign.difficulty_); if (selected_difficulty == "FAIL") return false; if (selected_difficulty == "CANCEL") { if (jump_to_campaign.campaign_id_.empty() == false) { jump_to_campaign.campaign_id_ = ""; } // canceled difficulty dialog, relaunch the campaign selection dialog return enter_create_mode(disp, game_config, state, jump_to_campaign, local_players_only); } create_eng.prepare_for_era_and_mods(); create_eng.prepare_for_campaign(selected_difficulty); if(!jump_to_campaign.scenario_id_.empty()) { state.set_carryover_sides_start( config_of("next_scenario", jump_to_campaign.scenario_id_) ); } create_eng.prepare_for_new_level(); create_eng.get_parameters(); if(!state.valid()) { //TODO: use ERR_NG or similar std::cerr << "Cannot load scenario with id=" << state.get_scenario_id() << "\n"; return false; } configure_canceled = !enter_configure_mode(disp, game_config_manager::get()->game_config(), state, local_players_only); } while (configure_canceled); return true; }
bool enter_create_mode(CVideo& video, const config& game_config, saved_game& state, jump_to_campaign_info jump_to_campaign, bool local_players_only) { bool configure_canceled = false; do { ng::create_engine create_eng(video, state); create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN); const std::vector<ng::create_engine::level_ptr> campaigns = create_eng.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN); if(campaigns.empty()) { gui2::show_error_message(video, _("No campaigns are available.")); return false; } std::string random_mode = ""; // No campaign selected from command line if(jump_to_campaign.campaign_id_.empty()) { gui2::tcampaign_selection dlg(create_eng); try { dlg.show(video); } catch(twml_exception& e) { e.show(video); return false; } if(dlg.get_retval() != gui2::twindow::OK) { return false; } if(dlg.get_deterministic()) { random_mode = "deterministic"; } } else { // Don't reset the campaign_id_ so we can know // if we should quit the game or return to the main menu // Checking for valid campaign name const auto campaign = std::find_if(campaigns.begin(), campaigns.end(), [&jump_to_campaign](ng::create_engine::level_ptr level) { return level->data()["id"] == jump_to_campaign.campaign_id_; }); // Didn't find a campaign with that id if(campaign == campaigns.end()) { ERR_NG << "No such campaign id to jump to: [" << jump_to_campaign.campaign_id_ << "]" << std::endl; return false; } create_eng.set_current_level(campaign - campaigns.begin()); } state.classification().random_mode = random_mode; const std::string selected_difficulty = create_eng.select_campaign_difficulty(jump_to_campaign.difficulty_); if(selected_difficulty == "FAIL") return false; if(selected_difficulty == "CANCEL") { if(!jump_to_campaign.campaign_id_.empty()) { jump_to_campaign.campaign_id_ = ""; } // Canceled difficulty dialog, relaunch the campaign selection dialog return enter_create_mode(video, game_config, state, jump_to_campaign, local_players_only); } create_eng.prepare_for_era_and_mods(); create_eng.prepare_for_campaign(selected_difficulty); if(!jump_to_campaign.scenario_id_.empty()) { state.set_carryover_sides_start( config_of("next_scenario", jump_to_campaign.scenario_id_) ); } if(!state.valid()) { ERR_NG << "Cannot load scenario with id=" << state.get_scenario_id() << std::endl; return false; } configure_canceled = !enter_configure_mode(video, game_config_manager::get()->game_config(), state, create_eng, local_players_only); } while (configure_canceled); return true; }