File diff r12404:d58b2d050240 → r12405:ba094e765533
src/station_gui.cpp
Show inline comments
 
@@ -40,25 +40,25 @@
 
 * @param type   Cargo type
 
 * @param amount Cargo amount
 
 * @param rating ratings data for that particular cargo
 
 *
 
 * @note Each cargo-bar is 16 pixels wide and 6 pixels high
 
 * @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar
 
 */
 
static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, byte rating)
 
{
 
	static const uint units_full  = 576; ///< number of units to show station as 'full'
 
	static const uint rating_full = 224; ///< rating needed so it is shown as 'full'
 

	
 
	const CargoSpec *cs = GetCargo(type);
 
	const CargoSpec *cs = CargoSpec::Get(type);
 
	if (!cs->IsValid()) return;
 

	
 
	int colour = cs->rating_colour;
 
	uint w = (minu(amount, units_full) + 5) / 36;
 

	
 
	/* Draw total cargo (limited) on station (fits into 16 pixels) */
 
	if (w != 0) GfxFillRect(left, y, left + w - 1, y + 6, colour);
 

	
 
	/* Draw a one pixel-wide bar of additional cargo meter, useful
 
	 * for stations with only a small amount (<=30) */
 
	if (w == 0) {
 
		uint rest = amount / 5;
 
@@ -249,34 +249,34 @@ protected:
 

	
 
public:
 
	CompanyStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
		this->owner = (Owner)this->window_number;
 
		this->vscroll.cap = 12;
 
		this->resize.step_height = 10;
 
		this->resize.height = this->height - 10 * 7; // minimum if 5 in the list
 

	
 
		/* Add cargo filter buttons */
 
		uint num_active = 0;
 
		for (CargoID c = 0; c < NUM_CARGO; c++) {
 
			if (GetCargo(c)->IsValid()) num_active++;
 
			if (CargoSpec::Get(c)->IsValid()) num_active++;
 
		}
 

	
 
		this->widget_count += num_active;
 
		this->widget = ReallocT(this->widget, this->widget_count + 1);
 
		this->widget[this->widget_count].type = WWT_LAST;
 

	
 
		uint i = 0;
 
		for (CargoID c = 0; c < NUM_CARGO; c++) {
 
			if (!GetCargo(c)->IsValid()) continue;
 
			if (!CargoSpec::Get(c)->IsValid()) continue;
 

	
 
			Widget *wi = &this->widget[SLW_CARGOSTART + i];
 
			wi->type     = WWT_PANEL;
 
			wi->display_flags = RESIZE_NONE;
 
			wi->colour   = COLOUR_GREY;
 
			wi->left     = 89 + i * 14;
 
			wi->right    = wi->left + 13;
 
			wi->top      = 14;
 
			wi->bottom   = 24;
 
			wi->data     = 0;
 
			wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
 

	
 
@@ -337,25 +337,25 @@ public:
 
		this->DrawWidgets();
 

	
 
		/* draw arrow pointing up/down for ascending/descending sorting */
 
		this->DrawSortButtonState(SLW_SORTBY, this->stations.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
 

	
 
		int cg_ofst;
 
		int x = 89;
 
		int y = 14;
 
		int xb = 2; ///< offset from left of widget
 

	
 
		uint i = 0;
 
		for (CargoID c = 0; c < NUM_CARGO; c++) {
 
			const CargoSpec *cs = GetCargo(c);
 
			const CargoSpec *cs = CargoSpec::Get(c);
 
			if (!cs->IsValid()) continue;
 

	
 
			cg_ofst = HasBit(this->cargo_filter, c) ? 2 : 1;
 
			GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
 
			DrawString(x + cg_ofst, x + 12 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK, SA_CENTER);
 
			x += 14;
 
			i++;
 
		}
 

	
 
		cg_ofst = this->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
 
		DrawString(x + cg_ofst, x + cg_ofst + 12, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK, SA_CENTER);
 
		x += 14;
 
@@ -448,25 +448,25 @@ public:
 
					this->LowerWidget(i + SLW_TRAIN);
 
				}
 
				this->LowerWidget(SLW_FACILALL);
 

	
 
				this->facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
 
				this->stations.ForceRebuild();
 
				this->SetDirty();
 
				break;
 

	
 
			case SLW_CARGOALL: {
 
				uint i = 0;
 
				for (CargoID c = 0; c < NUM_CARGO; c++) {
 
					if (!GetCargo(c)->IsValid()) continue;
 
					if (!CargoSpec::Get(c)->IsValid()) continue;
 
					this->LowerWidget(i + SLW_CARGOSTART);
 
					i++;
 
				}
 
				this->LowerWidget(SLW_NOCARGOWAITING);
 
				this->LowerWidget(SLW_CARGOALL);
 

	
 
				this->cargo_filter = _cargo_mask;
 
				this->include_empty = true;
 
				this->stations.ForceRebuild();
 
				this->SetDirty();
 
				break;
 
			}
 
@@ -498,25 +498,25 @@ public:
 
				}
 
				this->SetWidgetLoweredState(SLW_CARGOALL, this->cargo_filter == _cargo_mask && this->include_empty);
 
				this->stations.ForceRebuild();
 
				this->SetDirty();
 
				break;
 

	
 
			default:
 
				if (widget >= SLW_CARGOSTART) { // change cargo_filter
 
					/* Determine the selected cargo type */
 
					CargoID c;
 
					int i = 0;
 
					for (c = 0; c < NUM_CARGO; c++) {
 
						if (!GetCargo(c)->IsValid()) continue;
 
						if (!CargoSpec::Get(c)->IsValid()) continue;
 
						if (widget - SLW_CARGOSTART == i) break;
 
						i++;
 
					}
 

	
 
					if (_ctrl_pressed) {
 
						ToggleBit(this->cargo_filter, c);
 
						this->ToggleWidgetLoweredState(widget);
 
					} else {
 
						for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
 
							this->RaiseWidget(i);
 
						}
 
						this->RaiseWidget(SLW_NOCARGOWAITING);
 
@@ -715,25 +715,25 @@ static const NWidgetPart _nested_station
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_ACCEPTS), SetMinimalSize(61, 12), SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_RENAME), SetMinimalSize(60, 12), SetResize(1, 0), SetDataTip(STR_QUERY_RENAME, STR_STATION_VIEW_RENAME_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_TRAINS), SetMinimalSize(14, 12), SetDataTip(STR_TRAIN, STR_SCHEDULED_TRAINS_TIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_ROADVEHS), SetMinimalSize(14, 12), SetDataTip(STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_PLANES),  SetMinimalSize(14, 12), SetDataTip(STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, SVW_SHIPS), SetMinimalSize(14, 12), SetDataTip(STR_SHIP, STR_SCHEDULED_SHIPS_TIP),
 
		NWidget(WWT_RESIZEBOX, COLOUR_GREY, SVW_RESIZE),
 
	EndContainer(),
 
};
 

	
 
