Unit List/Unit Recall: simplified level sorting functionality
This commit is contained in:
parent
c41da8255d
commit
94db6ba8c5
3 changed files with 8 additions and 20 deletions
|
@ -14,7 +14,6 @@
|
|||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/dialogs/unit_list.hpp"
|
||||
#include "gui/dialogs/unit_recall.hpp" /* for default_compare */
|
||||
|
||||
#include "gui/auxiliary/find_widget.hpp"
|
||||
#include "gui/core/log.hpp"
|
||||
|
@ -154,10 +153,10 @@ void unit_list::pre_show(window& window)
|
|||
list.register_translatable_sorting_option(1, [this](const int i) { return unit_list_[i]->name().str(); });
|
||||
list.register_sorting_option(2, [this](const int i) { return unit_list_[i]->movement_left(); });
|
||||
list.register_sorting_option(3, [this](const int i) { return unit_list_[i]->hitpoints(); });
|
||||
list.set_column_order(4, {{
|
||||
[this](int lhs, int rhs) { return unit_recall::default_compare(unit_list_[rhs], unit_list_[lhs]); },
|
||||
[this](int lhs, int rhs) { return unit_recall::default_compare(unit_list_[lhs], unit_list_[rhs]); }
|
||||
}});
|
||||
list.register_sorting_option(4, [this](const int i) {
|
||||
const unit& u = *unit_list_[i];
|
||||
return std::make_tuple(-u.level(), u.experience_to_advance());
|
||||
});
|
||||
list.register_sorting_option(5, [this](const int i) { return unit_list_[i]->experience(); });
|
||||
list.register_translatable_sorting_option(6, [this](const int i) {
|
||||
return !unit_list_[i]->trait_names().empty() ? unit_list_[i]->trait_names().front().str() : ""; });
|
||||
|
|
|
@ -135,14 +135,6 @@ static std::string get_title_suffix(int side_num)
|
|||
return msg.str();
|
||||
}
|
||||
|
||||
bool unit_recall::default_compare(const unit_const_ptr first, const unit_const_ptr second)
|
||||
{
|
||||
if (first->level() > second->level()) return true;
|
||||
if (first->level() < second->level()) return false;
|
||||
if (first->experience_to_advance() < second->experience_to_advance()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void unit_recall::pre_show(window& window)
|
||||
{
|
||||
label& title = find_widget<label>(&window, "title", true);
|
||||
|
@ -229,10 +221,10 @@ void unit_recall::pre_show(window& window)
|
|||
|
||||
list.register_sorting_option(0, [this](const int i) { return recall_list_[i]->type_name().str(); });
|
||||
list.register_sorting_option(1, [this](const int i) { return recall_list_[i]->name().str(); });
|
||||
list.set_column_order(2, {{
|
||||
[this](int lhs, int rhs) { return default_compare(recall_list_[rhs], recall_list_[lhs]); },
|
||||
[this](int lhs, int rhs) { return default_compare(recall_list_[lhs], recall_list_[rhs]); }
|
||||
}});
|
||||
list.register_sorting_option(2, [this](const int i) {
|
||||
const unit& u = *recall_list_[i];
|
||||
return std::make_tuple(-u.level(), u.experience_to_advance());
|
||||
});
|
||||
list.register_sorting_option(3, [this](const int i) { return recall_list_[i]->experience(); });
|
||||
list.register_sorting_option(4, [this](const int i) {
|
||||
return !recall_list_[i]->trait_names().empty() ? recall_list_[i]->trait_names().front().str() : "";
|
||||
|
|
|
@ -44,9 +44,6 @@ public:
|
|||
return selected_index_;
|
||||
}
|
||||
|
||||
/** Function to sort recall_list_ by default. */
|
||||
static bool default_compare(const unit_const_ptr first, const unit_const_ptr second);
|
||||
|
||||
private:
|
||||
recalls_ptr_vector& recall_list_;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue