Change: Display cargo lists in sorted cargo order. (#11383)

This commit is contained in:
Peter Nelson 2023-10-20 17:32:17 +01:00 committed by GitHub
parent 088db62dba
commit bb6fa9bf3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 27 deletions

View File

@ -574,11 +574,12 @@ static uint GetCargoWeight(const CargoArray &cap, VehicleType vtype)
static int DrawCargoCapacityInfo(int left, int right, int y, TestedEngineDetails &te, bool refittable) static int DrawCargoCapacityInfo(int left, int right, int y, TestedEngineDetails &te, bool refittable)
{ {
for (CargoID c = 0; c < NUM_CARGO; c++) { for (const CargoSpec *cs : _sorted_cargo_specs) {
if (te.all_capacities[c] == 0) continue; CargoID cid = cs->Index();
if (te.all_capacities[cid] == 0) continue;
SetDParam(0, c); SetDParam(0, cid);
SetDParam(1, te.all_capacities[c]); SetDParam(1, te.all_capacities[cid]);
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY); SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY); DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;

View File

@ -876,7 +876,8 @@ struct DepotWindow : Window {
static std::string details; static std::string details;
details.clear(); details.clear();
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { for (const CargoSpec *cs : _sorted_cargo_specs) {
CargoID cargo_type = cs->Index();
if (capacity[cargo_type] == 0) continue; if (capacity[cargo_type] == 0) continue;
SetDParam(0, cargo_type); // {CARGO} #1 SetDParam(0, cargo_type); // {CARGO} #1

View File

@ -306,19 +306,20 @@ public:
line << GetString(STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED); line << GetString(STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED);
bool found = false; bool found = false;
for (CargoID i = 0; i < NUM_CARGO; ++i) { for (const CargoSpec *cs : _sorted_cargo_specs) {
if (acceptance[i] > 0) { CargoID cid = cs->Index();
if (acceptance[cid] > 0) {
/* Add a comma between each item. */ /* Add a comma between each item. */
if (found) line << ", "; if (found) line << ", ";
found = true; found = true;
/* If the accepted value is less than 8, show it in 1/8:ths */ /* If the accepted value is less than 8, show it in 1/8:ths */
if (acceptance[i] < 8) { if (acceptance[cid] < 8) {
SetDParam(0, acceptance[i]); SetDParam(0, acceptance[cid]);
SetDParam(1, CargoSpec::Get(i)->name); SetDParam(1, cs->name);
line << GetString(STR_LAND_AREA_INFORMATION_CARGO_EIGHTS); line << GetString(STR_LAND_AREA_INFORMATION_CARGO_EIGHTS);
} else { } else {
line << GetString(CargoSpec::Get(i)->name); line << GetString(cs->name);
} }
} }
} }

View File

@ -40,9 +40,7 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
if (v->HasArticulatedPart()) { if (v->HasArticulatedPart()) {
CargoArray max_cargo{}; CargoArray max_cargo{};
StringID subtype_text[NUM_CARGO]; std::array<StringID, NUM_CARGO> subtype_text{};
memset(subtype_text, 0, sizeof(subtype_text));
for (const Vehicle *u = v; u != nullptr; u = u->Next()) { for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
max_cargo[u->cargo_type] += u->cargo_cap; max_cargo[u->cargo_type] += u->cargo_cap;
@ -55,16 +53,17 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
std::string capacity = GetString(STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY); std::string capacity = GetString(STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY);
bool first = true; bool first = true;
for (CargoID i = 0; i < NUM_CARGO; i++) { for (const CargoSpec *cs : _sorted_cargo_specs) {
if (max_cargo[i] > 0) { CargoID cid = cs->Index();
if (max_cargo[cid] > 0) {
if (!first) capacity += ", "; if (!first) capacity += ", ";
SetDParam(0, i); SetDParam(0, cid);
SetDParam(1, max_cargo[i]); SetDParam(1, max_cargo[cid]);
capacity += GetString(STR_JUST_CARGO); capacity += GetString(STR_JUST_CARGO);
if (subtype_text[i] != 0) { if (subtype_text[cid] != STR_NULL) {
capacity += GetString(subtype_text[i]); capacity += GetString(subtype_text[cid]);
} }
first = false; first = false;

View File

@ -447,14 +447,15 @@ void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t v
/* Indent the total cargo capacity details */ /* Indent the total cargo capacity details */
Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl); Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl);
for (CargoID i = 0; i < NUM_CARGO; i++) { for (const CargoSpec *cs : _sorted_cargo_specs) {
if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) { CargoID cid = cs->Index();
SetDParam(0, i); // {CARGO} #1 if (max_cargo[cid] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
SetDParam(1, act_cargo[i]); // {CARGO} #2 SetDParam(0, cid); // {CARGO} #1
SetDParam(2, i); // {SHORTCARGO} #1 SetDParam(1, act_cargo[cid]); // {CARGO} #2
SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2 SetDParam(2, cid); // {SHORTCARGO} #1
SetDParam(3, max_cargo[cid]); // {SHORTCARGO} #2
SetDParam(4, _settings_game.vehicle.freight_trains); SetDParam(4, _settings_game.vehicle.freight_trains);
DrawString(ir.left, ir.right, y + text_y_offset, FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY); DrawString(ir.left, ir.right, y + text_y_offset, FreightWagonMult(cid) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
y += line_height; y += line_height;
} }
} }