Changeset - r21978:f6b80d19a51e
[Not reviewed]
master
0 1 0
frosch - 9 years ago 2015-02-01 19:40:04
frosch@openttd.org
(svn r27133) -Fix: Dragging of free wagons in depot failed with GUI zoom.
1 file changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/depot_gui.cpp
Show inline comments
 
@@ -408,49 +408,49 @@ struct DepotWindow : Window {
 

	
 
		uint pos = ((row + this->vscroll->GetPosition()) * this->num_columns) + xt;
 

	
 
		if (this->vehicle_list.Length() + this->wagon_list.Length() <= pos) {
 
			/* Clicking on 'line' / 'block' without a vehicle */
 
			if (this->type == VEH_TRAIN) {
 
				/* End the dragging */
 
				d->head  = NULL;
 
				d->wagon = NULL;
 
				return MODE_DRAG_VEHICLE;
 
			} else {
 
				return MODE_ERROR; // empty block, so no vehicle is selected
 
			}
 
		}
 

	
 
		bool wagon = false;
 
		if (this->vehicle_list.Length() > pos) {
 
			*veh = this->vehicle_list[pos];
 
			/* Skip vehicles that are scrolled off the list */
 
			if (this->type == VEH_TRAIN) x += this->hscroll->GetPosition();
 
		} else {
 
			pos -= this->vehicle_list.Length();
 
			*veh = this->wagon_list[pos];
 
			/* free wagons don't have an initial loco. */
 
			x -= VEHICLEINFO_FULL_VEHICLE_WIDTH;
 
			x -= UnScaleByZoom(VEHICLEINFO_FULL_VEHICLE_WIDTH * ZOOM_LVL_BASE, ZOOM_LVL_GUI);
 
			wagon = true;
 
		}
 

	
 
		const Train *v = NULL;
 
		if (this->type == VEH_TRAIN) {
 
			v = Train::From(*veh);
 
			d->head = d->wagon = v;
 
		}
 

	
 
		if (xm <= this->header_width) {
 
			switch (this->type) {
 
				case VEH_TRAIN:
 
					if (wagon) return MODE_ERROR;
 
					/* FALL THROUGH */
 
				case VEH_ROAD:
 
					if (xm <= this->flag_width) return MODE_START_STOP;
 
					break;
 

	
 
				case VEH_SHIP:
 
				case VEH_AIRCRAFT:
 
					if (xm <= this->flag_width && ym >= (uint)(FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL)) return MODE_START_STOP;
 
					break;
 

	
 
				default: NOT_REACHED();
 
@@ -648,49 +648,49 @@ struct DepotWindow : Window {
 
	 */
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		this->generate_list = true;
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		if (this->generate_list) {
 
			/* Generate the vehicle list
 
			 * It's ok to use the wagon pointers for non-trains as they will be ignored */
 
			BuildDepotVehicleList(this->type, this->window_number, &this->vehicle_list, &this->wagon_list);
 
			this->generate_list = false;
 
			DepotSortList(&this->vehicle_list);
 

	
 
			uint new_unitnumber_digits = GetUnitNumberDigits(this->vehicle_list);
 
			if (this->unitnumber_digits != new_unitnumber_digits) {
 
				this->unitnumber_digits = new_unitnumber_digits;
 
				this->ReInit();
 
			}
 
		}
 

	
 
		/* determine amount of items for scroller */
 
		if (this->type == VEH_TRAIN) {
 
			uint max_width = VEHICLEINFO_FULL_VEHICLE_WIDTH;
 
			uint max_width = UnScaleByZoom(VEHICLEINFO_FULL_VEHICLE_WIDTH * ZOOM_LVL_BASE, ZOOM_LVL_GUI);
 
			for (uint num = 0; num < this->vehicle_list.Length(); num++) {
 
				uint width = 0;
 
				for (const Train *v = Train::From(this->vehicle_list[num]); v != NULL; v = v->Next()) {
 
					width += v->GetDisplayImageWidth();
 
				}
 
				max_width = max(max_width, width);
 
			}
 
			/* Always have 1 empty row, so people can change the setting of the train */
 
			this->vscroll->SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
 
			this->hscroll->SetCount(max_width);
 
		} else {
 
			this->vscroll->SetCount(CeilDiv(this->vehicle_list.Length(), this->num_columns));
 
		}
 

	
 
		/* Setup disabled buttons. */
 
		TileIndex tile = this->window_number;
 
		this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_company),
 
			WID_D_STOP_ALL,
 
			WID_D_START_ALL,
 
			WID_D_SELL,
 
			WID_D_SELL_CHAIN,
 
			WID_D_SELL_ALL,
 
			WID_D_BUILD,
 
			WID_D_CLONE,
0 comments (0 inline, 0 general)