bool ttreasure_list::compare_row(tgrid& row1, tgrid& row2) { unsigned int i1 = dynamic_cast<ttoggle_panel*>(row1.find("_toggle", true))->get_data(); unsigned int i2 = dynamic_cast<ttoggle_panel*>(row2.find("_toggle", true))->get_data(); hero* h1; hero* h2; h1 = &heros_[i1]; h2 = &heros_[i2]; bool result = true; std::vector<tbutton*>& widgets = sorting_widgets_[current_page_]; if (current_page_ == OWNERSHIP_PAGE) { if (sorting_widget_ == widgets[0]) { // name result = utils::utf8str_compare(h1->name(), h2->name()); } else if (sorting_widget_ == widgets[1]) { // side std::string str1, str2; if (h1->side_ != HEROS_INVALID_SIDE) { str1 = teams_[h1->side_].name(); } if (h2->side_ != HEROS_INVALID_SIDE) { str2 = teams_[h2->side_].name(); } result = utils::utf8str_compare(str1, str2); } else if (sorting_widget_ == widgets[2]) { // city std::string str1, str2; artifical* city = units_.city_from_cityno(h1->city_); if (city) { str1 = city->name(); } city = units_.city_from_cityno(h2->city_); if (city) { str2 = city->name(); } result = utils::utf8str_compare(str1, str2); } else if (sorting_widget_ == widgets[3]) { // loyalty int l1 = 0; int l2 = 0; if (h1->side_ != HEROS_INVALID_SIDE) { l1 = h1->loyalty(*(teams_[h1->side_].leader())); } if (h2->side_ != HEROS_INVALID_SIDE) { l2 = h2->loyalty(*(teams_[h2->side_].leader())); } if (l1 > l2) { result = false; } } else if (sorting_widget_ == widgets[4]) { // catalog if (h1->base_catalog_ > h2->base_catalog_) { result = false; } } else if (sorting_widget_ == widgets[5]) { // meritorious if (h1->meritorious_ > h2->meritorious_) { result = false; } } } return ascend_? result: !result; }
bool ttroop_list::compare_row(tgrid& row1, tgrid& row2) { unsigned int i1 = dynamic_cast<ttoggle_panel*>(row1.find("_toggle", true))->get_data(); unsigned int i2 = dynamic_cast<ttoggle_panel*>(row2.find("_toggle", true))->get_data(); const unit& u1 = *candidate_troops_[i1]; const unit& u2 = *candidate_troops_[i2]; bool result = true; std::vector<tbutton*>& widgets = sorting_widgets_[current_page_]; if (current_page_ == OWNERSHIP_PAGE) { if (sorting_widget_ == widgets[0]) { // name result = utils::utf8str_compare(u1.name(), u2.name()); } else if (sorting_widget_ == widgets[1]) { // type result = utils::utf8str_compare(u1.type_name(), u2.type_name()); } else if (sorting_widget_ == widgets[2]) { // side result = utils::utf8str_compare(teams_[u1.side() - 1].name(), teams_[u2.side() - 1].name()); } else if (sorting_widget_ == widgets[3]) { // city std::string str1, str2; artifical* city = units_.city_from_cityno(u1.cityno()); if (city) { str1 = city->name(); } city = units_.city_from_cityno(u2.cityno()); if (city) { str2 = city->name(); } result = utils::utf8str_compare(str1, str2); } } else if (current_page_ == STATUS_PAGE) { if (sorting_widget_ == widgets[0]) { // name result = utils::utf8str_compare(u1.name(), u2.name()); } else if (sorting_widget_ == widgets[1]) { // type result = utils::utf8str_compare(u1.type_name(), u2.type_name()); } else if (sorting_widget_ == widgets[2]) { // level if (u1.level() > u2.level()) { result = false; } } else if (sorting_widget_ == widgets[3]) { // hp if (u1.max_hitpoints() > u2.max_hitpoints() || (u1.max_hitpoints() == u2.max_hitpoints() && u1.hitpoints() > u2.hitpoints())) { result = false; } } else if (sorting_widget_ == widgets[4]) { // xp if (u1.experience() > u2.experience() || (u1.experience() == u2.experience() && u1.max_experience() > u2.max_experience())) { result = false; } } else if (sorting_widget_ == widgets[5]) { // traits result = utils::utf8str_compare(utils::join(u1.trait_names(), ", "), utils::join(u2.trait_names(), ", ")); } else if (sorting_widget_ == widgets[6]) { // movement if (u1.movement_left() > u2.movement_left() || (u1.movement_left() == u2.movement_left() && u1.total_movement() > u2.total_movement())) { result = false; } } } else if (current_page_ == MERIT_PAGE) { if (sorting_widget_ == widgets[0]) { // name result = utils::utf8str_compare(u1.name(), u2.name()); } else if (sorting_widget_ == widgets[1]) { // type result = utils::utf8str_compare(u1.type_name(), u2.type_name()); } else if (sorting_widget_ == widgets[2]) { // cause_damage if (u1.cause_damage_ > u2.cause_damage_) { result = false; } } else if (sorting_widget_ == widgets[3]) { // been_damage if (u1.been_damage_ > u2.been_damage_) { result = false; } } else if (sorting_widget_ == widgets[4]) { // defeat_units if (u1.defeat_units_ > u2.defeat_units_) { result = false; } } else if (sorting_widget_ == widgets[5]) { // field_turns if (u1.field_turns_ > u2.field_turns_) { result = false; } } } return ascend_? result: !result; }