GUI2: initial work to remove window reference bindings in dialog callbacks

This practice stems from a time before get_window() was available in modal_dialog so the window reference
*had* to be bound to any callback that wanted to use it, resulting in a mess. This is much cleaner.
This commit is contained in:
Charles Dang 2020-11-22 23:34:53 +11:00
parent ba6b5f04aa
commit 0380d634fd
30 changed files with 170 additions and 177 deletions

View file

@ -63,7 +63,7 @@ addon_connect::addon_connect(std::string& host_name,
register_text("host_name", false, host_name, true);
}
void addon_connect::help_button_callback(window& /*window*/)
void addon_connect::help_button_callback()
{
help::show_help("installing_addons");
}
@ -75,9 +75,7 @@ void addon_connect::pre_show(window& window)
connect_signal_mouse_left_click(
find_widget<button>(&window, "show_help", false),
std::bind(&addon_connect::help_button_callback,
this,
std::ref(window)));
std::bind(&addon_connect::help_button_callback, this));
}
void addon_connect::post_show(window& window)

View file

@ -42,7 +42,7 @@ private:
/** Enable the addon remove button? */
bool allow_remove_;
void help_button_callback(window& window);
void help_button_callback();
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;

View file

@ -79,9 +79,9 @@ namespace dialogs
REGISTER_DIALOG(campaign_selection)
void campaign_selection::campaign_selected(window& window)
void campaign_selection::campaign_selected()
{
tree_view& tree = find_widget<tree_view>(&window, "campaign_tree", false);
tree_view& tree = find_widget<tree_view>(get_window(), "campaign_tree", false);
if(tree.empty()) {
return;
}
@ -96,14 +96,14 @@ void campaign_selection::campaign_selected(window& window)
return;
}
multi_page& pages = find_widget<multi_page>(&window, "campaign_details", false);
multi_page& pages = find_widget<multi_page>(get_window(), "campaign_details", false);
pages.select_page(choice);
engine_.set_current_level(choice);
}
}
void campaign_selection::sort_campaigns(window& window, campaign_selection::CAMPAIGN_ORDER order, bool ascending)
void campaign_selection::sort_campaigns(campaign_selection::CAMPAIGN_ORDER order, bool ascending)
{
using level_ptr = ng::create_engine::level_ptr;
@ -147,7 +147,7 @@ void campaign_selection::sort_campaigns(window& window, campaign_selection::CAMP
break;
}
tree_view& tree = find_widget<tree_view>(&window, "campaign_tree", false);
tree_view& tree = find_widget<tree_view>(get_window(), "campaign_tree", false);
// Remember which campaign was selected...
std::string was_selected;
@ -182,7 +182,7 @@ void campaign_selection::sort_campaigns(window& window, campaign_selection::CAMP
bool exists_in_filtered_result = false;
for(unsigned i = 0; i < levels.size(); ++i) {
if(show_items[i]) {
add_campaign_to_tree(window, levels[i]->data());
add_campaign_to_tree(levels[i]->data());
if (!exists_in_filtered_result) {
exists_in_filtered_result = levels[i]->id() == was_selected;
@ -191,13 +191,13 @@ void campaign_selection::sort_campaigns(window& window, campaign_selection::CAMP
}
if(!was_selected.empty() && exists_in_filtered_result) {
find_widget<tree_view_node>(&window, was_selected, false).select_node();
find_widget<tree_view_node>(get_window(), was_selected, false).select_node();
} else {
campaign_selected(window);
campaign_selected();
}
}
void campaign_selection::toggle_sorting_selection(window& window, CAMPAIGN_ORDER order)
void campaign_selection::toggle_sorting_selection(CAMPAIGN_ORDER order)
{
static bool force = false;
if(force) {
@ -221,15 +221,15 @@ void campaign_selection::toggle_sorting_selection(window& window, CAMPAIGN_ORDER
force = true;
if(order == NAME) {
find_widget<toggle_button>(&window, "sort_time", false).set_value(0);
find_widget<toggle_button>(get_window(), "sort_time", false).set_value(0);
} else if(order == DATE) {
find_widget<toggle_button>(&window, "sort_name", false).set_value(0);
find_widget<toggle_button>(get_window(), "sort_name", false).set_value(0);
}
force = false;
}
sort_campaigns(window, current_sorting_, currently_sorted_asc_);
sort_campaigns(current_sorting_, currently_sorted_asc_);
}
void campaign_selection::filter_text_changed(text_box_base* textbox, const std::string& text)
@ -241,8 +241,7 @@ void campaign_selection::filter_text_changed(text_box_base* textbox, const std::
}
last_search_words_ = words;
window& window = *textbox->get_window();
sort_campaigns(window, current_sorting_, currently_sorted_asc_);
sort_campaigns(current_sorting_, currently_sorted_asc_);
}
void campaign_selection::pre_show(window& window)
@ -255,16 +254,16 @@ void campaign_selection::pre_show(window& window)
tree_view& tree = find_widget<tree_view>(&window, "campaign_tree", false);
connect_signal_notify_modified(tree,
std::bind(&campaign_selection::campaign_selected, this, std::ref(window)));
std::bind(&campaign_selection::campaign_selected, this));
toggle_button& sort_name = find_widget<toggle_button>(&window, "sort_name", false);
toggle_button& sort_time = find_widget<toggle_button>(&window, "sort_time", false);
connect_signal_notify_modified(sort_name,
std::bind(&campaign_selection::toggle_sorting_selection, this, std::ref(window), NAME));
std::bind(&campaign_selection::toggle_sorting_selection, this, NAME));
connect_signal_notify_modified(sort_time,
std::bind(&campaign_selection::toggle_sorting_selection, this, std::ref(window), DATE));
std::bind(&campaign_selection::toggle_sorting_selection, this, DATE));
window.keyboard_capture(filter);
window.add_to_keyboard_chain(&tree);
@ -276,7 +275,7 @@ void campaign_selection::pre_show(window& window)
const config& campaign = level->data();
/*** Add tree item ***/
add_campaign_to_tree(window, campaign);
add_campaign_to_tree(campaign);
/*** Add detail item ***/
std::map<std::string, string_map> data;
@ -318,18 +317,18 @@ void campaign_selection::pre_show(window& window)
mods_menu.set_values(mod_menu_values);
mods_menu.select_options(mod_states_);
connect_signal_notify_modified(mods_menu, std::bind(&campaign_selection::mod_toggled, this, std::ref(window)));
connect_signal_notify_modified(mods_menu, std::bind(&campaign_selection::mod_toggled, this));
} else {
mods_menu.set_active(false);
mods_menu.set_label(_("active_modifications^None"));
}
campaign_selected(window);
campaign_selected();
}
void campaign_selection::add_campaign_to_tree(window& window, const config& campaign)
void campaign_selection::add_campaign_to_tree(const config& campaign)
{
tree_view& tree = find_widget<tree_view>(&window, "campaign_tree", false);
tree_view& tree = find_widget<tree_view>(get_window(), "campaign_tree", false);
std::map<std::string, string_map> data;
string_map item;
@ -395,10 +394,10 @@ void campaign_selection::post_show(window& window)
preferences::set_modifications(engine_.active_mods(), false);
}
void campaign_selection::mod_toggled(window& window)
void campaign_selection::mod_toggled()
{
boost::dynamic_bitset<> new_mod_states =
find_widget<multimenu_button>(&window, "mods_menu", false).get_toggle_states();
find_widget<multimenu_button>(get_window(), "mods_menu", false).get_toggle_states();
// Get a mask of any mods that were toggled, regardless of new state
mod_states_ = mod_states_ ^ new_mod_states;

View file

@ -56,7 +56,7 @@ public:
private:
/** Called when another campaign is selected. */
void campaign_selected(window& window);
void campaign_selected();
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;
@ -67,13 +67,13 @@ private:
/** Inherited from modal_dialog. */
virtual void post_show(window& window) override;
void sort_campaigns(window& window, CAMPAIGN_ORDER order, bool ascending);
void sort_campaigns(CAMPAIGN_ORDER order, bool ascending);
void add_campaign_to_tree(window& window, const config& campaign);
void add_campaign_to_tree(const config& campaign);
void toggle_sorting_selection(window& window, CAMPAIGN_ORDER order);
void toggle_sorting_selection(CAMPAIGN_ORDER order);
void mod_toggled(window& window);
void mod_toggled();
void filter_text_changed(text_box_base* textbox, const std::string &text);

View file

@ -66,14 +66,14 @@ namespace dialogs
REGISTER_DIALOG(core_selection)
void core_selection::core_selected(window& window)
void core_selection::core_selected()
{
const int selected_row
= find_widget<listbox>(&window, "core_list", false)
= find_widget<listbox>(get_window(), "core_list", false)
.get_selected_row();
multi_page& pages
= find_widget<multi_page>(&window, "core_details", false);
= find_widget<multi_page>(get_window(), "core_details", false);
pages.select_page(selected_row);
}
@ -83,7 +83,7 @@ void core_selection::pre_show(window& window)
/***** Setup core list. *****/
listbox& list = find_widget<listbox>(&window, "core_list", false);
connect_signal_notify_modified(list, std::bind(&core_selection::core_selected, this, std::ref(window)));
connect_signal_notify_modified(list, std::bind(&core_selection::core_selected, this));
window.keyboard_capture(&list);
@ -118,7 +118,7 @@ void core_selection::pre_show(window& window)
}
list.select_row(choice_, true);
core_selected(window);
core_selected();
}
void core_selection::post_show(window& window)

