# HG changeset patch # Parent 1d2f6bfa1c782f57740262df8f244b1fc6a6c171 # User sbr # Date 1348900829 -7200 Sort the cargoes buttons and cargoes ratings of CompanyStationsWindow by class / name. diff -r 1d2f6bfa1c78 src/station_gui.cpp --- a/src/station_gui.cpp Fri Sep 28 17:45:09 2012 +0000 +++ b/src/station_gui.cpp Sat Sep 29 12:41:45 2012 +0200 @@ -293,9 +293,10 @@ this->FinishInitNested(desc, window_number); this->owner = (Owner)this->window_number; - CargoID cid; - FOR_EACH_SET_CARGO_ID(cid, this->cargo_filter) { - if (CargoSpec::Get(cid)->IsValid()) this->LowerWidget(WID_STL_CARGOSTART + cid); + const CargoSpec *cs; + FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { + if (!HasBit(this->cargo_filter, cs->Index())) continue; + if (cs->IsValid()) this->LowerWidget(WID_STL_CARGOSTART + index); } if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask; @@ -360,7 +361,7 @@ default: if (widget >= WID_STL_CARGOSTART) { - const CargoSpec *cs = CargoSpec::Get(widget - WID_STL_CARGOSTART); + const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART]; if (cs->IsValid()) { Dimension d = GetStringBoundingBox(cs->abbrev); d.width += padding.width + 2; @@ -406,8 +407,9 @@ x += rtl ? -5 : 5; /* show cargo waiting and station ratings */ - for (CargoID j = 0; j < NUM_CARGO; j++) { - if (!st->goods[j].cargo.Empty()) { + for (uint j = 0; j < _sorted_standard_cargo_specs_size; j++) { + CargoID cid = _sorted_cargo_specs[j]->Index(); + if (!st->goods[cid].cargo.Empty()) { /* For RTL we work in exactly the opposite direction. So * decrement the space needed first, then draw to the left * instead of drawing to the left and then incrementing @@ -416,7 +418,7 @@ x -= 20; if (x < r.left + WD_FRAMERECT_LEFT) break; } - StationsWndShowStationRating(x, x + 16, y, j, st->goods[j].cargo.Count(), st->goods[j].rating); + StationsWndShowStationRating(x, x + 16, y, cid, st->goods[cid].cargo.Count(), st->goods[cid].rating); if (!rtl) { x += 20; if (x > r.right - WD_FRAMERECT_RIGHT) break; @@ -453,7 +455,7 @@ default: if (widget >= WID_STL_CARGOSTART) { - const CargoSpec *cs = CargoSpec::Get(widget - WID_STL_CARGOSTART); + const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART]; if (cs->IsValid()) { int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 2 : 1; GfxFillRect(r.left + cg_ofst, r.top + cg_ofst, r.right - 2 + cg_ofst, r.bottom - 2 + cg_ofst, cs->rating_colour); @@ -522,8 +524,8 @@ break; case WID_STL_CARGOALL: { - for (uint i = 0; i < NUM_CARGO; i++) { - const CargoSpec *cs = CargoSpec::Get(i); + for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) { + const CargoSpec *cs = _sorted_cargo_specs[i]; if (cs->IsValid()) this->LowerWidget(WID_STL_CARGOSTART + i); } this->LowerWidget(WID_STL_NOCARGOWAITING); @@ -551,8 +553,8 @@ this->include_empty = !this->include_empty; this->ToggleWidgetLoweredState(WID_STL_NOCARGOWAITING); } else { - for (uint i = 0; i < NUM_CARGO; i++) { - const CargoSpec *cs = CargoSpec::Get(i); + for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) { + const CargoSpec *cs = _sorted_cargo_specs[i]; if (cs->IsValid()) this->RaiseWidget(WID_STL_CARGOSTART + i); } @@ -568,15 +570,15 @@ default: if (widget >= WID_STL_CARGOSTART) { // change cargo_filter /* Determine the selected cargo type */ - const CargoSpec *cs = CargoSpec::Get(widget - WID_STL_CARGOSTART); + const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART]; if (!cs->IsValid()) break; if (_ctrl_pressed) { ToggleBit(this->cargo_filter, cs->Index()); this->ToggleWidgetLoweredState(widget); } else { - for (uint i = 0; i < NUM_CARGO; i++) { - const CargoSpec *cs = CargoSpec::Get(i); + for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) { + const CargoSpec *cs = _sorted_cargo_specs[i]; if (cs->IsValid()) this->RaiseWidget(WID_STL_CARGOSTART + i); } this->RaiseWidget(WID_STL_NOCARGOWAITING); @@ -677,8 +679,8 @@ { NWidgetHorizontal *container = new NWidgetHorizontal(); - for (uint i = 0; i < NUM_CARGO; i++) { - const CargoSpec *cs = CargoSpec::Get(i); + for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) { + const CargoSpec *cs = _sorted_cargo_specs[i]; if (cs->IsValid()) { NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i); panel->SetMinimalSize(14, 11); @@ -694,7 +696,7 @@ container->Add(nwi); } } - *biggest_index = WID_STL_CARGOSTART + NUM_CARGO; + *biggest_index = WID_STL_CARGOSTART + _sorted_standard_cargo_specs_size; return container; }