Moved level download utility functions to mp::wait.
This commit is contained in:
parent
7d704687be
commit
f57b29fc13
4 changed files with 40 additions and 51 deletions
|
@ -41,19 +41,6 @@ static lg::log_domain log_network("network");
|
|||
#define LOG_NW LOG_STREAM(info, log_network)
|
||||
#define ERR_NW LOG_STREAM(err, log_network)
|
||||
|
||||
namespace {
|
||||
|
||||
bool has_level_data(const config& level, bool first_scenario)
|
||||
{
|
||||
if (first_scenario) {
|
||||
return level.has_attribute("version") && level.has_child("side");
|
||||
} else {
|
||||
return level.has_child("next_scenario");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace mp {
|
||||
|
||||
config initial_level_config(game_display& disp, const mp_game_settings& params,
|
||||
|
@ -281,35 +268,5 @@ void check_response(network::connection res, const config& data)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool download_level_data(game_display& disp, config& level,
|
||||
bool first_scenario)
|
||||
{
|
||||
if (!first_scenario) {
|
||||
// Ask for the next scenario data.
|
||||
network::send_data(config("load_next_scenario"), 0);
|
||||
}
|
||||
|
||||
while (!has_level_data(level, first_scenario)) {
|
||||
network::connection data_res = dialogs::network_receive_dialog(
|
||||
disp, _("Getting game data..."), level);
|
||||
|
||||
if (!data_res) {
|
||||
return false;
|
||||
}
|
||||
check_response(data_res, level);
|
||||
if (level.child("leave_game")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!first_scenario) {
|
||||
config cfg = level.child("next_scenario");
|
||||
level = cfg;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // end namespace mp
|
||||
|
||||
|
|
|
@ -30,9 +30,6 @@ void level_to_gamestate(config& level, game_state& state);
|
|||
|
||||
void check_response(network::connection res, const config& data);
|
||||
|
||||
bool download_level_data(game_display& disp, config& level,
|
||||
bool first_scenario);
|
||||
|
||||
} // end namespace mp
|
||||
|
||||
#endif
|
||||
|
|
|
@ -203,11 +203,7 @@ void wait::process_event()
|
|||
|
||||
void wait::join_game(bool observe)
|
||||
{
|
||||
//if we have got valid side data
|
||||
//the first condition is to make sure that we don't have another
|
||||
//WML message with a side-tag in it
|
||||
const bool download_res = download_level_data(disp(), level_,
|
||||
first_scenario_);
|
||||
const bool download_res = download_level_data();
|
||||
if (!download_res) {
|
||||
set_result(QUIT);
|
||||
return;
|
||||
|
@ -548,5 +544,42 @@ void wait::generate_menu()
|
|||
}
|
||||
}
|
||||
|
||||
bool wait::has_level_data() const
|
||||
{
|
||||
if (first_scenario_) {
|
||||
return level_.has_attribute("version") && level_.has_child("side");
|
||||
} else {
|
||||
return level_.has_child("next_scenario");
|
||||
}
|
||||
}
|
||||
|
||||
bool wait::download_level_data()
|
||||
{
|
||||
if (!first_scenario_) {
|
||||
// Ask for the next scenario data.
|
||||
network::send_data(config("load_next_scenario"), 0);
|
||||
}
|
||||
|
||||
while (!has_level_data()) {
|
||||
network::connection data_res = dialogs::network_receive_dialog(
|
||||
disp(), _("Getting game data..."), level_);
|
||||
|
||||
if (!data_res) {
|
||||
return false;
|
||||
}
|
||||
check_response(data_res, level_);
|
||||
if (level_.child("leave_game")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!first_scenario_) {
|
||||
config cfg = level_.child("next_scenario");
|
||||
level_ = cfg;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace mp
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ private:
|
|||
};
|
||||
|
||||
void generate_menu();
|
||||
bool has_level_data() const;
|
||||
bool download_level_data();
|
||||
|
||||
gui::button cancel_button_;
|
||||
gui::label start_label_;
|
||||
|
|
Loading…
Add table
Reference in a new issue