File diff r12404:d58b2d050240 → r12405:ba094e765533
src/vehicle_gui.cpp
Show inline comments
 
@@ -230,49 +230,49 @@ static RefitList *BuildRefitList(const V
 
 * @param sel selected refit cargo-type in the window
 
 * @param pos position of the selected item in caller widow
 
 * @param rows number of rows(capacity) in caller window
 
 * @param delta step height in caller window
 
 * @return the refit option that is hightlighted, NULL if none
 
 */
 
static RefitOption *DrawVehicleRefitWindow(const RefitList *list, int sel, uint pos, uint rows, uint delta, uint right)
 
{
 
	RefitOption *refit = list->items;
 
	RefitOption *selected = NULL;
 
	uint num_lines = list->num_lines;
 
	uint y = 31;
 
	uint i;
 

	
 
	/* Draw the list, and find the selected cargo (by its position in list) */
 
	for (i = 0; i < num_lines; i++) {
 
		TextColour colour = TC_BLACK;
 
		if (sel == 0) {
 
			selected = &refit[i];
 
			colour = TC_WHITE;
 
		}
 

	
 
		if (i >= pos && i < pos + rows) {
 
			/* Draw the cargo name */
 
			int last_x = DrawString(2, right, y, GetCargo(refit[i].cargo)->name, colour);
 
			int last_x = DrawString(2, right, y, CargoSpec::Get(refit[i].cargo)->name, colour);
 

	
 
			/* If the callback succeeded, draw the cargo suffix */
 
			if (refit[i].value != CALLBACK_FAILED) {
 
				DrawString(last_x + 1, right, y, GetGRFStringID(GetEngineGRFID(refit[i].engine), 0xD000 + refit[i].value), colour);
 
			}
 
			y += delta;
 
		}
 

	
 
		sel--;
 
	}
 

	
 
	return selected;
 
}
 

	
 
/** Widget numbers of the vehicle refit window. */
 
enum VehicleRefitWidgets {
 
	VRW_CLOSEBOX,
 
	VRW_CAPTION,
 
	VRW_SELECTHEADER,
 
	VRW_MATRIX,
 
	VRW_SCROLLBAR,
 
	VRW_INFOPANEL,
 
	VRW_REFITBUTTON,
 
	VRW_RESIZEBOX,
 
@@ -482,49 +482,49 @@ uint ShowRefitOptionsList(int left, int 
 
	b = InlineString(b, STR_PURCHASE_INFO_REFITTABLE_TO);
 

	
 
	if (cmask == lmask) {
 
		/* Engine can be refitted to all types in this climate */
 
		b = InlineString(b, STR_PURCHASE_INFO_ALL_TYPES);
 
	} else {
 
		/* Check if we are able to refit to more cargo types and unable to. If
 
		 * so, invert the cargo types to list those that we can't refit to. */
 
		if (CountBits(cmask ^ lmask) < CountBits(cmask)) {
 
			cmask ^= lmask;
 
			b = InlineString(b, STR_PURCHASE_INFO_ALL_BUT);
 
		}
 

	
 
		bool first = true;
 

	
 
		/* Add each cargo type to the list */
 
		for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
 
			if (!HasBit(cmask, cid)) continue;
 

	
 
			if (b >= lastof(string) - (2 + 2 * 4)) break; // ", " and two calls to Utf8Encode()
 

	
 
			if (!first) b = strecpy(b, ", ", lastof(string));
 
			first = false;
 

	
 
			b = InlineString(b, GetCargo(cid)->name);
 
			b = InlineString(b, CargoSpec::Get(cid)->name);
 
		}
 
	}
 

	
 
	/* Terminate and display the completed string */
 
	*b = '\0';
 

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

	
 
	SetDParamStr(0, string);
 
	return DrawStringMultiLine(left, right, y, INT32_MAX, STR_JUST_RAW_STRING);
 
}
 

	
 
/** Get the cargo subtype text from NewGRF for the vehicle details window. */
 
StringID GetCargoSubtypeText(const Vehicle *v)
 
{
 
	if (HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_CARGO_SUFFIX)) {
 
		uint16 cb = GetVehicleCallback(CBID_VEHICLE_CARGO_SUFFIX, 0, 0, v->engine_type, v);
 
		if (cb != CALLBACK_FAILED) {
 
			return GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + cb);
 
		}
 
	}
 
	return STR_EMPTY;
 
}