Skip to content

Commit

Permalink
GUI2: convert remaining uses of dialog_callback to std::bind
Browse files Browse the repository at this point in the history
dialog_callback was designed to be passed where a void(widget&) function was expected.
It took the widget parameter, then found its dialog and window, and called the given
callback on that dialog object with the window as a parameter. I had left a few remaining
usecases for convenience, but it's not needed anymore.

* Faction Select: window parameter can be directly bound with std::ref
* Unit Create: window parameter not even needed, was only there to satisfy dialog_callback's
  signature.
* MP Create Game: window parameter needed, but I changed it to an in-function variable using
  modal_dialog::get_window. There's no window object to directly bind in the constructor, and
  using the actual callback widget's own get_window method just seems redundant.
  • Loading branch information
Vultraz committed Mar 12, 2018
1 parent 09d3f31 commit eabd374
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/gui/dialogs/multiplayer/faction_select.cpp
Expand Up @@ -68,7 +68,7 @@ void faction_select::pre_show(window& window)
gender_toggle_.set_member_states("random");

gender_toggle_.set_callback_on_value_change(
dialog_callback<faction_select, &faction_select::on_gender_select>);
std::bind(&faction_select::on_gender_select, this, std::ref(window)));

//
// Set up leader menu button
Expand Down
10 changes: 6 additions & 4 deletions src/gui/dialogs/multiplayer/mp_create_game.cpp
Expand Up @@ -82,12 +82,12 @@ mp_create_game::mp_create_game(const config& cfg, saved_game& state, bool local_
, selected_game_index_(-1)
, selected_rfm_index_(-1)
, use_map_settings_(register_bool( "use_map_settings", true, prefs::use_map_settings, prefs::set_use_map_settings,
dialog_callback<mp_create_game, &mp_create_game::update_map_settings>))
std::bind(&mp_create_game::update_map_settings, this)))
, fog_(register_bool("fog", true, prefs::fog, prefs::set_fog))
, shroud_(register_bool("shroud", true, prefs::shroud, prefs::set_shroud))
, start_time_(register_bool("random_start_time", true, prefs::random_start_time, prefs::set_random_start_time))
, time_limit_(register_bool("time_limit", true, prefs::countdown, prefs::set_countdown,
dialog_callback<mp_create_game, &mp_create_game::update_map_settings>))
std::bind(&mp_create_game::update_map_settings, this)))
, shuffle_sides_(register_bool("shuffle_sides", true, prefs::shuffle_sides, prefs::set_shuffle_sides))
, observers_(register_bool("observers", true, prefs::allow_observers, prefs::set_allow_observers))
, registered_users_(register_bool("registered_users", true, prefs::registered_users_only, prefs::set_registered_users_only))
Expand Down Expand Up @@ -541,7 +541,7 @@ void mp_create_game::on_game_select(window& window)
options_manager_->update_game_options();

// Game settings
update_map_settings(window);
update_map_settings();
}

void mp_create_game::on_tab_select(window& window)
Expand Down Expand Up @@ -739,8 +739,10 @@ void mp_create_game::update_details(window& win)
}
}

void mp_create_game::update_map_settings(window& window)
void mp_create_game::update_map_settings()
{
window& window = *get_window();

if(config_engine_->force_lock_settings()) {
use_map_settings_->widget_set_enabled(window, false, false);
use_map_settings_->set_widget_value(window, true);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/multiplayer/mp_create_game.hpp
Expand Up @@ -136,7 +136,7 @@ class mp_create_game : public modal_dialog, private plugin_executor
void show_description(window& window, const std::string& new_description);

void update_details(window& window);
void update_map_settings(window& window);
void update_map_settings();

/**
* Dialog exit hook to bring up the difficulty dialog when starting a campaign.
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dialogs/unit_create.cpp
Expand Up @@ -101,7 +101,7 @@ void unit_create::pre_show(window& window)
gender_toggle.set_member_states(last_gender);

gender_toggle.set_callback_on_value_change(
dialog_callback<unit_create, &unit_create::gender_toggle_callback>);
std::bind(&unit_create::gender_toggle_callback, this));

listbox& list = find_widget<listbox>(&window, "unit_type_list", false);

Expand Down Expand Up @@ -255,7 +255,7 @@ void unit_create::filter_text_changed(text_box_base* textbox, const std::string&
list.set_row_shown(show_items);
}

void unit_create::gender_toggle_callback(window&)
void unit_create::gender_toggle_callback()
{
gender_ = gender_toggle.get_active_member_value();

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/unit_create.hpp
Expand Up @@ -76,7 +76,7 @@ class unit_create : public modal_dialog
/** Callbacks */
void list_item_clicked(window& window);
void filter_text_changed(text_box_base* textbox, const std::string& text);
void gender_toggle_callback(window& window);
void gender_toggle_callback();

void update_displayed_type() const;

Expand Down

0 comments on commit eabd374

Please sign in to comment.