Add column sorting for level breaking tie using XP
only used in unit list for the moment
This commit is contained in:
parent
5b80e34dd9
commit
f4a077e252
3 changed files with 23 additions and 3 deletions
|
@ -210,7 +210,7 @@ void menu_handler::unit_list()
|
|||
|
||||
gui::menu::basic_sorter sorter;
|
||||
sorter.set_alpha_sort(0).set_alpha_sort(1).set_numeric_sort(2);
|
||||
sorter.set_alpha_sort(3).set_numeric_sort(4).set_numeric_sort(5);
|
||||
sorter.set_alpha_sort(3).set_numeric_sort(4).set_level_sort(5, 6);
|
||||
sorter.set_xp_sort(6).set_alpha_sort(7);
|
||||
|
||||
std::vector<std::string> items;
|
||||
|
|
|
@ -53,6 +53,13 @@ menu::basic_sorter& menu::basic_sorter::set_xp_sort(int column)
|
|||
return *this;
|
||||
}
|
||||
|
||||
menu::basic_sorter& menu::basic_sorter::set_level_sort(int level_column, int xp_column)
|
||||
{
|
||||
level_sort_.insert(level_column);
|
||||
xp_col_ = xp_column;
|
||||
return *this;
|
||||
}
|
||||
|
||||
menu::basic_sorter& menu::basic_sorter::set_id_sort(int column)
|
||||
{
|
||||
id_sort_.insert(column);
|
||||
|
@ -82,7 +89,8 @@ bool menu::basic_sorter::column_sortable(int column) const
|
|||
}
|
||||
|
||||
return alpha_sort_.count(column) == 1 || numeric_sort_.count(column) == 1 ||
|
||||
pos_sort_.count(column) == 1 || id_sort_.count(column) == 1 || xp_sort_.count(column) == 1;
|
||||
pos_sort_.count(column) == 1 || id_sort_.count(column) == 1 ||
|
||||
xp_sort_.count(column) == 1 || level_sort_.count(column) == 1;
|
||||
}
|
||||
|
||||
static std::pair<int, int> parse_fraction(const std::string& s)
|
||||
|
@ -145,6 +153,16 @@ bool menu::basic_sorter::less(int column, const item& row1, const item& row2) co
|
|||
return val_1 > val_2;
|
||||
} else if(xp_sort_.count(column) == 1) {
|
||||
return xp_to_advance(item1) < xp_to_advance(item2);
|
||||
} else if(level_sort_.count(column) == 1) {
|
||||
int level_1 = lexical_cast_default<int>(item1, 0);
|
||||
int level_2 = lexical_cast_default<int>(item2, 0);
|
||||
if (level_1 == level_2) {
|
||||
//break tie using xp
|
||||
const std::string& xp_item1 = font::del_tags(row1.fields[xp_col_]);
|
||||
const std::string& xp_item2 = font::del_tags(row2.fields[xp_col_]);
|
||||
return xp_to_advance(xp_item1) < xp_to_advance(xp_item2);
|
||||
}
|
||||
return level_1 > level_2;
|
||||
}
|
||||
|
||||
const std::map<int,std::vector<int> >::const_iterator itor = pos_sort_.find(column);
|
||||
|
|
|
@ -141,6 +141,7 @@ public:
|
|||
basic_sorter& set_alpha_sort(int column);
|
||||
basic_sorter& set_numeric_sort(int column);
|
||||
basic_sorter& set_xp_sort(int column);
|
||||
basic_sorter& set_level_sort(int level_column, int xp_column);
|
||||
basic_sorter& set_id_sort(int column);
|
||||
basic_sorter& set_redirect_sort(int column, int to);
|
||||
basic_sorter& set_position_sort(int column, const std::vector<int>& pos);
|
||||
|
@ -149,9 +150,10 @@ public:
|
|||
virtual bool less(int column, const item& row1, const item& row2) const;
|
||||
|
||||
private:
|
||||
std::set<int> alpha_sort_, numeric_sort_, id_sort_, xp_sort_;
|
||||
std::set<int> alpha_sort_, numeric_sort_, id_sort_, xp_sort_, level_sort_;
|
||||
std::map<int,int> redirect_sort_;
|
||||
std::map<int,std::vector<int> > pos_sort_;
|
||||
int xp_col_; //used by level sort
|
||||
};
|
||||
|
||||
menu(CVideo& video, const std::vector<std::string>& items,
|
||||
|
|
Loading…
Add table
Reference in a new issue