# HG changeset patch # User sbr # Date 1374914161 -7200 # Sat Jul 27 10:36:01 2013 +0200 # Node ID ff49afa94308bdbc302b0aabfd0b94a2c63e335f # Parent 0409deeb365bfd2c50c6f0d60aeb20f7f9c18f9c -Change: Use 'default sort orders' to sort industry directory (name and type ascending, production and transported descending). diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1070,6 +1070,7 @@ protected: /* Constants for sorting stations */ static const StringID sorter_names[]; static GUIIndustryList::SortFunction * const sorter_funcs[]; + static GUIIndustryList::DefaultSortOrder default_sort_orders[]; GUIIndustryList industries; Scrollbar *vscroll; @@ -1222,6 +1223,8 @@ public: this->industries.SetListing(this->last_sorting); this->industries.SetSortFuncs(IndustryDirectoryWindow::sorter_funcs); + this->industries.SetDefaultSortOrders(IndustryDirectoryWindow::default_sort_orders); + this->industries.UseDefaultSortOrder(); this->industries.ForceRebuild(); this->BuildSortIndustriesList(); @@ -1331,6 +1334,11 @@ public: { if (this->industries.SortType() != index) { this->industries.SetSortType(index); + + /* Use the default sort order for this sort type. */ + bool changed_sort_order = this->industries.UseDefaultSortOrder(); + if (changed_sort_order) this->SetWidgetDirty(WID_ID_DROPDOWN_ORDER); + this->BuildSortIndustriesList(); } } @@ -1388,6 +1396,13 @@ const StringID IndustryDirectoryWindow:: INVALID_STRING_ID }; +/** Sort orders to use by default. */ +GUIIndustryList::DefaultSortOrder IndustryDirectoryWindow::default_sort_orders[] = { + GUIIndustryList::DSO_ASCENDING, // Sort by name + GUIIndustryList::DSO_ASCENDING, // Sort by type + GUIIndustryList::DSO_DESCENDING, // Sort by production + GUIIndustryList::DSO_DESCENDING, // Sort by transported +}; /** Window definition of the industry directory gui */ static WindowDesc _industry_directory_desc(