Lambda-based replacement for e75eaca5a0
Should also fix underlying cause of 7e6a1892bb
This commit is contained in:
parent
44d171ab58
commit
df84646026
2 changed files with 12 additions and 19 deletions
|
@ -111,18 +111,8 @@ static std::string format_cost_string(int unit_recall_cost, const int team_recal
|
|||
return str.str();
|
||||
}
|
||||
|
||||
static std::string tstr_key(unit_const_ptr u, const t_string& (unit::* fcn)() const)
|
||||
{
|
||||
return (u.get()->*fcn)().str();
|
||||
}
|
||||
|
||||
static std::string trait_key(unit_const_ptr u)
|
||||
{
|
||||
return !u->trait_names().empty() ? u->trait_names().front().str() : "";
|
||||
}
|
||||
|
||||
template<typename Ret>
|
||||
void tunit_recall::init_sorting_option(generator_sort_array& order_funcs, std::function<Ret(unit_const_ptr)> filter_on)
|
||||
template<typename Fnc>
|
||||
void tunit_recall::init_sorting_option(generator_sort_array& order_funcs, Fnc filter_on)
|
||||
{
|
||||
order_funcs[0] = [this, filter_on](unsigned i1, unsigned i2) {
|
||||
return filter_on((*recall_list_)[i1]) < filter_on((*recall_list_)[i2]);
|
||||
|
@ -252,19 +242,22 @@ void tunit_recall::pre_show(twindow& window)
|
|||
|
||||
generator_sort_array order_funcs;
|
||||
|
||||
init_sorting_option<std::string>(order_funcs, std::bind(&tstr_key, _1, &unit::type_name));
|
||||
init_sorting_option(order_funcs, [](unit_const_ptr u) { return u.get()->type_name().str(); });
|
||||
list.set_column_order(0, order_funcs);
|
||||
|
||||
init_sorting_option<std::string>(order_funcs, std::bind(&tstr_key, _1, &unit::name));
|
||||
init_sorting_option(order_funcs, [](unit_const_ptr u) { return u.get()->name().str(); });
|
||||
list.set_column_order(1, order_funcs);
|
||||
|
||||
init_sorting_option<int>(order_funcs, std::bind(&unit::level, _1));
|
||||
init_sorting_option(order_funcs, [](unit_const_ptr u) { return u.get()->level(); });
|
||||
list.set_column_order(2, order_funcs);
|
||||
|
||||
init_sorting_option<int>(order_funcs, std::bind(&unit::experience, _1));
|
||||
init_sorting_option(order_funcs, [](unit_const_ptr u) { return u.get()->experience(); });
|
||||
list.set_column_order(3, order_funcs);
|
||||
|
||||
init_sorting_option<std::string>(order_funcs, std::bind(&trait_key, _1));
|
||||
init_sorting_option(order_funcs, [](unit_const_ptr u) {
|
||||
return !u.get()->trait_names().empty() ? u.get()->trait_names().front().str() : "";
|
||||
});
|
||||
|
||||
list.set_column_order(4, order_funcs);
|
||||
|
||||
list_item_clicked(window);
|
||||
|
|
|
@ -54,8 +54,8 @@ private:
|
|||
std::vector<std::string> filter_options_;
|
||||
std::vector<std::string> last_words_;
|
||||
|
||||
template<typename Ret>
|
||||
void init_sorting_option(generator_sort_array& order_funcs, std::function<Ret(unit_const_ptr)> filter_on);
|
||||
template<typename T>
|
||||
void init_sorting_option(generator_sort_array& order_funcs, T filter_on);
|
||||
|
||||
/** Callbacks */
|
||||
void list_item_clicked(twindow& window);
|
||||
|
|
Loading…
Add table
Reference in a new issue