Skip to content

Commit

Permalink
GUI2/Menu Button: changed callbacks to NOTIFY_MODIFIED ones
Browse files Browse the repository at this point in the history
menu_button doesn't even actually inherit from clickable_item. The only reason
[dis]connect_click_handler was declared in this class is the original implementation
was copied extensively from the Button widget.

Using NOTIFY_MODIFIED also means callbacks can fire if set_value/set_selected is used
on a menu_button.

The [dis]connect_click_handler functions were also removed from multimenu_button. All
callbacks for this widget type already used NOTIFY_MODIFIED signals.

(cherry-picked from commit 55f14ff)
  • Loading branch information
Vultraz committed Oct 7, 2018
1 parent 4f34220 commit 247750e
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 42 deletions.
11 changes: 8 additions & 3 deletions src/gui/dialogs/addon/manager.cpp
Expand Up @@ -337,7 +337,9 @@ void addon_manager::pre_show(window& window)
}

status_filter.set_values(status_filter_entries);
status_filter.connect_click_handler(std::bind(&addon_manager::apply_filters, this, std::ref(window)));

connect_signal_notify_modified(status_filter,
std::bind(&addon_manager::apply_filters, this, std::ref(window)));

multimenu_button& type_filter = find_widget<multimenu_button>(&window, "type_filter", false);

Expand All @@ -348,7 +350,8 @@ void addon_manager::pre_show(window& window)

type_filter.set_values(type_filter_entries);

connect_signal_notify_modified(type_filter, std::bind(&addon_manager::apply_filters, this, std::ref(window)));
connect_signal_notify_modified(type_filter,
std::bind(&addon_manager::apply_filters, this, std::ref(window)));

menu_button& order_dropdown = find_widget<menu_button>(&window, "order_dropdown", false);

Expand All @@ -367,7 +370,9 @@ void addon_manager::pre_show(window& window)
}

order_dropdown.set_values(order_dropdown_entries);
order_dropdown.connect_click_handler(std::bind(&addon_manager::order_addons, this, std::ref(window)));

connect_signal_notify_modified(order_dropdown,
std::bind(&addon_manager::order_addons, this, std::ref(window)));

button& url_go_button = find_widget<button>(&window, "url_go", false);
button& url_copy_button = find_widget<button>(&window, "url_copy", false);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/multiplayer/faction_select.cpp
Expand Up @@ -72,7 +72,7 @@ void faction_select::pre_show(window& window)
//
// Set up leader menu button
//
find_widget<menu_button>(&window, "leader_menu", false).connect_click_handler(
connect_signal_notify_modified(find_widget<menu_button>(&window, "leader_menu", false),
std::bind(&faction_select::on_leader_select, this, std::ref(window)));

//
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dialogs/multiplayer/lobby.cpp
Expand Up @@ -769,8 +769,8 @@ void mp_lobby::pre_show(window& window)
replay_options.set_selected(2);
}

replay_options.connect_click_handler(
std::bind(&mp_lobby::skip_replay_changed_callback, this, std::ref(window)));
connect_signal_notify_modified(replay_options,
std::bind(&mp_lobby::skip_replay_changed_callback, this, std::ref(window)));

filter_friends_ = find_widget<toggle_button>(&window, "filter_with_friends", false, true);
filter_ignored_ = find_widget<toggle_button>(&window, "filter_without_ignored", false, true);
Expand Down
12 changes: 9 additions & 3 deletions src/gui/dialogs/multiplayer/mp_create_game.cpp
Expand Up @@ -205,7 +205,9 @@ void mp_create_game::pre_show(window& win)
};

game_menu_button.set_values(game_types, get_initial_type_index());
game_menu_button.connect_click_handler(std::bind(&mp_create_game::update_games_list, this, std::ref(win)));

connect_signal_notify_modified(game_menu_button,
std::bind(&mp_create_game::update_games_list, this, std::ref(win)));

//
// Set up mods list
Expand Down Expand Up @@ -256,7 +258,9 @@ void mp_create_game::pre_show(window& win)
}

eras_menu_button_->set_values(era_names);
eras_menu_button_->connect_click_handler(std::bind(&mp_create_game::on_era_select, this, std::ref(win)));

connect_signal_notify_modified(*eras_menu_button_,
std::bind(&mp_create_game::on_era_select, this, std::ref(win)));

