summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-11-03 14:09:13 +0100
committerCharles Pigott <charlespigott@googlemail.com>2019-11-13 08:11:37 +0000
commitfa657c83604c11a27a62be7515b5395ab498dd86 (patch)
tree2143bf0e3a79bfd6683a7dbdc4ccdfe0782f052a /src
parent4eab70f84e0302f40ed356bb8965a8bb90a63e05 (diff)
downloadopenttd-fa657c83604c11a27a62be7515b5395ab498dd86.tar.xz
Fix #7631: 16 out cargo support for industry directory
Diffstat (limited to 'src')
-rw-r--r--src/industry_gui.cpp40
-rw-r--r--src/lang/english.txt7
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<CargoID, uint16, const char*, uint> CargoInfo;
+ std::vector<CargoInfo> 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<size_t>(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