diff --git gui/line_item.cc gui/line_item.cc index 42afbab10..62149b3c4 100644 --- gui/line_item.cc +++ gui/line_item.cc @@ -41,38 +41,14 @@ void line_scrollitem_t::set_text(char const* const t) } -// static helper function for sorting lineintems - -line_scrollitem_t::sort_modes_t line_scrollitem_t::sort_mode = line_scrollitem_t::SORT_BY_NAME; - - bool line_scrollitem_t::compare(const gui_component_t *aa, const gui_component_t *bb) { - const line_scrollitem_t *a = dynamic_cast(aa); - const line_scrollitem_t *b = dynamic_cast(bb); - // good luck with mixed lists - assert(a != NULL && b != NULL); (void)(a==b); + const line_scrollitem_t *a = dynamic_cast(aa); + const line_scrollitem_t *b = dynamic_cast(bb); - if( sort_mode != SORT_BY_NAME ) { - switch( sort_mode ) { - case SORT_BY_NAME: // default - break; - case SORT_BY_ID: - return (a->get_line().get_id(),b->get_line().get_id())<0; - case SORT_BY_PROFIT: - return (a->get_line()->get_finance_history(1,LINE_PROFIT) - b->get_line()->get_finance_history(1,LINE_PROFIT))<0; - case SORT_BY_TRANSPORTED: - return (a->get_line()->get_finance_history(1,LINE_TRANSPORTED_GOODS) - b->get_line()->get_finance_history(1,LINE_TRANSPORTED_GOODS))<0; - case SORT_BY_CONVOIS: - return (a->get_line()->get_finance_history(1,LINE_CONVOIS) - b->get_line()->get_finance_history(1,LINE_CONVOIS))<0; - case SORT_BY_DISTANCE: - // normalizing to the number of convoys to get the fastest ones ... - return (a->get_line()->get_finance_history(1,LINE_DISTANCE)/max(1,a->get_line()->get_finance_history(1,LINE_CONVOIS)) - - b->get_line()->get_finance_history(1,LINE_DISTANCE)/max(1,b->get_line()->get_finance_history(1,LINE_CONVOIS)) )<0; - default: break; - } - // default sorting ... - } + // good luck with mixed lists + assert(a != NULL); + assert(b != NULL); // first: try to sort by number const char *atxt = a->get_text(); diff --git gui/line_item.h gui/line_item.h index 9b8ec257e..e51a6929d 100644 --- gui/line_item.h +++ gui/line_item.h @@ -17,10 +17,8 @@ class line_scrollitem_t : public gui_scrolled_list_t::const_text_scrollitem_t { private: linehandle_t line; + public: - // helper to sort - enum sort_modes_t { SORT_BY_NAME=0, SORT_BY_ID, SORT_BY_PROFIT, SORT_BY_TRANSPORTED, SORT_BY_CONVOIS, SORT_BY_DISTANCE, MAX_SORT_MODES }; - static sort_modes_t sort_mode; // normal items line_scrollitem_t( linehandle_t l ) : gui_scrolled_list_t::const_text_scrollitem_t( NULL, color_idx_to_rgb(COL_ORANGE) ) { line = l; } PIXVAL get_color() const OVERRIDE; diff --git gui/schedule_gui.cc gui/schedule_gui.cc index 42bdd977c..0c379a926 100644 --- gui/schedule_gui.cc +++ gui/schedule_gui.cc @@ -677,7 +677,6 @@ void schedule_gui_t::init_line_selector() } line_selector.set_selection( selection ); - line_scrollitem_t::sort_mode = line_scrollitem_t::SORT_BY_NAME; line_selector.sort( offset ); old_line_count = player->simlinemgmt.get_line_count(); last_schedule_count = schedule->get_count(); diff --git gui/schedule_list.cc gui/schedule_list.cc index 2d9de3a6b..2bede7e8a 100644 --- gui/schedule_list.cc +++ gui/schedule_list.cc @@ -97,7 +97,6 @@ static uint8 statistic_type[MAX_LINE_COST] = { MONEY }; -static int current_sort_mode = 0; #define SCL_HEIGHT (15*LINESPACE) #define RIGHT_COLUMN_OFFSET (D_MARGIN_LEFT+3*D_BUTTON_WIDTH+2*D_H_SPACE+2*D_H_SPACE) @@ -598,7 +597,6 @@ void schedule_list_gui_t::build_line_list(int filter) } scl.set_selection( sel ); - line_scrollitem_t::sort_mode = (line_scrollitem_t::sort_modes_t)current_sort_mode; scl.sort( 0 ); scl.set_size(scl.get_size());