const int era_selection = create_engine_.find_extra_by_id(ng::create_engine::ERA, preferences::era());
if(era_selection >= 0) {
Expand Down Expand Up @@ -289,7 +293,9 @@ void mp_create_game::pre_show(window& win)
menu_button& rfm_menu_button = find_widget<menu_button>(&win, "random_faction_mode", false);

rfm_menu_button.set_values(rfm_options, initial_index);
rfm_menu_button.connect_click_handler(std::bind(&mp_create_game::on_random_faction_mode_select, this, std::ref(win)));

connect_signal_notify_modified(rfm_menu_button,
std::bind(&mp_create_game::on_random_faction_mode_select, this, std::ref(win)));

on_random_faction_mode_select(win);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/multiplayer/mp_options_helper.cpp
Expand Up @@ -286,7 +286,7 @@ void mp_options_helper::display_custom_options(const std::string& type, int node
menu->set_selected(std::distance(combo_values.begin(), iter));
}

menu->connect_click_handler(
connect_signal_notify_modified(*menu,
std::bind(&mp_options_helper::update_options_data_map_menu_button, this, menu, visible_options_.back(), option_cfg));

} else if(opt.key == "slider") {
Expand Down
16 changes: 12 additions & 4 deletions src/gui/dialogs/multiplayer/mp_staging.cpp
Expand Up @@ -209,7 +209,9 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
menu_button& ai_selection = find_widget<menu_button>(&row_grid, "ai_controller", false);

ai_selection.set_values(ai_options, selection);
ai_selection.connect_click_handler(std::bind(&mp_staging::on_ai_select, this, side, std::ref(ai_selection)));

connect_signal_notify_modified(ai_selection,
std::bind(&mp_staging::on_ai_select, this, side, std::ref(ai_selection)));

on_ai_select(side, ai_selection);

Expand All @@ -225,7 +227,9 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)

controller_selection.set_values(controller_names, side->current_controller_index());
controller_selection.set_active(controller_names.size() > 1);
controller_selection.connect_click_handler(std::bind(&mp_staging::on_controller_select, this, side, std::ref(row_grid)));

connect_signal_notify_modified(controller_selection,
std::bind(&mp_staging::on_controller_select, this, side, std::ref(row_grid)));

on_controller_select(side, row_grid);

Expand Down Expand Up @@ -274,7 +278,9 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)

team_selection.set_values(team_names, initial_team_selection);
team_selection.set_active(!saved_game);
team_selection.connect_click_handler(std::bind(&mp_staging::on_team_select, this, std::ref(window), side, std::ref(team_selection), _3, _4));

connect_signal_notify_modified(team_selection,
std::bind(&mp_staging::on_team_select, this, std::ref(window), side, std::ref(team_selection), _3, _4));

//
// Colors
Expand All @@ -292,7 +298,9 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
color_selection.set_values(color_options, side->color());
color_selection.set_active(!saved_game);
color_selection.set_use_markup(true);
color_selection.connect_click_handler(std::bind(&mp_staging::on_color_select, this, side, std::ref(row_grid)));

connect_signal_notify_modified(color_selection,
std::bind(&mp_staging::on_color_select, this, side, std::ref(row_grid)));

//
// Gold and Income
Expand Down
5 changes: 2 additions & 3 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -441,9 +441,8 @@ void preferences_dialog::post_build(window& window)

set_resolution_list(res_list, window.video());

res_list.connect_click_handler(
std::bind(&preferences_dialog::handle_res_select,
this, std::ref(window)));
connect_signal_notify_modified(res_list,
std::bind(&preferences_dialog::handle_res_select, this, std::ref(window)));

/* SHOW FLOATING LABELS */
register_bool("show_floating_labels", true,
Expand Down
4 changes: 3 additions & 1 deletion src/gui/dialogs/statistics_dialog.cpp
Expand Up @@ -74,7 +74,9 @@ void statistics_dialog::pre_show(window& window)
menu_button& scenario_menu = find_widget<menu_button>(&window, "scenario_menu", false);

scenario_menu.set_values(menu_items, selection_index_);
scenario_menu.connect_click_handler(std::bind(&statistics_dialog::on_scenario_select, this, std::ref(window)));

connect_signal_notify_modified(scenario_menu,
std::bind(&statistics_dialog::on_scenario_select, this, std::ref(window)));

//
// Set up primary stats list
Expand Down
12 changes: 0 additions & 12 deletions src/gui/widgets/menu_button.hpp
Expand Up @@ -54,18 +54,6 @@ class menu_button : public styled_widget, public selectable_item
/** See @ref styled_widget::get_state. */
virtual unsigned get_state() const override;

/** Inherited from clickable_item. */
void connect_click_handler(const event::signal_function& signal)
{
connect_signal_mouse_left_click(*this, signal);
}

/** Inherited from clickable_item. */
void disconnect_click_handler(const event::signal_function& signal)
{
disconnect_signal_mouse_left_click(*this, signal);
}

/***** ***** ***** setters / getters for members ***** ****** *****/

void set_values(const std::vector<::config>& values, int selected = 0);
Expand Down
12 changes: 0 additions & 12 deletions src/gui/widgets/multimenu_button.hpp
Expand Up @@ -54,18 +54,6 @@ class multimenu_button : public styled_widget
/** See @ref styled_widget::get_state. */
virtual unsigned get_state() const override;

/** Inherited from clickable_item. */
void connect_click_handler(const event::signal_function& signal)
{
connect_signal_mouse_left_click(*this, signal);
}

/** Inherited from clickable_item. */
void disconnect_click_handler(const event::signal_function& signal)
{
disconnect_signal_mouse_left_click(*this, signal);
}

/***** ***** ***** setters / getters for members ***** ****** *****/

/**
Expand Down

0 comments on commit 247750e

Please sign in to comment.