File diff r4076:ac684fc44bc2 → r4077:259c4c4aacad
roadveh_gui.c
Show inline comments
 
@@ -106,13 +106,12 @@ static void RoadVehRefitWndProc(Window *
 
				case 2: { /* List box */
 
					int y = e->click.pt.y - 25;
 
					if (y >= 0) {
 
						WP(w,refit_d).sel = y / 10;
 
						SetWindowDirty(w);
 
					}
 

	
 
					break;
 
				}
 

	
 
				case 4: /* Refit button */
 
					if (WP(w,refit_d).cargo != CT_INVALID) {
 
						const Vehicle *v = GetVehicle(w->window_number);
 
@@ -160,14 +159,14 @@ static void RoadVehDetailsWndProc(Window
 
	switch (e->event) {
 
	case WE_PAINT: {
 
		const Vehicle *v = GetVehicle(w->window_number);
 
		StringID str;
 

	
 
		w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
 
		if (!_patches.servint_roadveh) // disable service-scroller when interval is set to disabled
 
			w->disabled_state |= (1 << 5) | (1 << 6);
 
		// disable service-scroller when interval is set to disabled
 
		if (!_patches.servint_roadveh) w->disabled_state |= (1 << 5) | (1 << 6);
 

	
 
		SetDParam(0, v->string_id);
 
		SetDParam(1, v->unitnumber);
 
		DrawWindowWidgets(w);
 

	
 
		/* Draw running cost */
 
@@ -349,14 +348,15 @@ static void RoadVehViewWndProc(Window *w
 
				break;
 

	
 
			default:
 
				if (v->num_orders == 0) {
 
					str = STR_NO_ORDERS + _patches.vehicle_speed;
 
					SetDParam(0, v->cur_speed / 2);
 
				} else
 
				} else {
 
					str = STR_EMPTY;
 
				}
 
				break;
 
			}
 
		}
 

	
 
		/* draw the flag plus orders */
 
		DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1);
 
@@ -562,14 +562,13 @@ static void NewRoadVehWndProc(Window *w,
 
			DoCommandP(0, WP(w, buildtrain_d).rename_engine, 0, NULL,
 
				CMD_RENAME_ENGINE | CMD_MSG(STR_9037_CAN_T_RENAME_ROAD_VEHICLE));
 
		}
 
		break;
 

	
 
	case WE_RESIZE: {
 
		if (e->sizing.diff.y == 0)
 
			break;
 
		if (e->sizing.diff.y == 0) break;
 

	
 
		w->vscroll.cap += e->sizing.diff.y / 14;
 
		w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
 
	} break;
 

	
 
	}
 
@@ -629,14 +628,13 @@ static void DrawRoadDepotWindow(Window *
 
	w->disabled_state =
 
		IsTileOwner(tile, _local_player) ? 0 : ((1<<4) | (1<<7) | (1<<8));
 

	
 
	/* determine amount of items for scroller */
 
	num = 0;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile)
 
			num++;
 
		if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile) num++;
 
	}
 
	SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
 

	
 
	/* locate the depot struct */
 
	depot = GetDepotByTile(tile);
 
	assert(depot != NULL);
 
@@ -672,18 +670,16 @@ static int GetVehicleFromRoadDepotWndPt(
 
	TileIndex tile;
 
	Vehicle *v;
 
	int pos;
 

	
 
	xt = x / 56;
 
	xm = x % 56;
 
	if (xt >= w->hscroll.cap)
 
		return 1;
 
	if (xt >= w->hscroll.cap) return 1;
 

	
 
	row = (y - 14) / 14;
 
	if (row >= w->vscroll.cap)
 
		return 1;
 
	if (row >= w->vscroll.cap) return 1;
 

	
 
	pos = (row + w->vscroll.pos) * w->hscroll.cap + xt;
 

	
 
	tile = w->window_number;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile &&
 
@@ -704,13 +700,16 @@ static void RoadDepotClickVeh(Window *w,
 
	int mode;
 

	
 
	mode = GetVehicleFromRoadDepotWndPt(w, x, y, &v);
 
	if (mode > 0) return;
 

	
 
	// share / copy orders
 
	if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = v; return; }
 
	if (_thd.place_mode && mode <= 0) {
 
		_place_clicked_vehicle = v;
 
		return;
 
	}
 

	
 
	switch (mode) {
 
	case 0: // start dragging of vehicle
 
		if (v != NULL) {
 
			WP(w,traindepot_d).sel = v->index;
 
			SetWindowDirty(w);
 
@@ -788,20 +787,20 @@ static void RoadDepotWndProc(Window *w, 
 
				ResetObjectToPlace();
 
				ScrollMainWindowToTile(w->window_number);
 
					break;
 
		}
 
	} break;
 

	
 
	case WE_PLACE_OBJ: {
 
	case WE_PLACE_OBJ:
 
		ClonePlaceObj(w);
 
	} break;
 
		break;
 

	
 
	case WE_ABORT_PLACE_OBJ: {
 
	case WE_ABORT_PLACE_OBJ:
 
		CLRBIT(w->click_state, 8);
 
		InvalidateWidget(w, 8);
 
	} break;
 
		break;
 

	
 
	// check if a vehicle in a depot was clicked..
 
	case WE_MOUSELOOP: {
 
		const Vehicle* v = _place_clicked_vehicle;
 

	
 
		// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
 
@@ -845,28 +844,27 @@ static void RoadDepotWndProc(Window *w, 
 
				BackupVehicleOrders(v, _backup_orders_data);
 

	
 
				if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE)))
 
					_backup_orders_tile = 0;
 
			}
 
			break;
 

	
 
		default:
 
			WP(w,traindepot_d).sel = INVALID_VEHICLE;
 
			SetWindowDirty(w);
 
		}
 
		break;
 

	
 
	case WE_RESIZE: {
 
	case WE_RESIZE:
 
		/* Update the scroll + matrix */
 
		w->vscroll.cap += e->sizing.diff.y / 14;
 
		w->hscroll.cap += e->sizing.diff.x / 56;
 
		w->widget[5].unkA = (w->vscroll.cap << 8) + w->hscroll.cap;
 

	
 
	} break;
 
		break;
 

	
 
	}
 

	
 
}
 

	
 
