src/station_gui.cpp
changeset 7928 63e18de69e50
parent 7886 f0901496b7f1
child 7931 b0a46cd92225
equal deleted inserted replaced
7927:3a3289a049f9 7928:63e18de69e50
   135 	const Station* st1 = *(const Station**)a;
   135 	const Station* st1 = *(const Station**)a;
   136 	const Station* st2 = *(const Station**)b;
   136 	const Station* st2 = *(const Station**)b;
   137 	Money sum1 = 0, sum2 = 0;
   137 	Money sum1 = 0, sum2 = 0;
   138 
   138 
   139 	for (CargoID j = 0; j < NUM_CARGO; j++) {
   139 	for (CargoID j = 0; j < NUM_CARGO; j++) {
   140 		if (!HASBIT(_cargo_filter, j)) continue;
   140 		if (!HasBit(_cargo_filter, j)) continue;
   141 		if (!st1->goods[j].cargo.Empty()) sum1 += GetTransportedGoodsIncome(st1->goods[j].cargo.Count(), 20, 50, j);
   141 		if (!st1->goods[j].cargo.Empty()) sum1 += GetTransportedGoodsIncome(st1->goods[j].cargo.Count(), 20, 50, j);
   142 		if (!st2->goods[j].cargo.Empty()) sum2 += GetTransportedGoodsIncome(st2->goods[j].cargo.Count(), 20, 50, j);
   142 		if (!st2->goods[j].cargo.Empty()) sum2 += GetTransportedGoodsIncome(st2->goods[j].cargo.Count(), 20, 50, j);
   143 	}
   143 	}
   144 
   144 
   145 	return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2);
   145 	return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2);
   159 	const Station* st2 = *(const Station**)b;
   159 	const Station* st2 = *(const Station**)b;
   160 	byte maxr1 = 0;
   160 	byte maxr1 = 0;
   161 	byte maxr2 = 0;
   161 	byte maxr2 = 0;
   162 
   162 
   163 	for (CargoID j = 0; j < NUM_CARGO; j++) {
   163 	for (CargoID j = 0; j < NUM_CARGO; j++) {
   164 		if (HASBIT(st1->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, st1->goods[j].rating);
   164 		if (HasBit(st1->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, st1->goods[j].rating);
   165 		if (HASBIT(st2->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, st2->goods[j].rating);
   165 		if (HasBit(st2->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, st2->goods[j].rating);
   166 	}
   166 	}
   167 
   167 
   168 	return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
   168 	return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
   169 }
   169 }
   170 
   170 
   229 			if (facilities & st->facilities) { //only stations with selected facilities
   229 			if (facilities & st->facilities) { //only stations with selected facilities
   230 				int num_waiting_cargo = 0;
   230 				int num_waiting_cargo = 0;
   231 				for (CargoID j = 0; j < NUM_CARGO; j++) {
   231 				for (CargoID j = 0; j < NUM_CARGO; j++) {
   232 					if (!st->goods[j].cargo.Empty()) {
   232 					if (!st->goods[j].cargo.Empty()) {
   233 						num_waiting_cargo++; //count number of waiting cargo
   233 						num_waiting_cargo++; //count number of waiting cargo
   234 						if (HASBIT(cargo_filter, j)) {
   234 						if (HasBit(cargo_filter, j)) {
   235 							station_sort[n++] = st;
   235 							station_sort[n++] = st;
   236 							break;
   236 							break;
   237 						}
   237 						}
   238 					}
   238 					}
   239 				}
   239 				}
   288 	switch (e->event) {
   288 	switch (e->event) {
   289 		case WE_CREATE: /* set up resort timer */
   289 		case WE_CREATE: /* set up resort timer */
   290 			if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
   290 			if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
   291 
   291 
   292 			for (uint i = 0; i < 5; i++) {
   292 			for (uint i = 0; i < 5; i++) {
   293 				if (HASBIT(facilities, i)) LowerWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
   293 				if (HasBit(facilities, i)) LowerWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
   294 			}
   294 			}
   295 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
   295 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
   296 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
   296 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
   297 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_NOCARGOWAITING, include_empty);
   297 			SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_NOCARGOWAITING, include_empty);
   298 
   298 
   327 			uint i = 0;
   327 			uint i = 0;
   328 			for (CargoID c = 0; c < NUM_CARGO; c++) {
   328 			for (CargoID c = 0; c < NUM_CARGO; c++) {
   329 				const CargoSpec *cs = GetCargo(c);
   329 				const CargoSpec *cs = GetCargo(c);
   330 				if (!cs->IsValid()) continue;
   330 				if (!cs->IsValid()) continue;
   331 
   331 
   332 				cg_ofst = HASBIT(_cargo_filter, c) ? 2 : 1;
   332 				cg_ofst = HasBit(_cargo_filter, c) ? 2 : 1;
   333 				GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
   333 				GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
   334 				DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK);
   334 				DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK);
   335 				x += 14;
   335 				x += 14;
   336 				i++;
   336 				i++;
   337 			}
   337 			}
   402 					if (_ctrl_pressed) {
   402 					if (_ctrl_pressed) {
   403 						TOGGLEBIT(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
   403 						TOGGLEBIT(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
   404 						ToggleWidgetLoweredState(w, e->we.click.widget);
   404 						ToggleWidgetLoweredState(w, e->we.click.widget);
   405 					} else {
   405 					} else {
   406 						for (uint i = 0; facilities != 0; i++, facilities >>= 1) {
   406 						for (uint i = 0; facilities != 0; i++, facilities >>= 1) {
   407 							if (HASBIT(facilities, 0)) RaiseWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
   407 							if (HasBit(facilities, 0)) RaiseWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
   408 						}
   408 						}
   409 						SETBIT(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
   409 						SETBIT(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
   410 						LowerWindowWidget(w, e->we.click.widget);
   410 						LowerWindowWidget(w, e->we.click.widget);
   411 					}
   411 					}
   412 					SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
   412 					SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
   442 					break;
   442 					break;
   443 				}
   443 				}
   444 
   444 
   445 				case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/
   445 				case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/
   446 					sl->flags ^= SL_ORDER; //DESC-flag
   446 					sl->flags ^= SL_ORDER; //DESC-flag
   447 					station_sort.order = HASBIT(sl->flags, 0);
   447 					station_sort.order = HasBit(sl->flags, 0);
   448 					sl->flags |= SL_RESORT;
   448 					sl->flags |= SL_RESORT;
   449 					w->flags4 |= 5 << WF_TIMEOUT_SHL;
   449 					w->flags4 |= 5 << WF_TIMEOUT_SHL;
   450 					LowerWindowWidget(w, STATIONLIST_WIDGET_SORTBY);
   450 					LowerWindowWidget(w, STATIONLIST_WIDGET_SORTBY);
   451 					SetWindowDirty(w);
   451 					SetWindowDirty(w);
   452 					break;
   452 					break;
   613 		wi->top      = 14;
   613 		wi->top      = 14;
   614 		wi->bottom   = 24;
   614 		wi->bottom   = 24;
   615 		wi->data     = 0;
   615 		wi->data     = 0;
   616 		wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
   616 		wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
   617 
   617 
   618 		if (HASBIT(_cargo_filter, c)) LowerWindowWidget(w, STATIONLIST_WIDGET_CARGOSTART + i);
   618 		if (HasBit(_cargo_filter, c)) LowerWindowWidget(w, STATIONLIST_WIDGET_CARGOSTART + i);
   619 		i++;
   619 		i++;
   620 	}
   620 	}
   621 
   621 
   622 	w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].left += num_active * 14;
   622 	w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].left += num_active * 14;
   623 	w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].right += num_active * 14;
   623 	w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].right += num_active * 14;
   770 
   770 
   771 		b = InlineString(b, STR_000C_ACCEPTS);
   771 		b = InlineString(b, STR_000C_ACCEPTS);
   772 
   772 
   773 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   773 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   774 			if (b >= endof(_userstring) - 5 - 1) break;
   774 			if (b >= endof(_userstring) - 5 - 1) break;
   775 			if (HASBIT(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
   775 			if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
   776 				if (first) {
   776 				if (first) {
   777 					first = false;
   777 					first = false;
   778 				} else {
   778 				} else {
   779 					/* Add a comma if this is not the first item */
   779 					/* Add a comma if this is not the first item */
   780 					*b++ = ',';
   780 					*b++ = ',';
   796 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   796 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   797 			const CargoSpec *cs = GetCargo(i);
   797 			const CargoSpec *cs = GetCargo(i);
   798 			if (!cs->IsValid()) continue;
   798 			if (!cs->IsValid()) continue;
   799 
   799 
   800 			const GoodsEntry *ge = &st->goods[i];
   800 			const GoodsEntry *ge = &st->goods[i];
   801 			if (!HASBIT(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
   801 			if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
   802 
   802 
   803 			SetDParam(0, cs->name);
   803 			SetDParam(0, cs->name);
   804 			SetDParam(2, ge->rating * 101 >> 8);
   804 			SetDParam(2, ge->rating * 101 >> 8);
   805 			SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
   805 			SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
   806 			DrawString(8, y, STR_303D, TC_FROMSTRING);
   806 			DrawString(8, y, STR_303D, TC_FROMSTRING);