View file

@ -41,7 +41,7 @@ public:
private:
/** Called when another core is selected. */
void core_selected(window& window);
void core_selected();
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;

View file

@ -239,19 +239,19 @@ void game_stats::pre_show(window& window)
window.keyboard_capture(&tab_bar);
connect_signal_notify_modified(tab_bar, std::bind(&game_stats::on_tab_select, this, std::ref(window)));
connect_signal_notify_modified(tab_bar, std::bind(&game_stats::on_tab_select, this));
on_tab_select(window);
on_tab_select();
}
void game_stats::on_tab_select(window& window)
void game_stats::on_tab_select()
{
const int i = find_widget<listbox>(&window, "tab_bar", false).get_selected_row();
const int i = find_widget<listbox>(get_window(), "tab_bar", false).get_selected_row();
find_widget<stacked_widget>(&window, "pager", false).select_layer(i);
find_widget<stacked_widget>(get_window(), "pager", false).select_layer(i);
// There are only two tabs, so this is simple
find_widget<label>(&window, "title", false).set_label(
find_widget<label>(get_window(), "title", false).set_label(
i == 0 ? _("Current Status") : _("Scenario Settings")
);
}

View file

@ -59,7 +59,7 @@ private:
unit_const_ptr get_leader(const int side);
void on_tab_select(window& window);
void on_tab_select();
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;

View file

@ -269,15 +269,15 @@ void game_version::pre_show(window& window)
VALIDATE(tab_count == pager.get_layer_count(), "Tab bar and container size mismatch");
connect_signal_notify_modified(tab_bar,
std::bind(&game_version::tab_switch_callback, this, std::ref(window)));
std::bind(&game_version::tab_switch_callback, this));
}
void game_version::tab_switch_callback(window& window)
void game_version::tab_switch_callback()
{
stacked_widget& pager
= find_widget<stacked_widget>(&window, "tabs_container", false);
= find_widget<stacked_widget>(get_window(), "tabs_container", false);
listbox& tab_bar
= find_widget<listbox>(&window, "tab_bar", false);
= find_widget<listbox>(get_window(), "tab_bar", false);
pager.select_layer(std::max<int>(0, tab_bar.get_selected_row()));
}

