* Draw the given cargo entries in the station GUI. * @param entry Root entry for all cargo to be drawn. * @param r Screen rectangle to draw into. * @param pos Current row to be drawn to (counted down from 0 to -maxrows, same as vscroll->GetPosition()). * @param maxrows Maximum row to be drawn. * @param column Current "column" being drawn. * @param cargo Current cargo being drawn (if ca
| 1797 | * @return row (in "pos" counting) after the one we have last drawn to. |
| 1798 | */ |
| 1799 | int DrawEntries(CargoDataEntry &entry, const Rect &r, int pos, int maxrows, int column, CargoType cargo = INVALID_CARGO) |
| 1800 | { |
| 1801 | assert(column < NUM_COLUMNS); |
| 1802 | if (this->sortings[column] == CargoSortType::AsGrouping) { |
| 1803 | if (this->groupings[column] != GR_CARGO) { |
| 1804 | entry.Resort(CargoSortType::StationString, this->sort_orders[column]); |
| 1805 | } |
| 1806 | } else { |
| 1807 | entry.Resort(CargoSortType::Count, this->sort_orders[column]); |
| 1808 | } |
| 1809 | int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2; |
| 1810 | for (CargoDataSet::iterator i = entry.Begin(); i != entry.End(); ++i) { |
| 1811 | CargoDataEntry &cd = **i; |
| 1812 | |
| 1813 | Grouping grouping = this->groupings[column]; |
| 1814 | if (grouping == GR_CARGO) cargo = cd.GetCargo(); |
| 1815 | bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL; |
| 1816 | |
| 1817 | if (pos > -maxrows && pos <= 0) { |
| 1818 | StringID str = STR_EMPTY; |
| 1819 | StationID station = StationID::Invalid(); |
| 1820 | int y = r.top - pos * this->line_height; |
| 1821 | if (this->groupings[column] == GR_CARGO) { |
| 1822 | str = STR_STATION_VIEW_WAITING_CARGO; |
| 1823 | this->DrawCargoIcons(cd.GetCargo(), cd.GetCount(), Rect(r.left + this->expand_shrink_width, y, r.right - this->expand_shrink_width, y + this->line_height - 1)); |
| 1824 | } else { |
| 1825 | if (!auto_distributed) grouping = GR_SOURCE; |
| 1826 | station = cd.GetStation(); |
| 1827 | str = this->GetGroupingString(grouping, station); |
| 1828 | if (grouping == GR_NEXT && str == STR_STATION_VIEW_VIA) str = this->SearchNonStop(cd, station, column); |
| 1829 | |
| 1830 | if (pos == -this->scroll_to_row && Station::IsValidID(station)) { |
| 1831 | ScrollMainWindowToTile(Station::Get(station)->xy); |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | bool rtl = _current_text_dir == TD_RTL; |
| 1836 | Rect text = r.Indent(column * WidgetDimensions::scaled.hsep_indent, rtl).Indent(this->expand_shrink_width, !rtl); |
| 1837 | Rect shrink = r.WithWidth(this->expand_shrink_width, !rtl); |
| 1838 | |
| 1839 | DrawString(text.left, text.right, y + text_y_offset, GetString(str, cargo, cd.GetCount(), station)); |
| 1840 | |
| 1841 | if (column < NUM_COLUMNS - 1) { |
| 1842 | std::string_view sym; |
| 1843 | if (cd.GetNumChildren() > 0) { |
| 1844 | sym = "-"; |
| 1845 | } else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) { |
| 1846 | sym = "+"; |
| 1847 | } else { |
| 1848 | /* Only draw '+' if there is something to be shown. */ |
| 1849 | const GoodsEntry &ge = Station::Get(this->window_number)->goods[cargo]; |
| 1850 | if (ge.HasData()) { |
| 1851 | const StationCargoList &cargo_list = ge.GetData().cargo; |
| 1852 | if (grouping == GR_CARGO && (cargo_list.ReservedCount() > 0 || cd.HasTransfers())) { |
| 1853 | sym = "+"; |
| 1854 | } |
| 1855 | } |
| 1856 | } |
no test coverage detected