forked from mirror/OpenTTD
Fix #11315: Sort industries and cargoes by name* in industry chain window.
*Cargo types are sorted by the normal method so it's not strictly alphabetical.
This commit is contained in:
@@ -1920,6 +1920,11 @@ enum CargoesFieldType {
|
||||
|
||||
static const uint MAX_CARGOES = 16; ///< Maximum number of cargoes carried in a #CFT_CARGO field in #CargoesField.
|
||||
|
||||
static bool CargoIDSorter(const CargoID &a, const CargoID &b)
|
||||
{
|
||||
return _sorted_cargo_types[a] < _sorted_cargo_types[b];
|
||||
}
|
||||
|
||||
/** Data about a single field in the #IndustryCargoesWindow panel. */
|
||||
struct CargoesField {
|
||||
static int vert_inter_industry_space;
|
||||
@@ -2049,6 +2054,7 @@ struct CargoesField {
|
||||
}
|
||||
}
|
||||
this->u.cargo.num_cargoes = (count < 0) ? static_cast<uint8_t>(insert - std::begin(this->u.cargo.vertical_cargoes)) : count;
|
||||
std::sort(std::begin(this->u.cargo.vertical_cargoes), insert, &CargoIDSorter);
|
||||
std::fill(insert, std::end(this->u.cargo.vertical_cargoes), CT_INVALID);
|
||||
this->u.cargo.top_end = top_end;
|
||||
this->u.cargo.bottom_end = bottom_end;
|
||||
@@ -2813,7 +2819,7 @@ struct IndustryCargoesWindow : public Window {
|
||||
/* Add suppliers and customers of the 'it' industry. */
|
||||
int supp_count = 0;
|
||||
int cust_count = 0;
|
||||
for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
|
||||
for (IndustryType it : _sorted_industry_types) {
|
||||
const IndustrySpec *indsp = GetIndustrySpec(it);
|
||||
if (!indsp->enabled) continue;
|
||||
|
||||
@@ -2881,7 +2887,7 @@ struct IndustryCargoesWindow : public Window {
|
||||
/* Add suppliers and customers of the cargo. */
|
||||
int supp_count = 0;
|
||||
int cust_count = 0;
|
||||
for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
|
||||
for (IndustryType it : _sorted_industry_types) {
|
||||
const IndustrySpec *indsp = GetIndustrySpec(it);
|
||||
if (!indsp->enabled) continue;
|
||||
|
||||
|
Reference in New Issue
Block a user