View file

@ -77,7 +77,7 @@ private:
/**
* Callback function called when switching tabs.
*/
void tab_switch_callback(window& window);
void tab_switch_callback();
/**
* Callback function for the dialog-wide copy-to-clipboard button.

View file

@ -56,7 +56,7 @@ void help_browser::pre_show(window& window)
multi_page& topic_pages = find_widget<multi_page>(&window, "topic_text_pages", false);
connect_signal_notify_modified(topic_tree,
std::bind(&help_browser::on_topic_select, this, std::ref(window)));
std::bind(&help_browser::on_topic_select, this));
window.keyboard_capture(&topic_tree);
@ -83,12 +83,12 @@ void help_browser::pre_show(window& window)
++id;
}
on_topic_select(window);
on_topic_select();
}
void help_browser::on_topic_select(window& window)
void help_browser::on_topic_select()
{
tree_view& tree = find_widget<tree_view>(&window, "topic_tree", false);
tree_view& tree = find_widget<tree_view>(get_window(), "topic_tree", false);
if(tree.empty()) {
return;
@ -101,7 +101,7 @@ void help_browser::on_topic_select(window& window)
}
const unsigned topic_i = lexical_cast<unsigned>(tree.selected_item()->id());
find_widget<multi_page>(&window, "topic_text_pages", false).select_page(topic_i);
find_widget<multi_page>(get_window(), "topic_text_pages", false).select_page(topic_i);
}

View file

@ -41,7 +41,7 @@ private:
/** Inherited from modal_dialog. */
virtual void pre_show(window& window) override;
void on_topic_select(window& window);
void on_topic_select();
};
} // namespace dialogs

View file