static const Widget _road_depot_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5, 										STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   302,     0,    13, STR_9003_ROAD_VEHICLE_DEPOT,	STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{  WWT_STICKYBOX,     RESIZE_LR,    14,   303,   314,     0,    13, 0x0,													STR_STICKY_BUTTON},
 
@@ -890,16 +888,15 @@ static const WindowDesc _road_depot_desc
 
	_road_depot_widgets,
 
	RoadDepotWndProc
 
};
 

	
 
void ShowRoadDepotWindow(TileIndex tile)
 
{
 
	Window *w;
 
	Window* w = AllocateWindowDescFront(&_road_depot_desc, tile);
 

	
 
	w = AllocateWindowDescFront(&_road_depot_desc, tile);
 
	if (w) {
 
	if (w != NULL) {
 
		w->caption_color = GetTileOwner(w->window_number);
 
		w->hscroll.cap = 5;
 
		w->vscroll.cap = 3;
 
		w->resize.step_width = 56;
 
		w->resize.step_height = 14;
 
		WP(w,traindepot_d).sel = INVALID_VEHICLE;
 
@@ -956,32 +953,30 @@ static void PlayerRoadVehWndProc(Window 
 
		BuildVehicleList(vl, VEH_Road, owner, station);
 
		SortVehicleList(vl);
 

	
 
		SetVScrollCount(w, vl->list_length);
 

	
 
		// disable 'Sort By' tooltip on Unsorted sorting criteria
 
		if (vl->sort_type == SORT_BY_UNSORTED)
 
			w->disabled_state |= (1 << 3);
 
		if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
 

	
 
		/* draw the widgets */
 
		{
 
		if (station == INVALID_STATION) {
 
			const Player *p = GetPlayer(owner);
 
			if (station == INVALID_STATION) {
 

	
 
				/* Company Name -- (###) Road vehicles */
 
				SetDParam(0, p->name_1);
 
				SetDParam(1, p->name_2);
 
				SetDParam(2, w->vscroll.count);
 
				w->widget[1].unkA = STR_9001_ROAD_VEHICLES;
 
			} else {
 
				/* Station Name -- (###) Road vehicles */
 
				SetDParam(0, station);
 
				SetDParam(1, w->vscroll.count);
 
				w->widget[1].unkA = STR_SCHEDULED_ROAD_VEHICLES;
 
			}
 
			DrawWindowWidgets(w);
 
		}
 
		/* draw sorting criteria string */
 
		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
 
		/* draw arrow pointing up/down for ascending/descending sorting */
 
		DoDrawString(vl->flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, 0x10);
 

	
 
		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
 
@@ -1026,39 +1021,34 @@ static void PlayerRoadVehWndProc(Window 
 

	
 
		case 4: case 5:/* Select sorting criteria dropdown menu */
 
			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
 
			return;
 
		case 7: { /* Matrix to show vehicles */
 
			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
 
			const Vehicle* v;
 

	
 
			if (id_v >= w->vscroll.cap) return; // click out of bounds
 

	
 
			id_v += w->vscroll.pos;
 

	
 
			{
 
				Vehicle *v;
 

	
 
				if (id_v >= vl->list_length) return; // click out of list bound
 

	
 
				v	= GetVehicle(vl->sort_list[id_v].index);
 

	
 
				assert(v->type == VEH_Road && v->owner == owner);
 

	
 
				ShowRoadVehViewWindow(v);
 
			}
 
		} break;
 

	
 
		case 9: /* Build new Vehicle */
 
			if (!IsWindowOfPrototype(w, _player_roadveh_widgets)) break;
 
			ShowBuildRoadVehWindow(0);
 
			break;
 

	
 
		case 10: {
 
			if (!IsWindowOfPrototype(w, _player_roadveh_widgets))
 
				break;
 

	
 
			if (!IsWindowOfPrototype(w, _player_roadveh_widgets)) break;
 
			ShowReplaceVehicleWindow(VEH_Road);
 
			break;
 
		}
 
		}
 
	}	break;
 

	
 
@@ -1067,14 +1057,13 @@ static void PlayerRoadVehWndProc(Window 
 
			// value has changed -> resort
 
			vl->flags |= VL_RESORT;
 
			vl->sort_type = e->dropdown.index;
 
			_sorting.roadveh.criteria = vl->sort_type;
 

	
 
			// enable 'Sort By' if a sorter criteria is chosen
 
			if (vl->sort_type != SORT_BY_UNSORTED)
 
				CLRBIT(w->disabled_state, 3);
 
			if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3);
 
		}
 
		SetWindowDirty(w);
 
		break;
 

	
 
	case WE_CREATE: /* set up resort timer */
 
		vl->sort_list = NULL;