Skip to content

Commit

Permalink
MP Create Game: minor improvements
Browse files Browse the repository at this point in the history
* The dialog now owns its own create_engine object. Previously, it was created immediately
  adjacent to the dialog object and passed in by reference, which made no sense.
* The create_engine also no longer takes a CVideo reference and instead initializes its CVideo
  member from the singleton.
* The 'Registered Users Only' toggle is now disabled if the host isn't registered themselves
  (fixes #2206)
* The above setting, along with Observers, Strict Sync, and Game Password, are disabled in local
  mode. These don't really make sense when not playing a networked game.
  • Loading branch information
Vultraz authored and GregoryLundberg committed Nov 30, 2017
1 parent ac08bb1 commit eaf441d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/game_initialization/create_engine.cpp
Expand Up @@ -28,6 +28,7 @@
#include "map/map.hpp"
#include "minimap.hpp"
#include "saved_game.hpp"
#include "video.hpp"
#include "wml_exception.hpp"

#include "serialization/preprocessor.hpp"
Expand Down Expand Up @@ -226,7 +227,7 @@ void campaign::mark_if_completed()
}
}

create_engine::create_engine(CVideo& v, saved_game& state)
create_engine::create_engine(saved_game& state)
: current_level_type_()
, current_level_index_(0)
, current_era_index_(0)
Expand All @@ -238,7 +239,7 @@ create_engine::create_engine(CVideo& v, saved_game& state)
, eras_()
, mods_()
, state_(state)
, video_(v)
, video_(CVideo::get_singleton())
, dependency_manager_(nullptr)
, generator_(nullptr)
, selected_campaign_difficulty_()
Expand Down
2 changes: 1 addition & 1 deletion src/game_initialization/create_engine.hpp
Expand Up @@ -274,7 +274,7 @@ class campaign : public level
class create_engine
{
public:
create_engine(CVideo& v, saved_game& state);
explicit create_engine(saved_game& state);

enum MP_EXTRA { ERA, MOD };

Expand Down
8 changes: 4 additions & 4 deletions src/game_initialization/multiplayer.cpp
Expand Up @@ -470,11 +470,11 @@ void enter_create_mode(mp_workflow_helper_ptr helper)

bool dlg_cancel = false;
{
ng::create_engine create_eng(helper->video, helper->state);
bool local_mode = helper->connection == nullptr;
mp::user_info* host_info = helper->lobby_info->get_user(preferences::login());

gui2::dialogs::mp_create_game dlg(helper->game_config, create_eng);
dlg.show(helper->video);
dlg_cancel = dlg.get_retval() == gui2::window::CANCEL;
gui2::dialogs::mp_create_game dlg(helper->game_config, helper->state, local_mode, host_info);
dlg_cancel = !dlg.show(helper->video);
}

if(!dlg_cancel) {
Expand Down
2 changes: 1 addition & 1 deletion src/game_initialization/singleplayer.cpp
Expand Up @@ -31,7 +31,7 @@ bool enter_create_mode(CVideo& video, const config& game_config, saved_game& sta
bool configure_canceled = false;

do {
ng::create_engine create_eng(video, state);
ng::create_engine create_eng(state);

create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN);

Expand Down
39 changes: 31 additions & 8 deletions src/gui/dialogs/multiplayer/mp_create_game.cpp
Expand Up @@ -17,35 +17,36 @@
#include "gui/dialogs/multiplayer/mp_create_game.hpp"

#include "game_config_manager.hpp"
#include "preferences/game.hpp"
#include "game_initialization/lobby_data.hpp"
#include "gettext.hpp"
#include "gui/auxiliary/field.hpp"
#include "gui/dialogs/helper.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/simple_item_selector.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "gui/widgets/integer_selector.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/menu_button.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/integer_selector.hpp"
#include "gui/widgets/menu_button.hpp"
#include "preferences/game.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "gui/widgets/list.hpp"
#else
#include "gui/widgets/listbox.hpp"
#endif
#include "formatter.hpp"
#include "game_config.hpp"
#include "gui/widgets/minimap.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/slider.hpp"
#include "gui/widgets/stacked_widget.hpp"
#include "gui/widgets/status_label_helper.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/toggle_panel.hpp"
#include "gui/widgets/text_box.hpp"
#include "game_config.hpp"
#include "log.hpp"
#include "savegame.hpp"
#include "settings.hpp"
#include "formatter.hpp"

#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "utils/functional.hpp"
Expand Down Expand Up @@ -73,9 +74,9 @@ namespace prefs = preferences;

REGISTER_DIALOG(mp_create_game)

mp_create_game::mp_create_game(const config& cfg, ng::create_engine& create_eng)
mp_create_game::mp_create_game(const config& cfg, saved_game& state, bool local_mode, mp::user_info* host_info)
: cfg_(cfg)
, create_engine_(create_eng)
, create_engine_(state)
, config_engine_()
, options_manager_()
, selected_game_index_(-1)
Expand All @@ -101,6 +102,8 @@ mp_create_game::mp_create_game(const config& cfg, ng::create_engine& create_eng)
, action_bonus_(register_integer("action_bonus", true, prefs::countdown_action_bonus, prefs::set_countdown_action_bonus))
, mod_list_()
, eras_menu_button_()
, local_mode_(local_mode)
, host_info_(host_info)
{
level_types_ = {
{ng::level::TYPE::SCENARIO, _("Scenarios")},
Expand Down Expand Up @@ -299,6 +302,26 @@ void mp_create_game::pre_show(window& win)
bind_status_label<slider>(&win, reservoir_->id());
bind_status_label<slider>(&win, action_bonus_->id());

//
// Disable certain settings if we're playing a local game.
//

// Don't allow a 'registered users only' game if the host themselves isn't registered.
if(local_mode_ || (host_info_ && !host_info_->registered)) {
registered_users_->widget_set_enabled(win, false, false);
}

if(local_mode_) {
find_widget<text_box>(&win, "game_password", false).set_active(false);

observers_->widget_set_enabled(win, false, false);
strict_sync_->widget_set_enabled(win, false, false);
}

if(host_info_ && !host_info_->registered) {
registered_users_->widget_set_enabled(win, false, false);
}

//
// Set up tab control
//
Expand Down
16 changes: 11 additions & 5 deletions src/gui/dialogs/multiplayer/mp_create_game.hpp
Expand Up @@ -25,12 +25,14 @@

class config;

namespace gui2
namespace mp
{
struct user_info;
}

namespace gui2
{
class toggle_button;
class toggle_panel;
class widget;
class listbox;
class menu_button;

Expand All @@ -42,7 +44,7 @@ class mp_create_game : public modal_dialog, private plugin_executor
typedef std::pair<ng::level::TYPE, std::string> level_type_info;

public:
mp_create_game(const config& cfg, ng::create_engine& create_eng);
mp_create_game(const config& cfg, saved_game& state, bool local_mode, mp::user_info* host_info = nullptr);

private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
Expand All @@ -56,7 +58,7 @@ class mp_create_game : public modal_dialog, private plugin_executor

const config& cfg_;

ng::create_engine& create_engine_;
ng::create_engine create_engine_;
std::unique_ptr<ng::configure_engine> config_engine_;
std::unique_ptr<mp_options_helper> options_manager_;

Expand Down Expand Up @@ -113,6 +115,10 @@ class mp_create_game : public modal_dialog, private plugin_executor
listbox* mod_list_;
menu_button* eras_menu_button_;

bool local_mode_;

mp::user_info* host_info_;

template<typename widget>
void on_filter_change(window& window, const std::string& id, bool do_select);

Expand Down

0 comments on commit eaf441d

Please sign in to comment.