@ -69,17 +69,17 @@ void faction_select::pre_show(window& window)
gender_toggle_.set_member_states("random");
gender_toggle_.set_callback_on_value_change(
std::bind(&faction_select::on_gender_select, this, std::ref(window)));
std::bind(&faction_select::on_gender_select, this));
//
// Set up leader menu button
//
connect_signal_notify_modified(find_widget<menu_button>(&window, "leader_menu", false),
std::bind(&faction_select::on_leader_select, this, std::ref(window)));
std::bind(&faction_select::on_leader_select, this));
// Leader's profile button
find_widget<button>(&window, "type_profile", false).connect_click_handler(
std::bind(&faction_select::profile_button_callback, this, std::ref(window)));
std::bind(&faction_select::profile_button_callback, this));
//
// Set up faction list
@ -89,7 +89,7 @@ void faction_select::pre_show(window& window)
window.keyboard_capture(&list);
connect_signal_notify_modified(list,
std::bind(&faction_select::on_faction_select, this, std::ref(window)));
std::bind(&faction_select::on_faction_select, this));
for(const config *s : flg_manager_.choosable_factions()) {
const config& side = *s;
@ -112,12 +112,12 @@ void faction_select::pre_show(window& window)
list.select_row(flg_manager_.current_faction_index());
on_faction_select(window);
on_faction_select();
}
void faction_select::on_faction_select(window& window)
void faction_select::on_faction_select()
{
const int selected_row = find_widget<listbox>(&window, "faction_list", false).get_selected_row();
const int selected_row = find_widget<listbox>(get_window(), "faction_list", false).get_selected_row();
if(selected_row == -1) {
return;
@ -146,12 +146,12 @@ void faction_select::on_faction_select(window& window)
}
}
menu_button& leader_dropdown = find_widget<menu_button>(&window, "leader_menu", false);
menu_button& leader_dropdown = find_widget<menu_button>(get_window(), "leader_menu", false);
leader_dropdown.set_values(leaders, std::min<int>(leaders.size() - 1, previous_leader_selection));
leader_dropdown.set_active(leaders.size() > 1 && !flg_manager_.is_saved_game());
on_leader_select(window);
on_leader_select();
// Print recruits
const std::vector<std::string> recruit_list = utils::split(flg_manager_.current_faction()["recruit"]);
@ -167,12 +167,12 @@ void faction_select::on_faction_select(window& window)
return translation::compare(s1, s2) < 0;
});
find_widget<styled_widget>(&window, "recruits", false).set_label(utils::join(recruit_names, "\n"));
find_widget<styled_widget>(get_window(), "recruits", false).set_label(utils::join(recruit_names, "\n"));
}
void faction_select::on_leader_select(window& window)
void faction_select::on_leader_select()
{
flg_manager_.set_current_leader(find_widget<menu_button>(&window, "leader_menu", false).get_value());
flg_manager_.set_current_leader(find_widget<menu_button>(get_window(), "leader_menu", false).get_value());
// TODO: should we decouple this from the flg manager and instead just check the unit type directly?
// If that's done so, we'd need to come up with a different check for Random availability.
@ -181,17 +181,17 @@ void faction_select::on_leader_select(window& window)
return std::find(genders.begin(), genders.end(), gender) != genders.end();
});
update_leader_image(window);
update_leader_image();
// Disable the profile button if leader_type is dash or "Random"
button& profile_button = find_widget<button>(&window, "type_profile", false);
const std::string& leader_type = find_widget<menu_button>(&window, "leader_menu", false).get_value_string();
button& profile_button = find_widget<button>(get_window(), "type_profile", false);
const std::string& leader_type = find_widget<menu_button>(get_window(), "leader_menu", false).get_value_string();
profile_button.set_active(unit_types.find(leader_type) != nullptr);
}
void faction_select::profile_button_callback(window& window)
void faction_select::profile_button_callback()
{
const std::string& leader_type = find_widget<menu_button>(&window, "leader_menu", false).get_value_string();
const std::string& leader_type = find_widget<menu_button>(get_window(), "leader_menu", false).get_value_string();
const unit_type* ut = unit_types.find(leader_type);
if(ut != nullptr) {
preferences::encountered_units().insert(ut->id());
@ -200,14 +200,14 @@ void faction_select::profile_button_callback(window& window)
}
}
void faction_select::on_gender_select(window& window)
void faction_select::on_gender_select()
{
flg_manager_.set_current_gender(gender_toggle_.get_active_member_value());
update_leader_image(window);
update_leader_image();
}
void faction_select::update_leader_image(window& window)
void faction_select::update_leader_image()
{
std::string leader_image = ng::random_enemy_picture;
@ -216,7 +216,7 @@ void faction_select::update_leader_image(window& window)
leader_image = formatter() << utg.image() << "~RC(" << utg.flag_rgb() << ">" << tc_color_ << ")" << "~SCALE_INTO_SHARP(144,144)";
}
find_widget<image>(&window, "leader_image", false).set_label(leader_image);
find_widget<image>(get_window(), "leader_image", false).set_label(leader_image);
}
void faction_select::post_show(window& /*window*/)

View file

@ -54,15 +54,15 @@ private:
virtual void post_show(window& window) override;
/** Callbacks */
void on_faction_select(window& window);
void on_faction_select();
void on_leader_select(window& window);
void on_leader_select();
void profile_button_callback(window& window);
void profile_button_callback();
void on_gender_select(window& window);
void on_gender_select();
void update_leader_image(window& window);
void update_leader_image();
};
} // namespace dialogs

View file

@ -47,13 +47,13 @@ void server_info::pre_show(window& window)
VALIDATE(tab_bar.get_item_count() == pager.get_layer_count(), "Tab bar and container size mismatch");
connect_signal_notify_modified(tab_bar, std::bind(&server_info::tab_switch_callback, this, std::ref(window)));
connect_signal_notify_modified(tab_bar, std::bind(&server_info::tab_switch_callback, this));
}
void server_info::tab_switch_callback(window& window)
void server_info::tab_switch_callback()
{
stacked_widget& pager = find_widget<stacked_widget>(&window, "tabs_container", false);
listbox& tab_bar = find_widget<listbox>(&window, "tab_bar", false);
stacked_widget& pager = find_widget<stacked_widget>(get_window(), "tabs_container", false);
listbox& tab_bar = find_widget<listbox>(get_window(), "tab_bar", false);
pager.select_layer(std::max<int>(0, tab_bar.get_selected_row()));
}

View file

@ -46,7 +46,7 @@ private:
/** Inherited from modal_dialog. */
virtual void pre_show(window& window) override;
void tab_switch_callback(window& window);
void tab_switch_callback();
const std::string& server_information_;
const std::string& announcements_;

View file

