--- C:\DOCUME~1\X\LOKALA~1\Temp\depot_gui.cpp-revBASE.svn000.tmp.cpp to maj 14 22:07:28 2009 +++ D:\D\Projects\OpenTTD\trunk\src\depot_gui.cpp to maj 14 22:12:36 2009 @@ -237,6 +237,8 @@ bool generate_list; VehicleList vehicle_list; VehicleList wagon_list; + const Vehicle *tmp_vehicle; + bool tmp_ctrl_pressed; DepotWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc, tile) { @@ -556,8 +558,8 @@ */ void HandleCloneVehClick(const Vehicle *v, const Window *w) { - StringID error_str; - + this->tmp_vehicle = NULL; + this->tmp_ctrl_pressed = false; if (v == NULL) return; if (!v->IsPrimaryVehicle()) { @@ -566,17 +568,51 @@ if (v->type == VEH_TRAIN && !IsFrontEngine(v)) return; } - switch (v->type) { + if (_alt_pressed) + { + /* First, store the vehicle to clone and if ctrl was pressed. Show a window that will call OnQueryFinished with the desired amount of clones. */ + this->tmp_vehicle = v; + this->tmp_ctrl_pressed = _ctrl_pressed; + ShowQueryString(STR_EMPTY, STR_DEPOT_CLONE_VEHICLE_CAPTION, 30, 180, this, CS_NUMERAL, QSF_NONE); + } + else + { + uint error_str; + switch (v->type) { case VEH_TRAIN: error_str = STR_ERROR_CAN_T_BUILD_RAILROAD_VEHICLE; break; case VEH_ROAD: error_str = STR_ERROR_CAN_T_BUILD_ROAD_VEHICLE; break; case VEH_SHIP: error_str = STR_ERROR_CAN_T_BUILD_SHIP; break; case VEH_AIRCRAFT: error_str = STR_ERROR_CAN_T_BUILD_AIRCRAFT; break; default: return; + } + + DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CMD_CLONE_VEHICLE | error_str, CcCloneVehicle); } + ResetObjectToPlace(); + } - DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CMD_CLONE_VEHICLE | CMD_MSG(error_str), CcCloneVehicle); + /** + * Overloaded function that receives the number of clones to produce + * @param *str is the number in string format + */ + virtual void OnQueryTextFinished(char *str) + { + if (str == NULL) return; + if (this->tmp_vehicle == NULL) return; - ResetObjectToPlace(); + uint error_str; + switch (this->tmp_vehicle->type) { + case VEH_TRAIN: error_str = STR_ERROR_CAN_T_BUILD_RAILROAD_VEHICLE; break; + case VEH_ROAD: error_str = STR_ERROR_CAN_T_BUILD_ROAD_VEHICLE; break; + case VEH_SHIP: error_str = STR_ERROR_CAN_T_BUILD_SHIP; break; + case VEH_AIRCRAFT: error_str = STR_ERROR_CAN_T_BUILD_AIRCRAFT; break; + default: return; + } + + for (int i = 0; i < atoi(str); i++) + DoCommandP(this->window_number, this->tmp_vehicle->index, this->tmp_ctrl_pressed ? 1 : 0, CMD_CLONE_VEHICLE | error_str, CcCloneVehicle); + this->tmp_ctrl_pressed = false; + this->tmp_vehicle = NULL; } void ResizeDepotButtons(Window *w)