Skip to content

Commit

Permalink
in mp lobby, try to download addons if we can't join a game
Browse files Browse the repository at this point in the history
If we try to join or observe a game but don't have addons to do it,
ask if we want to try to download them, then call addon client code
to initiate transactions.

Note that because the "is_joinable" / "is_observable" logic includes
this stuff, we would have to refactor to be able to determine
"would this game be joinable if I downloaded the addons". So in the
current state, it's possible that you will be prompted to download
add-ons for a game that you ultimately cannot join anyways, which
might be a bit dissappointing.
  • Loading branch information
cbeck88 committed Mar 15, 2015
1 parent e334a50 commit 1cafaf2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/game_initialization/multiplayer_lobby.cpp
Expand Up @@ -18,6 +18,7 @@

#include "global.hpp"

#include "addon/manager_ui.hpp"
#include "construct_dialog.hpp"
#include "filesystem.hpp"
#include "game_preferences.hpp"
Expand All @@ -28,6 +29,8 @@
#include "multiplayer_lobby.hpp"
#include "gettext.hpp"
#include "gui/auxiliary/old_markup.hpp"
#include "gui/dialogs/message.hpp" // for gui2::show_message
#include "gui/widgets/window.hpp" // for gui2::twindow::OK
#include "log.hpp"
#include "playmp_controller.hpp"
#include "sound.hpp"
Expand Down Expand Up @@ -475,6 +478,7 @@ void gamebrowser::set_game_items(const config& cfg, const config& game_config)
games_.push_back(game_item());
games_.back().password_required = game["password"].to_bool();
games_.back().reloaded = game["savegame"].to_bool();
games_.back().addon_ids = game["addon_ids"].str();
games_.back().have_era = true;
games_.back().have_scenario = true;
if (game["mp_campaign"].empty()) {
Expand Down Expand Up @@ -1026,8 +1030,20 @@ void lobby::process_event_impl(const process_event_data & data)
join_game_.enable(games_menu_.selection_is_joinable());
observe_game_.enable(games_menu_.selection_is_observable());

// check whehter to try to download addons
if (games_menu_.selected() && (data.observe || data.join) && games_menu_.selection_needs_addons())
{
if (gui2::show_message(video(), _("Missing user-made content."), _("This game requires one or more user-made addons to join. Do you want to try to install them?"), gui2::tmessage::yes_no_buttons) == gui2::twindow::OK) {
std::vector<std::string> addon_ids = games_menu_.selection_addon_ids();
BOOST_FOREACH(const std::string & id, addon_ids) {
ad_hoc_addon_fetch_session(disp(), id);
}
}
}

const bool observe = (data.observe || (games_menu_.selected() && !games_menu_.selection_is_joinable())) && games_menu_.selection_is_observable();
const bool join = (data.join || games_menu_.selected()) && games_menu_.selection_is_joinable();

games_menu_.reset_selection();
preferences::set_skip_mp_replay(replay_options_.selected() == 1);
preferences::set_blindfold_replay(replay_options_.selected() == 2);
Expand Down
10 changes: 9 additions & 1 deletion src/game_initialization/multiplayer_lobby.hpp
Expand Up @@ -20,6 +20,7 @@
#include "multiplayer_ui.hpp"
#include "game_preferences.hpp"
#include "image.hpp"
#include "serialization/string_utils.hpp"

class config;
class video;
Expand Down Expand Up @@ -62,7 +63,8 @@ class gamebrowser : public gui::menu {
password_required(false),
have_scenario(false),
have_era(false),
have_all_mods(false)
have_all_mods(false),
addon_ids()
{
}

Expand Down Expand Up @@ -92,6 +94,7 @@ class gamebrowser : public gui::menu {
bool have_scenario;
bool have_era;
bool have_all_mods;
std::string addon_ids;
};
gamebrowser(CVideo& video, const config &map_hashes);
void scroll(unsigned int pos);
Expand All @@ -117,6 +120,11 @@ class gamebrowser : public gui::menu {
games_[selected_].have_era &&
games_[selected_].have_all_mods) ||
preferences::is_authenticated(); }
bool selection_needs_addons() const // TODO: Add support have downloading addons that require the scenario
{ return empty() ? false : !games_[selected_].have_era ||
!games_[selected_].have_all_mods; }
std::vector<std::string> selection_addon_ids() const
{ return empty() ? std::vector<std::string>() : utils::split(games_[selected_].addon_ids, ','); }
bool selected() const { return double_clicked_ && !empty(); }
void reset_selection() { double_clicked_ = false; }
int selection() const { return selected_; }
Expand Down
8 changes: 8 additions & 0 deletions src/tests/gui/test_gui2.cpp
Expand Up @@ -455,6 +455,14 @@ BOOST_AUTO_TEST_CASE(test_gui2)
std::remove(list.begin(), list.end(), "lua_interpreter")
, list.end());

//Window 'addon_description' registered but not tested.
//Window 'addon_filter_options' registered but not tested.
//Window 'addon_uninstall_list' registered but not tested.
//Window 'network_transmission' registered but not tested.
list.erase(std::remove(list.begin(), list.end(), "addon_description"), list.end());
list.erase(std::remove(list.begin(), list.end(), "addon_filter_options"), list.end());
list.erase(std::remove(list.begin(), list.end(), "addon_uninstall_list"), list.end());
list.erase(std::remove(list.begin(), list.end(), "network_transmission"), list.end());

// Test size() instead of empty() to get the number of offenders
BOOST_CHECK_EQUAL(list.size(), 0);
Expand Down

0 comments on commit 1cafaf2

Please sign in to comment.