@ -90,7 +90,7 @@ void statistics_dialog::pre_show(window& window)
scenario_menu.set_values(menu_items, selection_index_);
connect_signal_notify_modified(scenario_menu,
std::bind(&statistics_dialog::on_scenario_select, this, std::ref(window)));
std::bind(&statistics_dialog::on_scenario_select, this));
//
// Set up primary stats list
@ -98,9 +98,9 @@ void statistics_dialog::pre_show(window& window)
listbox& stat_list = find_widget<listbox>(&window, "stats_list_main", false);
connect_signal_notify_modified(stat_list,
std::bind(&statistics_dialog::on_primary_list_select, this, std::ref(window)));
std::bind(&statistics_dialog::on_primary_list_select, this));
update_lists(window);
update_lists();
}
inline const statistics::stats& statistics_dialog::current_stats()
@ -108,9 +108,9 @@ inline const statistics::stats& statistics_dialog::current_stats()
return selection_index_ == 0 ? campaign_ : *scenarios_[selection_index_ - 1].second;
}
void statistics_dialog::add_stat_row(window& window, const std::string& type, const statistics::stats::str_int_map& value, const bool has_cost)
void statistics_dialog::add_stat_row(const std::string& type, const statistics::stats::str_int_map& value, const bool has_cost)
{
listbox& stat_list = find_widget<listbox>(&window, "stats_list_main", false);
listbox& stat_list = find_widget<listbox>(get_window(), "stats_list_main", false);
std::map<std::string, string_map> data;
string_map item;
@ -145,7 +145,6 @@ static std::ostream& write_actual_and_expected(std::ostream& str, const long lon
}
void statistics_dialog::add_damage_row(
window& window,
const std::string& type,
const long long& damage,
const long long& expected,
@ -153,7 +152,7 @@ void statistics_dialog::add_damage_row(
const long long& turn_expected,
const bool show_this_turn)
{
listbox& damage_list = find_widget<listbox>(&window, "stats_list_damage", false);
listbox& damage_list = find_widget<listbox>(get_window(), "stats_list_damage", false);
std::map<std::string, string_map> data;
string_map item;
@ -177,7 +176,7 @@ void statistics_dialog::add_damage_row(
data.emplace("overall_score", item);
if(show_this_turn) {
label& this_turn_header = find_widget<label>(&window, "damage_this_turn_header", false);
label& this_turn_header = find_widget<label>(get_window(), "damage_this_turn_header", false);
this_turn_header.set_label(_("This Turn"));
item["label"] = damage_str(turn_damage, turn_expected);
@ -186,8 +185,8 @@ void statistics_dialog::add_damage_row(
item["label"] = "";
data.emplace("this_turn_score", item);
} else {
// TODO: Setting the label to "" causes "This Turn" not to be drawn when changing back to the current scenraio view, so set the label to " " (a single space) instead.
label& this_turn_header = find_widget<label>(&window, "damage_this_turn_header", false);
// TODO: Setting the label to "" causes "This Turn" not to be drawn when changing back to the current scenario view, so set the label to " " (a single space) instead.
label& this_turn_header = find_widget<label>(get_window(), "damage_this_turn_header", false);
this_turn_header.set_label(" ");
}
@ -307,14 +306,13 @@ static hitrate_table_element tally(const statistics::stats::hitrate_map& by_cth,
}
void statistics_dialog::add_hits_row(
window& window,
const std::string& type,
const bool more_is_better,
const statistics::stats::hitrate_map& by_cth,
const statistics::stats::hitrate_map& turn_by_cth,
const bool show_this_turn)
{
listbox& hits_list = find_widget<listbox>(&window, "stats_list_hits", false);
listbox& hits_list = find_widget<listbox>(get_window(), "stats_list_hits", false);
std::map<std::string, string_map> data;
string_map item;
@ -337,7 +335,7 @@ void statistics_dialog::add_hits_row(
data.emplace("overall_score", string_map { { "label", element.pvalue_str } });
if(show_this_turn) {
label& this_turn_header = find_widget<label>(&window, "hits_this_turn_header", false);
label& this_turn_header = find_widget<label>(get_window(), "hits_this_turn_header", false);
this_turn_header.set_label(_("This Turn"));
element = tally(turn_by_cth, more_is_better);
@ -348,20 +346,20 @@ void statistics_dialog::add_hits_row(
// Don't set the tooltip; it's set in WML.
data.emplace("this_turn_score", string_map { { "label", element.pvalue_str } });
} else {
// TODO: Setting the label to "" causes "This Turn" not to be drawn when changing back to the current scenraio view, so set the label to " " (a single space) instead.
label& this_turn_header = find_widget<label>(&window, "hits_this_turn_header", false);
// TODO: Setting the label to "" causes "This Turn" not to be drawn when changing back to the current scenario view, so set the label to " " (a single space) instead.
label& this_turn_header = find_widget<label>(get_window(), "hits_this_turn_header", false);
this_turn_header.set_label(" ");
}
hits_list.add_row(data);
}
void statistics_dialog::update_lists(window& window)
void statistics_dialog::update_lists()
{
//
// Update primary stats list
//
listbox& stat_list = find_widget<listbox>(&window, "stats_list_main", false);
listbox& stat_list = find_widget<listbox>(get_window(), "stats_list_main", false);
const int last_selected_stat_row = stat_list.get_selected_row();
stat_list.clear();
@ -369,11 +367,11 @@ void statistics_dialog::update_lists(window& window)
const statistics::stats& stats = current_stats();
add_stat_row(window, _("Recruits"), stats.recruits);
add_stat_row(window, _("Recalls"), stats.recalls);
add_stat_row(window, _("Advancements"), stats.advanced_to, false);
add_stat_row(window, _("Losses"), stats.deaths);
add_stat_row(window, _("Kills"), stats.killed);
add_stat_row(_("Recruits"), stats.recruits);
add_stat_row(_("Recalls"), stats.recalls);
add_stat_row(_("Advancements"), stats.advanced_to, false);
add_stat_row(_("Losses"), stats.deaths);
add_stat_row(_("Kills"), stats.killed);
// Reselect previously selected row. Do this *before* calling on_primary_list_select.
if(last_selected_stat_row != -1) {
@ -381,65 +379,65 @@ void statistics_dialog::update_lists(window& window)
}
// Update unit count list
on_primary_list_select(window);
on_primary_list_select();
//
// Update damage stats list
//
const bool show_this_turn = selection_index_ == scenarios_.size();
listbox& damage_list = find_widget<listbox>(&window, "stats_list_damage", false);
listbox& damage_list = find_widget<listbox>(get_window(), "stats_list_damage", false);
damage_list.clear();
listbox& hits_list = find_widget<listbox>(&window, "stats_list_hits", false);
listbox& hits_list = find_widget<listbox>(get_window(), "stats_list_hits", false);
hits_list.clear();
add_damage_row(window, _("Inflicted"),
add_damage_row(_("Inflicted"),
stats.damage_inflicted,
stats.expected_damage_inflicted,
stats.turn_damage_inflicted,
stats.turn_expected_damage_inflicted,
show_this_turn
);
add_hits_row(window, _("Inflicted"), true,
add_hits_row(_("Inflicted"), true,
stats.by_cth_inflicted,
stats.turn_by_cth_inflicted,
show_this_turn
);
add_damage_row(window, _("Taken"),
add_damage_row(_("Taken"),
stats.damage_taken,
stats.expected_damage_taken,
stats.turn_damage_taken,
stats.turn_expected_damage_taken,
show_this_turn
);
add_hits_row(window, _("Taken"), false,
add_hits_row(_("Taken"), false,
stats.by_cth_taken,
stats.turn_by_cth_taken,
show_this_turn
);
}
void statistics_dialog::on_scenario_select(window& window)
void statistics_dialog::on_scenario_select()
{
const std::size_t new_index = find_widget<menu_button>(&window, "scenario_menu", false).get_value();
const std::size_t new_index = find_widget<menu_button>(get_window(), "scenario_menu", false).get_value();
if(selection_index_ != new_index) {
selection_index_ = new_index;
update_lists(window);
update_lists();
}
}
void statistics_dialog::on_primary_list_select(window& window)
void statistics_dialog::on_primary_list_select()
{
const int selected_row = find_widget<listbox>(&window, "stats_list_main", false).get_selected_row();
const int selected_row = find_widget<listbox>(get_window(), "stats_list_main", false).get_selected_row();
if(selected_row == -1) {
return;
}
listbox& unit_list = find_widget<listbox>(&window, "stats_list_units", false);
listbox& unit_list = find_widget<listbox>(get_window(), "stats_list_units", false);
unit_list.clear();

View file

@ -43,11 +43,10 @@ private:
*/
inline const statistics::stats& current_stats();
void add_stat_row(window& window, const std::string& type, const statistics::stats::str_int_map& value, const bool has_cost = true);
void add_stat_row(const std::string& type, const statistics::stats::str_int_map& value, const bool has_cost = true);
/// Add a row to the Damage table
void add_damage_row(
window& window,
const std::string& type,
const long long& damage,
const long long& expected,
@ -59,17 +58,16 @@ private:
///
/// @param more_is_better True for "Inflicted" and false for "Taken". Affects coloring.
void add_hits_row(
window& window,
const std::string& type,
const bool more_is_better,
const statistics::stats::hitrate_map& by_cth,
const statistics::stats::hitrate_map& turn_by_cth,
const bool show_this_turn);
void update_lists(window& window);
void update_lists();
void on_primary_list_select(window& window);
void on_scenario_select(window& window);
void on_primary_list_select();
void on_scenario_select();
const team& current_team_;

View file

@ -47,7 +47,7 @@ void unit_advance::pre_show(window& window)
{
listbox& list = find_widget<listbox>(&window, "advance_choice", false);
connect_signal_notify_modified(list, std::bind(&unit_advance::list_item_clicked, this, std::ref(window)));
connect_signal_notify_modified(list, std::bind(&unit_advance::list_item_clicked, this));
window.keyboard_capture(&list);
@ -88,22 +88,22 @@ void unit_advance::pre_show(window& window)
list.add_row(row_data);
}
list_item_clicked(window);
list_item_clicked();
// Disable ESC existing
window.set_escape_disabled(true);
}
void unit_advance::list_item_clicked(window& window)
void unit_advance::list_item_clicked()
{
const int selected_row
= find_widget<listbox>(&window, "advance_choice", false).get_selected_row();
= find_widget<listbox>(get_window(), "advance_choice", false).get_selected_row();
if(selected_row == -1) {
return;
}
find_widget<unit_preview_pane>(&window, "advancement_details", false)
find_widget<unit_preview_pane>(get_window(), "advancement_details", false)
.set_displayed_unit(*previews_[selected_row]);
}

View file

@ -40,7 +40,7 @@ private:
virtual void pre_show(window& window) override;
virtual void post_show(window& window) override;
void list_item_clicked(window& window);
void list_item_clicked();
void show_help();

View file

@ -81,9 +81,9 @@ unit_attack::unit_attack(const unit_map::iterator& attacker_itor,
{
}
void unit_attack::damage_calc_callback(window& window)
void unit_attack::damage_calc_callback()
{
const std::size_t index = find_widget<listbox>(&window, "weapon_list", false).get_selected_row();
const std::size_t index = find_widget<listbox>(get_window(), "weapon_list", false).get_selected_row();
attack_predictions::display(weapons_[index], attacker_itor_.get_shared_ptr(), defender_itor_.get_shared_ptr());
}
@ -91,7 +91,7 @@ void unit_attack::pre_show(window& window)
{
connect_signal_mouse_left_click(
find_widget<button>(&window, "damage_calculation", false),
std::bind(&unit_attack::damage_calc_callback, this, std::ref(window)));
std::bind(&unit_attack::damage_calc_callback, this));
find_widget<unit_preview_pane>(&window, "attacker_pane", false)
.set_displayed_unit(*attacker_itor_);

View file

@ -48,7 +48,7 @@ private:
/** Inherited from modal_dialog. */
virtual void post_show(window& window) override;
void damage_calc_callback(window& window);
void damage_calc_callback();
/** The index of the selected weapon. */
int selected_weapon_;

View file

@ -115,7 +115,7 @@ void unit_create::pre_show(window& window)
window.keyboard_capture(filter);
window.add_to_keyboard_chain(&list);
connect_signal_notify_modified(list, std::bind(&unit_create::list_item_clicked, this, std::ref(window)));
connect_signal_notify_modified(list, std::bind(&unit_create::list_item_clicked, this));
list.clear();
@ -157,7 +157,7 @@ void unit_create::pre_show(window& window)
// Select the first entry on sort if no previous selection was provided.
list.set_active_sorting_option({0, preferences::SORT_ORDER::ASCENDING}, choice_.empty());
list_item_clicked(window);
list_item_clicked();
}
void unit_create::post_show(window& window)
@ -207,10 +207,10 @@ void unit_create::update_displayed_type() const
find_widget<unit_preview_pane>(w, "unit_details", false).set_displayed_type(*ut);
}
void unit_create::list_item_clicked(window& window)
void unit_create::list_item_clicked()
{
const int selected_row
= find_widget<listbox>(&window, "unit_type_list", false).get_selected_row();
= find_widget<listbox>(get_window(), "unit_type_list", false).get_selected_row();
if(selected_row == -1) {
return;
@ -222,7 +222,7 @@ void unit_create::list_item_clicked(window& window)
return units_[selected_row]->has_gender_variation(gender);
});
menu_button& var_box = find_widget<menu_button>(&window, "variation_box", false);
menu_button& var_box = find_widget<menu_button>(get_window(), "variation_box", false);
std::vector<config> var_box_values;
var_box_values.emplace_back("label", _("unit_variation^Default Variation"), "variation_id", "");

View file

@ -83,7 +83,7 @@ private:
virtual void post_show(window& window) override;
/** Callbacks */
void list_item_clicked(window& window);
void list_item_clicked();
void filter_text_changed(text_box_base* textbox, const std::string& text);
void gender_toggle_callback();
void variation_menu_callback();

View file

@ -92,7 +92,7 @@ void unit_list::pre_show(window& window)
{
listbox& list = find_widget<listbox>(&window, "units_list", false);
connect_signal_notify_modified(list, std::bind(&unit_list::list_item_clicked, this, std::ref(window)));
connect_signal_notify_modified(list, std::bind(&unit_list::list_item_clicked, this));
list.clear();
@ -171,19 +171,19 @@ void unit_list::pre_show(window& window)
list.register_translatable_sorting_option(6, [this](const int i) {
return !unit_list_[i]->trait_names().empty() ? unit_list_[i]->trait_names().front().str() : ""; });
list_item_clicked(window);
list_item_clicked();
}
void unit_list::list_item_clicked(window& window)
void unit_list::list_item_clicked()
{
const int selected_row
= find_widget<listbox>(&window, "units_list", false).get_selected_row();
= find_widget<listbox>(get_window(), "units_list", false).get_selected_row();
if(selected_row == -1) {
return;
}
find_widget<unit_preview_pane>(&window, "unit_details", false)
find_widget<unit_preview_pane>(get_window(), "unit_details", false)
.set_displayed_unit(*unit_list_[selected_row].get());
}

View file

@ -55,7 +55,7 @@ private:
map_location& scroll_to_;
/** Callbacks */
void list_item_clicked(window& window);
void list_item_clicked();
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;

View file

@ -171,7 +171,7 @@ void unit_recall::pre_show(window& window)
listbox& list = find_widget<listbox>(&window, "recall_list", false);
connect_signal_notify_modified(list, std::bind(&unit_recall::list_item_clicked, this, std::ref(window)));
connect_signal_notify_modified(list, std::bind(&unit_recall::list_item_clicked, this));
list.clear();
@ -180,11 +180,11 @@ void unit_recall::pre_show(window& window)
connect_signal_mouse_left_click(
find_widget<button>(&window, "rename", false),
std::bind(&unit_recall::rename_unit, this, std::ref(window)));
std::bind(&unit_recall::rename_unit, this));
connect_signal_mouse_left_click(
find_widget<button>(&window, "dismiss", false),
std::bind(&unit_recall::dismiss_unit, this, std::ref(window)));
std::bind(&unit_recall::dismiss_unit, this));
connect_signal_mouse_left_click(
find_widget<button>(&window, "show_help", false),
@ -305,12 +305,12 @@ void unit_recall::pre_show(window& window)
list.set_active_sorting_option(sort_last.first >= 0 ? sort_last : sort_default, true);
list_item_clicked(window);
list_item_clicked();
}
void unit_recall::rename_unit(window& window)
void unit_recall::rename_unit()
{
listbox& list = find_widget<listbox>(&window, "recall_list", false);
listbox& list = find_widget<listbox>(get_window(), "recall_list", false);
const int index = list.get_selected_row();
if (index == -1) {
@ -336,16 +336,16 @@ void unit_recall::rename_unit(window& window)
}
filter_options_.insert(filter_options_.begin() + index, filter_text.str());
list_item_clicked(window);
window.invalidate_layout();
list_item_clicked();
get_window()->invalidate_layout();
}
}
void unit_recall::dismiss_unit(window& window)
void unit_recall::dismiss_unit()
{
LOG_DP << "Recall list units:\n"; dump_recall_list_to_console(recall_list_);
listbox& list = find_widget<listbox>(&window, "recall_list", false);
listbox& list = find_widget<listbox>(get_window(), "recall_list", false);
const int index = list.get_selected_row();
if (index == -1) {
return;
@ -383,7 +383,7 @@ void unit_recall::dismiss_unit(window& window)
// Remove the entry from the dialog list
list.remove_row(index);
list_item_clicked(window);
list_item_clicked();
// Remove the entry from the filter list
filter_options_.erase(filter_options_.begin() + index);
@ -402,7 +402,7 @@ void unit_recall::dismiss_unit(window& window)
// Close the dialog if all units are dismissed
if(list.get_item_count() == 0) {
window.set_retval(retval::CANCEL);
get_window()->set_retval(retval::CANCEL);
}
}
@ -411,10 +411,10 @@ void unit_recall::show_help()
help::show_help("recruit_and_recall");
}
void unit_recall::list_item_clicked(window& window)
void unit_recall::list_item_clicked()
{
const int selected_row
= find_widget<listbox>(&window, "recall_list", false).get_selected_row();
= find_widget<listbox>(get_window(), "recall_list", false).get_selected_row();
if(selected_row == -1) {
return;
@ -422,10 +422,10 @@ void unit_recall::list_item_clicked(window& window)
const unit& selected_unit = *recall_list_[selected_row].get();
find_widget<unit_preview_pane>(&window, "unit_details", false)
find_widget<unit_preview_pane>(get_window(), "unit_details", false)
.set_displayed_unit(selected_unit);
find_widget<button>(&window, "rename", false).set_active(!selected_unit.unrenamable());
find_widget<button>(get_window(), "rename", false).set_active(!selected_unit.unrenamable());
}
void unit_recall::post_show(window& window)

View file

@ -55,10 +55,10 @@ private:
std::vector<std::string> last_words_;
/** Callbacks */
void list_item_clicked(window& window);
void list_item_clicked();
void filter_text_changed(text_box_base* textbox, const std::string& text);
void rename_unit(window& window);
void dismiss_unit(window& window);
void rename_unit();
void dismiss_unit();
void show_help();
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */

View file

@ -116,7 +116,7 @@ void unit_recruit::pre_show(window& window)
listbox& list = find_widget<listbox>(&window, "recruit_list", false);
connect_signal_notify_modified(list, std::bind(&unit_recruit::list_item_clicked, this, std::ref(window)));
connect_signal_notify_modified(list, std::bind(&unit_recruit::list_item_clicked, this));
window.keyboard_capture(filter);
window.add_to_keyboard_chain(&list);
@ -161,19 +161,19 @@ void unit_recruit::pre_show(window& window)
}
}
list_item_clicked(window);
list_item_clicked();
}
void unit_recruit::list_item_clicked(window& window)
void unit_recruit::list_item_clicked()
{
const int selected_row
= find_widget<listbox>(&window, "recruit_list", false).get_selected_row();
= find_widget<listbox>(get_window(), "recruit_list", false).get_selected_row();
if(selected_row == -1) {
return;
}
find_widget<unit_preview_pane>(&window, "recruit_details", false)
find_widget<unit_preview_pane>(get_window(), "recruit_details", false)
.set_displayed_type(*recruit_list_[selected_row]);
}

View file

@ -44,7 +44,7 @@ private:
virtual void pre_show(window& window) override;
virtual void post_show(window& window) override;
void list_item_clicked(window& window);
void list_item_clicked();
void filter_text_changed(text_box_base* textbox, const std::string& text);
void show_help();