From fa657c83604c11a27a62be7515b5395ab498dd86 Mon Sep 17 00:00:00 2001 From: glx Date: Sun, 3 Nov 2019 14:09:13 +0100 Subject: Fix #7631: 16 out cargo support for industry directory --- src/industry_gui.cpp | 40 ++++++++++++++++++++++++++++------------ src/lang/english.txt | 7 +++++-- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index b695feaf4..536f6da58 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1315,25 +1315,41 @@ protected: static CargoSuffix cargo_suffix[lengthof(i->produced_cargo)]; GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_DIR, i, i->type, indsp, i->produced_cargo, cargo_suffix); - /* Industry productions */ + /* Get industry productions (CargoID, production, suffix, transported) */ + typedef std::tuple CargoInfo; + std::vector cargos; + for (byte j = 0; j < lengthof(i->produced_cargo); j++) { if (i->produced_cargo[j] == CT_INVALID) continue; - SetDParam(p++, i->produced_cargo[j]); - SetDParam(p++, i->last_month_production[j]); - SetDParamStr(p++, cargo_suffix[j].text); + cargos.emplace_back(i->produced_cargo[j], i->last_month_production[j], cargo_suffix[j].text, ToPercent8(i->last_month_pct_transported[j])); } - /* Transported productions */ - for (byte j = 0; j < lengthof(i->produced_cargo); j++) { - if (i->produced_cargo[j] == CT_INVALID) continue; - SetDParam(p++, ToPercent8(i->last_month_pct_transported[j])); + /* Sort by descending production, then descending transported */ + std::sort(cargos.begin(), cargos.end(), [](const CargoInfo a, const CargoInfo b) { + if (std::get<1>(a) != std::get<1>(b)) return std::get<1>(a) > std::get<1>(b); + return std::get<3>(a) > std::get<3>(b); + }); + + /* Display first 3 cargos */ + for (size_t j = 0; j < min(3, cargos.size()); j++) { + CargoInfo ci = cargos[j]; + SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO); + SetDParam(p++, std::get<0>(ci)); + SetDParam(p++, std::get<1>(ci)); + SetDParamStr(p++, std::get<2>(ci)); + SetDParam(p++, std::get<3>(ci)); } + /* Undisplayed cargos if any */ + SetDParam(p++, cargos.size() - 3); + /* Drawing the right string */ - switch (p) { - case 1: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD; - case 5: return STR_INDUSTRY_DIRECTORY_ITEM; - default: return STR_INDUSTRY_DIRECTORY_ITEM_TWO; + switch (cargos.size()) { + case 0: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD; + case 1: return STR_INDUSTRY_DIRECTORY_ITEM_PROD1; + case 2: return STR_INDUSTRY_DIRECTORY_ITEM_PROD2; + case 3: return STR_INDUSTRY_DIRECTORY_ITEM_PROD3; + default: return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE; } } diff --git a/src/lang/english.txt b/src/lang/english.txt index ea6c8520f..7c59faa54 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3392,9 +3392,12 @@ STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL :{WHITE}{CURRENC # Industry directory STR_INDUSTRY_DIRECTORY_CAPTION :{WHITE}Industries STR_INDUSTRY_DIRECTORY_NONE :{ORANGE}- None - -STR_INDUSTRY_DIRECTORY_ITEM :{ORANGE}{INDUSTRY}{BLACK} ({CARGO_LONG}{RAW_STRING}){YELLOW} ({COMMA}% transported) -STR_INDUSTRY_DIRECTORY_ITEM_TWO :{ORANGE}{INDUSTRY}{BLACK} ({CARGO_LONG}{RAW_STRING}/{CARGO_LONG}{RAW_STRING}){YELLOW} ({COMMA}%/{COMMA}% transported) +STR_INDUSTRY_DIRECTORY_ITEM_INFO :{BLACK}{CARGO_LONG}{RAW_STRING}{YELLOW} ({COMMA}% transported){BLACK} STR_INDUSTRY_DIRECTORY_ITEM_NOPROD :{ORANGE}{INDUSTRY} +STR_INDUSTRY_DIRECTORY_ITEM_PROD1 :{ORANGE}{INDUSTRY} {STRING4} +STR_INDUSTRY_DIRECTORY_ITEM_PROD2 :{ORANGE}{INDUSTRY} {STRING4}, {STRING4} +STR_INDUSTRY_DIRECTORY_ITEM_PROD3 :{ORANGE}{INDUSTRY} {STRING4}, {STRING4}, {STRING4} +STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE :{ORANGE}{INDUSTRY} {STRING4}, {STRING4}, {STRING4} and {NUM} more... STR_INDUSTRY_DIRECTORY_LIST_CAPTION :{BLACK}Industry names - click on name to centre main view on industry. Ctrl+Click opens a new viewport on industry location # Industry view -- cgit v1.2.3-70-g09d2