src/build_vehicle_gui.cpp
branchNewGRF_ports
changeset 6720 35756db7e577
parent 6719 4cc327ad39d5
child 6725 23339968083f
--- a/src/build_vehicle_gui.cpp	Sat Jun 02 19:59:29 2007 +0000
+++ b/src/build_vehicle_gui.cpp	Sat Jul 14 19:42:58 2007 +0000
@@ -140,12 +140,14 @@
 
 	if (va != last_engine[0]) {
 		last_engine[0] = va;
-		GetString(last_name[0], GetCustomEngineName(va), lastof(last_name[0]));
+		SetDParam(0, va);
+		GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
 	}
 
 	if (vb != last_engine[1]) {
 		last_engine[1] = vb;
-		GetString(last_name[1], GetCustomEngineName(vb), lastof(last_name[1]));
+		SetDParam(0, vb);
+		GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
 	}
 
 	r = strcmp(last_name[0], last_name[1]); // sort by name
@@ -206,9 +208,9 @@
 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
 
-	int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
-	int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
-	int r = va - vb;
+	Money va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
+	Money vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
+	int r = ClampToI32(va - vb);
 
 	return _internal_sort_order ? -r : r;
 }
@@ -224,9 +226,9 @@
 		* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
 		* Another thing is that both power and running costs should be doubled for multiheaded engines.
 		* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
-	int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power);
-	int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power);
-	int r = vb - va;
+	Money va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power);
+	Money vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power);
+	int r = ClampToI32(vb - va);
 
 	return _internal_sort_order ? -r : r;
 }
@@ -670,7 +672,7 @@
 	int num_wagons  = 0;
 	buildvehicle_d *bv = &WP(w, buildvehicle_d);
 
-	bv->filter.railtype = (w->window_number == 0) ? RAILTYPE_END : GetRailType(w->window_number);
+	bv->filter.railtype = (w->window_number <= VEH_END) ? RAILTYPE_END : GetRailType(w->window_number);
 
 	EngList_RemoveAll(&bv->eng_list);
 
@@ -762,7 +764,8 @@
 	sel_id = INVALID_ENGINE;
 	for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) {
 		if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_player)) continue;
-		if (w->window_number != 0 && !IsAircraftBuildableAtStation(eid, w->window_number)) continue;
+		/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
+		if (w->window_number > VEH_END && !IsAircraftBuildableAtStation(eid, w->window_number)) continue;
 
 		EngList_Add(&bv->eng_list, eid);
 		if (eid == bv->sel_engine) sel_id = eid;
@@ -853,7 +856,8 @@
 		const EngineID engine = eng_list[min];
 		const uint num_engines = IsDefaultGroupID(selected_group) ? p->num_engines[engine] : GetGroup(selected_group)->num_engines[engine];
 
-		DrawString(x + x_offset, y, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
+		SetDParam(0, engine);
+		DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? 0xC : 0x10);
 		DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
 		if (show_count) {
 			SetDParam(0, num_engines);
@@ -884,7 +888,7 @@
 	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
 	uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
 
-	SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number == 0);
+	SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number <= VEH_END);
 
 	SetVScrollCount(w, EngList_Count(&bv->eng_list));
 	SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
@@ -963,7 +967,8 @@
 					case VEH_SHIP:     str = STR_9838_RENAME_SHIP_TYPE;          break;
 					case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE;      break;
 				}
-				ShowQueryString(GetCustomEngineName(sel_eng), str, 31, 160, w, CS_ALPHANUMERAL);
+				SetDParam(0, sel_eng);
+				ShowQueryString(STR_ENGINE_NAME, str, 31, 160, w, CS_ALPHANUMERAL);
 			}
 			break;
 		}
@@ -996,6 +1001,14 @@
 			BuildVehicleClickEvent(w, e);
 			break;
 
+		case WE_DOUBLE_CLICK:
+			if (e->we.click.widget == BUILD_VEHICLE_WIDGET_LIST) {
+				/* When double clicking, we want to buy a vehicle */
+				e->we.click.widget = BUILD_VEHICLE_WIDGET_BUILD;
+				BuildVehicleClickEvent(w, e);
+			}
+			break;
+
 		case WE_ON_EDIT_TEXT: {
 			if (e->we.edittext.str[0] != '\0') {
 				StringID str = STR_NULL;
@@ -1043,12 +1056,17 @@
 {
 	buildvehicle_d *bv;
 	Window *w;
+	/* We want to be able to open both Available Train as Available Ships,
+	 *  so if tile == 0 (Available XXX Window), use 'type' as unique number.
+	 *  As it always is a low value, it won't collide with any real tile
+	 *  number. */
+	uint num = (tile == 0) ? (int)type : tile;
 
 	assert(IsPlayerBuildableVehicleType(type));
 
-	DeleteWindowById(WC_BUILD_VEHICLE, tile);
+	DeleteWindowById(WC_BUILD_VEHICLE, num);
 
-	w = AllocateWindowDescFront(&_build_vehicle_desc, tile);
+	w = AllocateWindowDescFront(&_build_vehicle_desc, num);
 
 	if (w == NULL) return;