(svn r24615) -Feature [FS#5311]: Sort cargo filter by cargo name/label at the company stations window (sbr)

This commit is contained in:
terkhen 2012-10-20 08:44:07 +00:00
parent 232ef441eb
commit efb2ddf62a

View File

@ -293,9 +293,10 @@ public:
this->FinishInitNested(desc, window_number); this->FinishInitNested(desc, window_number);
this->owner = (Owner)this->window_number; this->owner = (Owner)this->window_number;
CargoID cid; const CargoSpec *cs;
FOR_EACH_SET_CARGO_ID(cid, this->cargo_filter) { FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (CargoSpec::Get(cid)->IsValid()) this->LowerWidget(WID_STL_CARGOSTART + cid); if (!HasBit(this->cargo_filter, cs->Index())) continue;
this->LowerWidget(WID_STL_CARGOSTART + index);
} }
if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask; if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask;
@ -360,14 +361,11 @@ public:
default: default:
if (widget >= WID_STL_CARGOSTART) { if (widget >= WID_STL_CARGOSTART) {
const CargoSpec *cs = CargoSpec::Get(widget - WID_STL_CARGOSTART); Dimension d = GetStringBoundingBox(_sorted_cargo_specs[widget - WID_STL_CARGOSTART]->abbrev);
if (cs->IsValid()) {
Dimension d = GetStringBoundingBox(cs->abbrev);
d.width += padding.width + 2; d.width += padding.width + 2;
d.height += padding.height; d.height += padding.height;
*size = maxdim(*size, d); *size = maxdim(*size, d);
} }
}
break; break;
} }
} }
@ -406,8 +404,9 @@ public:
x += rtl ? -5 : 5; x += rtl ? -5 : 5;
/* show cargo waiting and station ratings */ /* show cargo waiting and station ratings */
for (CargoID j = 0; j < NUM_CARGO; j++) { for (uint j = 0; j < _sorted_standard_cargo_specs_size; j++) {
if (!st->goods[j].cargo.Empty()) { CargoID cid = _sorted_cargo_specs[j]->Index();
if (!st->goods[cid].cargo.Empty()) {
/* For RTL we work in exactly the opposite direction. So /* For RTL we work in exactly the opposite direction. So
* decrement the space needed first, then draw to the left * decrement the space needed first, then draw to the left
* instead of drawing to the left and then incrementing * instead of drawing to the left and then incrementing
@ -416,7 +415,7 @@ public:
x -= 20; x -= 20;
if (x < r.left + WD_FRAMERECT_LEFT) break; 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) { if (!rtl) {
x += 20; x += 20;
if (x > r.right - WD_FRAMERECT_RIGHT) break; if (x > r.right - WD_FRAMERECT_RIGHT) break;
@ -453,13 +452,11 @@ public:
default: default:
if (widget >= WID_STL_CARGOSTART) { 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; 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); GfxFillRect(r.left + cg_ofst, r.top + cg_ofst, r.right - 2 + cg_ofst, r.bottom - 2 + cg_ofst, cs->rating_colour);
DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, cs->abbrev, TC_BLACK, SA_HOR_CENTER); DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + cg_ofst, cs->abbrev, TC_BLACK, SA_HOR_CENTER);
} }
}
break; break;
} }
} }
@ -522,9 +519,8 @@ public:
break; break;
case WID_STL_CARGOALL: { case WID_STL_CARGOALL: {
for (uint i = 0; i < NUM_CARGO; i++) { for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
const CargoSpec *cs = CargoSpec::Get(i); this->LowerWidget(WID_STL_CARGOSTART + i);
if (cs->IsValid()) this->LowerWidget(WID_STL_CARGOSTART + i);
} }
this->LowerWidget(WID_STL_NOCARGOWAITING); this->LowerWidget(WID_STL_NOCARGOWAITING);
@ -551,9 +547,8 @@ public:
this->include_empty = !this->include_empty; this->include_empty = !this->include_empty;
this->ToggleWidgetLoweredState(WID_STL_NOCARGOWAITING); this->ToggleWidgetLoweredState(WID_STL_NOCARGOWAITING);
} else { } else {
for (uint i = 0; i < NUM_CARGO; i++) { for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
const CargoSpec *cs = CargoSpec::Get(i); this->RaiseWidget(WID_STL_CARGOSTART + i);
if (cs->IsValid()) this->RaiseWidget(WID_STL_CARGOSTART + i);
} }
this->cargo_filter = 0; this->cargo_filter = 0;
@ -568,16 +563,14 @@ public:
default: default:
if (widget >= WID_STL_CARGOSTART) { // change cargo_filter if (widget >= WID_STL_CARGOSTART) { // change cargo_filter
/* Determine the selected cargo type */ /* 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) { if (_ctrl_pressed) {
ToggleBit(this->cargo_filter, cs->Index()); ToggleBit(this->cargo_filter, cs->Index());
this->ToggleWidgetLoweredState(widget); this->ToggleWidgetLoweredState(widget);
} else { } else {
for (uint i = 0; i < NUM_CARGO; i++) { for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
const CargoSpec *cs = CargoSpec::Get(i); this->RaiseWidget(WID_STL_CARGOSTART + i);
if (cs->IsValid()) this->RaiseWidget(WID_STL_CARGOSTART + i);
} }
this->RaiseWidget(WID_STL_NOCARGOWAITING); this->RaiseWidget(WID_STL_NOCARGOWAITING);
@ -677,24 +670,15 @@ static NWidgetBase *CargoWidgets(int *biggest_index)
{ {
NWidgetHorizontal *container = new NWidgetHorizontal(); NWidgetHorizontal *container = new NWidgetHorizontal();
for (uint i = 0; i < NUM_CARGO; i++) { for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
const CargoSpec *cs = CargoSpec::Get(i);
if (cs->IsValid()) {
NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i); NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i);
panel->SetMinimalSize(14, 11); panel->SetMinimalSize(14, 11);
panel->SetResize(0, 0); panel->SetResize(0, 0);
panel->SetFill(0, 1); panel->SetFill(0, 1);
panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE); panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE);
container->Add(panel); container->Add(panel);
} else {
NWidgetLeaf *nwi = new NWidgetLeaf(WWT_EMPTY, COLOUR_GREY, WID_STL_CARGOSTART + i, 0x0, STR_NULL);
nwi->SetMinimalSize(0, 11);
nwi->SetResize(0, 0);
nwi->SetFill(0, 1);
container->Add(nwi);
} }
} *biggest_index = WID_STL_CARGOSTART + _sorted_standard_cargo_specs_size;
*biggest_index = WID_STL_CARGOSTART + NUM_CARGO;
return container; return container;
} }