SpriteID GetCargoSprite(CargoID i)
 
{
 
	const CargoSpec *cs = GetCargo(i);
 
	const CargoSpec *cs = CargoSpec::Get(i);
 
	SpriteID sprite;
 

	
 
	if (cs->sprite == 0xFFFF) {
 
		/* A value of 0xFFFF indicates we should draw a custom icon */
 
		sprite = GetCustomCargoSprite(cs);
 
	} else {
 
		sprite = cs->sprite;
 
	}
 

	
 
	if (sprite == 0) sprite = SPR_CARGO_GOODS;
 

	
 
	return sprite;
 
@@ -915,46 +915,46 @@ struct StationViewWindow : public Window
 
			b = InlineString(b, STR_STATION_VIEW_ACCEPTS_CARGO);
 

	
 
			for (CargoID i = 0; i < NUM_CARGO; i++) {
 
				if (b >= lastof(string) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
 
				if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
 
					if (first) {
 
						first = false;
 
					} else {
 
						/* Add a comma if this is not the first item */
 
						*b++ = ',';
 
						*b++ = ' ';
 
					}
 
					b = InlineString(b, GetCargo(i)->name);
 
					b = InlineString(b, CargoSpec::Get(i)->name);
 
				}
 
			}
 

	
 
			/* If first is still true then no cargo is accepted */
 
			if (first) b = InlineString(b, STR_JUST_NOTHING);
 

	
 
			*b = '\0';
 

	
 
			/* Make sure we detect any buffer overflow */
 
			assert(b < endof(string));
 

	
 
			SetDParamStr(0, string);
 
			DrawStringMultiLine(this->widget[SVW_ACCEPTLIST].left + 2, this->widget[SVW_ACCEPTLIST].right - 2, this->widget[SVW_ACCEPTLIST].top + 1, this->widget[SVW_ACCEPTLIST].bottom - 1, STR_JUST_RAW_STRING);
 
		} else { // extended window with list of cargo ratings
 
			y = this->widget[SVW_RATINGLIST].top + 1;
 

	
 
			DrawString(this->widget[SVW_ACCEPTLIST].left + 2, this->widget[SVW_ACCEPTLIST].right - 2, y, STR_STATION_VIEW_CARGO_RATINGS_TITLE);
 
			y += 10;
 

	
 
			for (CargoID i = 0; i < NUM_CARGO; i++) {
 
				const CargoSpec *cs = GetCargo(i);
 
				const CargoSpec *cs = CargoSpec::Get(i);
 
				if (!cs->IsValid()) continue;
 

	
 
				const GoodsEntry *ge = &st->goods[i];
 
				if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
 

	
 
				SetDParam(0, cs->name);
 
				SetDParam(2, ge->rating * 101 >> 8);
 
				SetDParam(1, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
 
				DrawString(this->widget[SVW_ACCEPTLIST].left + 8, this->widget[SVW_ACCEPTLIST].right - 2, y, STR_STATION_VIEW_CARGO_RATING);
 
				y += 10;
 
			}
 
		}