MP Create: much more efficient method of game filtering

This commit is contained in:
Charles Dang 2016-08-19 13:37:23 +11:00
parent 90c3c05af4
commit 6b3f9d8cbd
3 changed files with 32 additions and 2 deletions

View file

@ -1281,6 +1281,26 @@ std::vector<create_engine::level_ptr> create_engine::get_levels_by_type(level::T
return levels;
}
std::vector<size_t> create_engine::get_filtered_level_indicies(level::TYPE type) const
{
switch (type.v) {
case level::TYPE::SCENARIO:
return scenarios_filtered_;
case level::TYPE::USER_MAP:
return user_maps_filtered_;
case level::TYPE::USER_SCENARIO:
return user_scenarios_filtered_;
case level::TYPE::RANDOM_MAP:
return random_maps_filtered_;
case level::TYPE::CAMPAIGN:
return campaigns_filtered_;
case level::TYPE::SP_CAMPAIGN:
return sp_campaigns_filtered_;
} // end switch
return std::vector<size_t>();
}
const std::vector<create_engine::extras_metadata_ptr>&
create_engine::get_const_extras_by_type(const MP_EXTRA extra_type) const
{

View file

@ -222,6 +222,8 @@ public:
std::vector<level_ptr> get_levels_by_type_unfiltered(level::TYPE type) const;
std::vector<level_ptr> get_levels_by_type(level::TYPE type) const;
std::vector<size_t> get_filtered_level_indicies(level::TYPE type) const;
std::vector<std::string> levels_menu_item_names() const;
std::vector<std::string> extras_menu_item_names(
const MP_EXTRA extra_type, bool escape_markup = true) const;

View file

@ -290,8 +290,16 @@ void tmp_create_game::filter_changed_callback(twindow& window, const std::string
{
create_engine_.apply_level_filter(find_widget<widget>(&window, id, false).get_value());
// TODO: should this be done with tlistbox::set_row_shown?
update_games_list(window);
tlistbox& game_list = find_widget<tlistbox>(&window, "games_list", false);
std::vector<bool> filtered(game_list.get_item_count());
for(const size_t i : create_engine_.get_filtered_level_indicies(create_engine_.current_level_type())) {
filtered[i] = true;
}
game_list.set_row_shown(filtered);
update_details(window);
}
void tmp_create_game::update_games_list(twindow& window)