MP Create Game: delegate tab content updates to game selection

Previously, on_tab_select was called every time update_details was called (including on game selection), as well as
when a tab was manually selected. I had enabled the updating of tab 3 (game settings) on every call to fix an issue
where game settings were incorrect if that tab had not been selected. However, it was recently discovered that the
same issue affected tab 2 (custom options). Since the only time the contents of the tabs change is when called from
update_details anyway (manually selecting a tab did not), it made sense to move the updating code out of on_tab_select.

This is also a performance optimization, since it prevents tabs' contents from being updated every single time a new
one was selected, when in reality there would be no change unless a game was changed. This will also prevent any future
issues of the same ilk and ensures the state of all widget is always in sync with the settings of the selected game.
This commit is contained in:
Charles Dang 2016-10-22 18:50:16 +11:00
parent 1cef83b08a
commit 80115b11fa
2 changed files with 23 additions and 27 deletions

View file

@ -316,6 +316,8 @@ void tmp_create_game::pre_show(twindow& window)
dialog_callback<tmp_create_game, &tmp_create_game::on_tab_select>);
#endif
on_tab_select(window);
//
// Main games list
//
@ -450,26 +452,6 @@ void tmp_create_game::on_tab_select(twindow& window)
{
const int i = find_widget<tlistbox>(&window, "tab_bar", false).get_selected_row();
find_widget<tstacked_widget>(&window, "pager", false).select_layer(i);
if(i == tab::TAB_GENERAL) {
const bool can_select_era = create_engine_.current_level().allow_era_choice();
tmenu_button& era_combo = find_widget<tmenu_button>(&window, "eras", false);
if(!can_select_era) {
era_combo.set_label(_("No eras available for this game."));
} else {
era_combo.set_selected(era_combo.get_value());
}
era_combo.set_active(can_select_era);
}
if(i == tab::TAB_OPTIONS) {
update_options_list();
}
// Map Settings can and should be updated every time
update_map_settings(window);
}
void tmp_create_game::on_mod_select(twindow& window)
@ -559,11 +541,6 @@ void tmp_create_game::display_games_of_type(twindow& window, ng::level::TYPE typ
on_game_select(window);
}
void tmp_create_game::update_options_list()
{
options_manager_->update_options_list();
}
void tmp_create_game::show_generator_settings(twindow& window)
{
create_engine_.generator_user_config();
@ -658,7 +635,27 @@ void tmp_create_game::update_details(twindow& window)
}
}
on_tab_select(window);
// General settings
tstacked_widget& stack = find_widget<tstacked_widget>(&window, "pager", false);
const bool can_select_era = create_engine_.current_level().allow_era_choice();
tmenu_button& era_combo = find_widget<tmenu_button>(stack.get_layer_grid(TAB_GENERAL), "eras", false);
if(!can_select_era) {
era_combo.set_label(_("No eras available for this game."));
} else {
era_combo.set_selected(era_combo.get_value());
}
era_combo.set_active(can_select_era);
//
// Custom options
//
options_manager_->update_options_list();
// Game settings
update_map_settings(window);
}
void tmp_create_game::update_map_settings(twindow& window)

View file

@ -118,7 +118,6 @@ private:
void show_description(twindow& window, const std::string& new_description);
void update_options_list();
void update_details(twindow& window);
void update_map_settings(twindow& window);