Index: src/lang/english.txt =================================================================== --- src/lang/english.txt (revision 24945) +++ src/lang/english.txt (working copy) @@ -290,6 +290,12 @@ STR_SORT_BY_CARGO_CAPACITY :Cargo Capacity STR_SORT_BY_RANGE :Range +STR_FILTER_TRANSPORTED_BOTH :Show all (transported or not) +STR_FILTER_TRANSPORTED_ONLY_NOT :Show only non-transported +STR_FILTER_TRANSPORTED_ONLY :Show only transported + +STR_FILTER_INDUSTRY_TYPE_ALL :Show all + # Tooltips for the main toolbar STR_TOOLBAR_TOOLTIP_PAUSE_GAME :{BLACK}Pause game STR_TOOLBAR_TOOLTIP_FORWARD :{BLACK}Fast forward the game Index: src/industry_gui.cpp =================================================================== --- src/industry_gui.cpp (revision 24945) +++ src/industry_gui.cpp (working copy) @@ -144,6 +144,18 @@ QSortT(_sorted_industry_types, NUM_INDUSTRYTYPES, &IndustryTypeNameSorter); } +DropDownList *GetIndustryTypeDropDownList(bool include_show_all=0){ + DropDownList *lst = new DropDownList; + if (include_show_all) lst->push_back(new DropDownListStringItem(STR_FILTER_INDUSTRY_TYPE_ALL, -1, false)); + for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) { + IndustryType ind = _sorted_industry_types[i]; + const IndustrySpec *indsp = GetIndustrySpec(ind); + if (!indsp->enabled) continue; + lst->push_back(new DropDownListStringItem(indsp->name, ind, false)); + } + return lst; +} + /** * Command callback. In case of failure to build an industry, show an error message. * @param result Result of the command. @@ -1037,6 +1049,9 @@ NWidget(NWID_HORIZONTAL), NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_ID_DROPDOWN_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_DROPDOWN_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), + NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_DROPDOWN_FILTER_TRANSPORTED), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA), + NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_DROPDOWN_FILTER_INDUSTRY_TYPE), + SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP), NWidget(WWT_PANEL, COLOUR_BROWN), SetResize(1, 0), EndContainer(), EndContainer(), NWidget(WWT_PANEL, COLOUR_BROWN, WID_ID_INDUSTRY_LIST), SetDataTip(0x0, STR_INDUSTRY_DIRECTORY_LIST_CAPTION), SetResize(1, 1), SetScrollbar(WID_ID_SCROLLBAR), EndContainer(), @@ -1062,6 +1077,10 @@ /* Constants for sorting stations */ static const StringID sorter_names[]; + static const StringID filter_names[]; + byte selected_filter_transported_index; + int selected_filter_industry_type_index; + Dimension ind_textsize; ///< Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY. static GUIIndustryList::SortFunction * const sorter_funcs[]; GUIIndustryList industries; @@ -1075,9 +1094,30 @@ const Industry *i; FOR_ALL_INDUSTRIES(i) { - *this->industries.Append() = i; - } + if (this->selected_filter_industry_type_index == -1 || i->type == this->selected_filter_industry_type_index) { + bool transported = 0; + for (byte j = 0; j < lengthof(i->produced_cargo); j++) { + if (i->produced_cargo[j] == CT_INVALID) continue; + if (i->last_month_pct_transported[j]) { + transported = 1; + break; + } + } /// for cargoes + switch (this->selected_filter_transported_index) { + case 1: /// ONLY NOT TRANSPORTED + if (!transported) *this->industries.Append() = i; + break; + case 2: /// ONLY TRANSPORTED + if (transported) *this->industries.Append() = i; + break; + default: /// BOTH + *this->industries.Append() = i; + break; + } /// switch + } /// If correct type + } /// FOR_ALL_INDUSTRIES + this->industries.Compact(); this->industries.RebuildDone(); this->vscroll->SetCount(this->industries.Length()); // Update scrollbar as well. @@ -1212,7 +1252,7 @@ { this->CreateNestedTree(desc); this->vscroll = this->GetScrollbar(WID_ID_SCROLLBAR); - + this->SetFilterIndustryTypeIndex(-1); this->industries.SetListing(this->last_sorting); this->industries.SetSortFuncs(IndustryDirectoryWindow::sorter_funcs); this->industries.ForceRebuild(); @@ -1226,9 +1266,18 @@ this->last_sorting = this->industries.GetListing(); } + virtual void SetFilterTransportedIndex(byte index) { + this->selected_filter_transported_index = index; + } + + virtual void SetFilterIndustryTypeIndex(int index) { + this->selected_filter_industry_type_index = index; + } + virtual void SetStringParameters(int widget) const { if (widget == WID_ID_DROPDOWN_CRITERIA) SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.SortType()]); + if (widget == WID_ID_DROPDOWN_FILTER_TRANSPORTED) SetDParam(0, IndustryDirectoryWindow::filter_names[this->selected_filter_transported_index]); } virtual void DrawWidget(const Rect &r, int widget) const @@ -1253,6 +1302,7 @@ } break; } + } } @@ -1278,6 +1328,22 @@ break; } + case WID_ID_DROPDOWN_FILTER_TRANSPORTED: { + Dimension d = {0, 0}; + for (uint i = 0; IndustryDirectoryWindow::filter_names[i] != INVALID_STRING_ID; i++) { + d = maxdim(d, GetStringBoundingBox(IndustryDirectoryWindow::filter_names[i])); + } + d.width += padding.width; + d.height += padding.height; + *size = maxdim(*size, d); + break; + } + + case WID_ID_DROPDOWN_FILTER_INDUSTRY_TYPE: { + size->width = max(size->width, this->ind_textsize.width + padding.width); + break; + } + case WID_ID_INDUSTRY_LIST: { Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE); for (uint i = 0; i < this->industries.Length(); i++) { @@ -1306,6 +1372,20 @@ ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), WID_ID_DROPDOWN_CRITERIA, 0, 0); break; + case WID_ID_DROPDOWN_FILTER_TRANSPORTED: + ShowDropDownMenu(this, IndustryDirectoryWindow::filter_names, this->selected_filter_transported_index, WID_ID_DROPDOWN_FILTER_TRANSPORTED, 0, 0); + break; + + case WID_ID_DROPDOWN_FILTER_INDUSTRY_TYPE: { + DropDownList *lst = GetIndustryTypeDropDownList(1); + if (lst->size() == 0) { + delete lst; + break; + } + ShowDropDownList(this, lst, this->selected_filter_industry_type_index, WID_ID_DROPDOWN_FILTER_INDUSTRY_TYPE, 0, true); + break; + } + case WID_ID_INDUSTRY_LIST: { uint p = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_ID_INDUSTRY_LIST, WD_FRAMERECT_TOP); if (p < this->industries.Length()) { @@ -1322,10 +1402,32 @@ virtual void OnDropdownSelect(int widget, int index) { + switch (widget) { + case WID_ID_DROPDOWN_CRITERIA: if (this->industries.SortType() != index) { this->industries.SetSortType(index); this->BuildSortIndustriesList(); } + break; + + case WID_ID_DROPDOWN_FILTER_TRANSPORTED: + if (this->selected_filter_transported_index != index) { + this->SetFilterTransportedIndex(index); + this->industries.ForceRebuild(); + this->BuildSortIndustriesList(); + // Needs to refresh the widget somehow + } + break; + + case WID_ID_DROPDOWN_FILTER_INDUSTRY_TYPE: + if (this->selected_filter_industry_type_index != index) { + this->SetFilterIndustryTypeIndex(index); + this->industries.ForceRebuild(); + this->BuildSortIndustriesList(); + // Needs to refresh the widget somehow + } + break; + } } virtual void OnResize() @@ -1381,7 +1483,15 @@ INVALID_STRING_ID }; +/* Names of the filter functions */ +const StringID IndustryDirectoryWindow::filter_names[] = { + STR_FILTER_TRANSPORTED_BOTH, + STR_FILTER_TRANSPORTED_ONLY_NOT, + STR_FILTER_TRANSPORTED_ONLY, + INVALID_STRING_ID +}; + /** Window definition of the industry directory gui */ static const WindowDesc _industry_directory_desc( WDP_AUTO, 428, 190, @@ -2581,13 +2691,7 @@ } case WID_IC_IND_DROPDOWN: { - DropDownList *lst = new DropDownList; - for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) { - IndustryType ind = _sorted_industry_types[i]; - const IndustrySpec *indsp = GetIndustrySpec(ind); - if (!indsp->enabled) continue; - lst->push_back(new DropDownListStringItem(indsp->name, ind, false)); - } + DropDownList *lst = GetIndustryTypeDropDownList(); if (lst->size() == 0) { delete lst; break; Index: src/widgets/industry_widget.h =================================================================== --- src/widgets/industry_widget.h (revision 24945) +++ src/widgets/industry_widget.h (working copy) @@ -35,6 +35,8 @@ WID_ID_DROPDOWN_ORDER, ///< Dropdown for the order of the sort. WID_ID_DROPDOWN_CRITERIA, ///< Dropdown for the criteria of the sort. WID_ID_INDUSTRY_LIST, ///< Industry list. + WID_ID_DROPDOWN_FILTER_TRANSPORTED, + WID_ID_DROPDOWN_FILTER_INDUSTRY_TYPE, WID_ID_SCROLLBAR, ///< Scrollbar of the list. };