149 Vehicle *v = GetVehicle(_new_vehicle_id); |
151 Vehicle *v = GetVehicle(_new_vehicle_id); |
150 |
152 |
151 ShowVehicleViewWindow(v); |
153 ShowVehicleViewWindow(v); |
152 } |
154 } |
153 |
155 |
154 static void DepotSellAllConfirmationCallback(Window *w, bool confirmed) |
|
155 { |
|
156 if (confirmed) { |
|
157 TileIndex tile = w->window_number; |
|
158 byte vehtype = WP(w, depot_d).type; |
|
159 DoCommandP(tile, vehtype, 0, NULL, CMD_DEPOT_SELL_ALL_VEHICLES); |
|
160 } |
|
161 } |
|
162 |
|
163 const Sprite *GetAircraftSprite(EngineID engine); |
|
164 |
|
165 /** Draw a vehicle in the depot window in the box with the top left corner at x,y |
|
166 * @param *w Window to draw in |
|
167 * @param *v Vehicle to draw |
|
168 * @param x Left side of the box to draw in |
|
169 * @param y Top of the box to draw in |
|
170 */ |
|
171 static void DrawVehicleInDepot(Window *w, const Vehicle *v, int x, int y) |
|
172 { |
|
173 byte diff_x = 0, diff_y = 0; |
|
174 |
|
175 int sprite_y = y + w->resize.step_height - GetVehicleListHeight(v->type); |
|
176 |
|
177 switch (v->type) { |
|
178 case VEH_TRAIN: |
|
179 DrawTrainImage(v, x + 21, sprite_y, WP(w, depot_d).sel, w->hscroll.cap + 4, w->hscroll.pos); |
|
180 |
|
181 /* Number of wagons relative to a standard length wagon (rounded up) */ |
|
182 SetDParam(0, (v->u.rail.cached_total_length + 7) / 8); |
|
183 DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter |
|
184 break; |
|
185 |
|
186 case VEH_ROAD: DrawRoadVehImage( v, x + 24, sprite_y, WP(w, depot_d).sel, 1); break; |
|
187 case VEH_SHIP: DrawShipImage( v, x + 19, sprite_y - 1, WP(w, depot_d).sel); break; |
|
188 case VEH_AIRCRAFT: { |
|
189 const Sprite *spr = GetSprite(v->GetImage(DIR_W)); |
|
190 DrawAircraftImage(v, x + 12, |
|
191 y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset |
|
192 WP(w, depot_d).sel); |
|
193 } break; |
|
194 default: NOT_REACHED(); |
|
195 } |
|
196 |
|
197 if (w->resize.step_height == 14) { |
|
198 /* VEH_TRAIN and VEH_ROAD, which are low */ |
|
199 diff_x = 15; |
|
200 } else { |
|
201 /* VEH_SHIP and VEH_AIRCRAFT, which are tall */ |
|
202 diff_y = 12; |
|
203 } |
|
204 |
|
205 DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, x + diff_x, y + diff_y); |
|
206 |
|
207 SetDParam(0, v->unitnumber); |
|
208 DrawString(x, y + 2, (uint16)(v->max_age - 366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING); |
|
209 } |
|
210 |
|
211 static void DrawDepotWindow(Window *w) |
|
212 { |
|
213 Vehicle **vl = WP(w, depot_d).vehicle_list; |
|
214 TileIndex tile = w->window_number; |
|
215 int x, y, i, maxval; |
|
216 uint16 hnum; |
|
217 uint16 num = WP(w, depot_d).engine_count; |
|
218 |
|
219 /* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */ |
|
220 uint16 rows_in_display = w->widget[DEPOT_WIDGET_MATRIX].data >> 8; |
|
221 uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF; |
|
222 |
|
223 /* setup disabled buttons */ |
|
224 w->SetWidgetsDisabledState(!IsTileOwner(tile, _local_player), |
|
225 DEPOT_WIDGET_STOP_ALL, |
|
226 DEPOT_WIDGET_START_ALL, |
|
227 DEPOT_WIDGET_SELL, |
|
228 DEPOT_WIDGET_SELL_CHAIN, |
|
229 DEPOT_WIDGET_SELL_ALL, |
|
230 DEPOT_WIDGET_BUILD, |
|
231 DEPOT_WIDGET_CLONE, |
|
232 DEPOT_WIDGET_AUTOREPLACE, |
|
233 WIDGET_LIST_END); |
|
234 |
|
235 /* determine amount of items for scroller */ |
|
236 if (WP(w, depot_d).type == VEH_TRAIN) { |
|
237 hnum = 8; |
|
238 for (num = 0; num < WP(w, depot_d).engine_count; num++) { |
|
239 const Vehicle *v = vl[num]; |
|
240 hnum = max(hnum, v->u.rail.cached_total_length); |
|
241 } |
|
242 /* Always have 1 empty row, so people can change the setting of the train */ |
|
243 SetVScrollCount(w, WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count + 1); |
|
244 SetHScrollCount(w, WagonLengthToPixels(hnum)); |
|
245 } else { |
|
246 SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap); |
|
247 } |
|
248 |
|
249 /* locate the depot struct */ |
|
250 if (WP(w, depot_d).type == VEH_AIRCRAFT) { |
|
251 SetDParam(0, GetStationIndex(tile)); // Airport name |
|
252 } else { |
|
253 Depot *depot = GetDepotByTile(tile); |
|
254 assert(depot != NULL); |
|
255 |
|
256 SetDParam(0, depot->town_index); |
|
257 } |
|
258 |
|
259 DrawWindowWidgets(w); |
|
260 |
|
261 num = w->vscroll.pos * boxes_in_each_row; |
|
262 maxval = min(WP(w, depot_d).engine_count, num + (rows_in_display * boxes_in_each_row)); |
|
263 |
|
264 for (x = 2, y = 15; num < maxval; y += w->resize.step_height, x = 2) { // Draw the rows |
|
265 byte i; |
|
266 |
|
267 for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += w->resize.step_width) { |
|
268 /* Draw all vehicles in the current row */ |
|
269 const Vehicle *v = vl[num]; |
|
270 DrawVehicleInDepot(w, v, x, y); |
|
271 } |
|
272 } |
|
273 |
|
274 maxval = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, (w->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row)); |
|
275 |
|
276 /* draw the train wagons, that do not have an engine in front */ |
|
277 for (; num < maxval; num++, y += 14) { |
|
278 const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count]; |
|
279 const Vehicle *u; |
|
280 |
|
281 DrawTrainImage(v, x + 50, y, WP(w, depot_d).sel, w->hscroll.cap - 29, 0); |
|
282 DrawString(x, y + 2, STR_8816, TC_FROMSTRING); |
|
283 |
|
284 /*Draw the train counter */ |
|
285 i = 0; |
|
286 u = v; |
|
287 do i++; while ((u = u->Next()) != NULL); // Determine length of train |
|
288 SetDParam(0, i); // Set the counter |
|
289 DrawStringRightAligned(w->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter |
|
290 } |
|
291 } |
|
292 |
|
293 struct GetDepotVehiclePtData { |
|
294 Vehicle *head; |
|
295 Vehicle *wagon; |
|
296 }; |
|
297 |
|
298 enum DepotGUIAction { |
|
299 MODE_ERROR, |
|
300 MODE_DRAG_VEHICLE, |
|
301 MODE_SHOW_VEHICLE, |
|
302 MODE_START_STOP, |
|
303 }; |
|
304 |
|
305 static DepotGUIAction GetVehicleFromDepotWndPt(const Window *w, int x, int y, Vehicle **veh, GetDepotVehiclePtData *d) |
|
306 { |
|
307 Vehicle **vl = WP(w, depot_d).vehicle_list; |
|
308 uint xt, row, xm = 0, ym = 0; |
|
309 int pos, skip = 0; |
|
310 uint16 boxes_in_each_row = w->widget[DEPOT_WIDGET_MATRIX].data & 0xFF; |
|
311 |
|
312 if (WP(w, depot_d).type == VEH_TRAIN) { |
|
313 xt = 0; |
|
314 x -= 23; |
|
315 } else { |
|
316 xt = x / w->resize.step_width; |
|
317 xm = x % w->resize.step_width; |
|
318 if (xt >= w->hscroll.cap) return MODE_ERROR; |
|
319 |
|
320 ym = (y - 14) % w->resize.step_height; |
|
321 } |
|
322 |
|
323 row = (y - 14) / w->resize.step_height; |
|
324 if (row >= w->vscroll.cap) return MODE_ERROR; |
|
325 |
|
326 pos = ((row + w->vscroll.pos) * boxes_in_each_row) + xt; |
|
327 |
|
328 if (WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count <= pos) { |
|
329 if (WP(w, depot_d).type == VEH_TRAIN) { |
|
330 d->head = NULL; |
|
331 d->wagon = NULL; |
|
332 return MODE_DRAG_VEHICLE; |
|
333 } else { |
|
334 return MODE_ERROR; // empty block, so no vehicle is selected |
|
335 } |
|
336 } |
|
337 |
|
338 if (WP(w, depot_d).engine_count > pos) { |
|
339 *veh = vl[pos]; |
|
340 skip = w->hscroll.pos; |
|
341 } else { |
|
342 vl = WP(w, depot_d).wagon_list; |
|
343 pos -= WP(w, depot_d).engine_count; |
|
344 *veh = vl[pos]; |
|
345 /* free wagons don't have an initial loco. */ |
|
346 x -= _traininfo_vehicle_width; |
|
347 } |
|
348 |
|
349 switch (WP(w, depot_d).type) { |
|
350 case VEH_TRAIN: { |
|
351 Vehicle *v = *veh; |
|
352 d->head = d->wagon = v; |
|
353 |
|
354 /* either pressed the flag or the number, but only when it's a loco */ |
|
355 if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE; |
|
356 |
|
357 skip = (skip * 8) / _traininfo_vehicle_width; |
|
358 x = (x * 8) / _traininfo_vehicle_width; |
|
359 |
|
360 /* Skip vehicles that are scrolled off the list */ |
|
361 x += skip; |
|
362 |
|
363 /* find the vehicle in this row that was clicked */ |
|
364 while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->Next(); |
|
365 |
|
366 /* if an articulated part was selected, find its parent */ |
|
367 while (v != NULL && IsArticulatedPart(v)) v = v->Previous(); |
|
368 |
|
369 d->wagon = v; |
|
370 |
|
371 return MODE_DRAG_VEHICLE; |
|
372 } |
|
373 break; |
|
374 |
|
375 case VEH_ROAD: |
|
376 if (xm >= 24) return MODE_DRAG_VEHICLE; |
|
377 if (xm <= 16) return MODE_SHOW_VEHICLE; |
|
378 break; |
|
379 |
|
380 case VEH_SHIP: |
|
381 if (xm >= 19) return MODE_DRAG_VEHICLE; |
|
382 if (ym <= 10) return MODE_SHOW_VEHICLE; |
|
383 break; |
|
384 |
|
385 case VEH_AIRCRAFT: |
|
386 if (xm >= 12) return MODE_DRAG_VEHICLE; |
|
387 if (ym <= 12) return MODE_SHOW_VEHICLE; |
|
388 break; |
|
389 |
|
390 default: NOT_REACHED(); |
|
391 } |
|
392 return MODE_START_STOP; |
|
393 } |
|
394 |
|
395 static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head) |
156 static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head) |
396 { |
157 { |
397 Vehicle *v; |
158 Vehicle *v; |
398 |
159 |
399 v = GetVehicle(sel); |
160 v = GetVehicle(sel); |
409 |
170 |
410 if (wagon == v) return; |
171 if (wagon == v) return; |
411 |
172 |
412 DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); |
173 DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); |
413 } |
174 } |
414 |
|
415 static void DepotClick(Window *w, int x, int y) |
|
416 { |
|
417 GetDepotVehiclePtData gdvp; |
|
418 Vehicle *v = NULL; |
|
419 DepotGUIAction mode = GetVehicleFromDepotWndPt(w, x, y, &v, &gdvp); |
|
420 |
|
421 /* share / copy orders */ |
|
422 if (_thd.place_mode != VHM_NONE && mode != MODE_ERROR) { |
|
423 _place_clicked_vehicle = (WP(w, depot_d).type == VEH_TRAIN ? gdvp.head : v); |
|
424 return; |
|
425 } |
|
426 |
|
427 if (WP(w, depot_d).type == VEH_TRAIN) v = gdvp.wagon; |
|
428 |
|
429 switch (mode) { |
|
430 case MODE_ERROR: // invalid |
|
431 return; |
|
432 |
|
433 case MODE_DRAG_VEHICLE: { // start dragging of vehicle |
|
434 VehicleID sel = WP(w, depot_d).sel; |
|
435 |
|
436 if (WP(w, depot_d).type == VEH_TRAIN && sel != INVALID_VEHICLE) { |
|
437 WP(w, depot_d).sel = INVALID_VEHICLE; |
|
438 TrainDepotMoveVehicle(v, sel, gdvp.head); |
|
439 } else if (v != NULL) { |
|
440 int image = v->GetImage(DIR_W); |
|
441 |
|
442 WP(w, depot_d).sel = v->index; |
|
443 SetWindowDirty(w); |
|
444 SetObjectToPlaceWnd(image, GetVehiclePalette(v), VHM_DRAG, w); |
|
445 _cursor.vehchain = _ctrl_pressed; |
|
446 } |
|
447 } |
|
448 break; |
|
449 |
|
450 case MODE_SHOW_VEHICLE: // show info window |
|
451 ShowVehicleViewWindow(v); |
|
452 break; |
|
453 |
|
454 case MODE_START_STOP: { // click start/stop flag |
|
455 uint command; |
|
456 |
|
457 switch (WP(w, depot_d).type) { |
|
458 case VEH_TRAIN: command = CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN); break; |
|
459 case VEH_ROAD: command = CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE); break; |
|
460 case VEH_SHIP: command = CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP); break; |
|
461 case VEH_AIRCRAFT: command = CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT); break; |
|
462 default: NOT_REACHED(); command = 0; |
|
463 } |
|
464 DoCommandP(v->tile, v->index, 0, NULL, command); |
|
465 } |
|
466 break; |
|
467 |
|
468 default: NOT_REACHED(); |
|
469 } |
|
470 } |
|
471 |
|
472 /** |
|
473 * Clones a vehicle |
|
474 * @param *v is the original vehicle to clone |
|
475 * @param *w is the window of the depot where the clone is build |
|
476 */ |
|
477 static void HandleCloneVehClick(const Vehicle *v, const Window *w) |
|
478 { |
|
479 uint error_str; |
|
480 |
|
481 if (v == NULL) return; |
|
482 |
|
483 if (!v->IsPrimaryVehicle()) { |
|
484 v = v->First(); |
|
485 /* Do nothing when clicking on a train in depot with no loc attached */ |
|
486 if (v->type == VEH_TRAIN && !IsFrontEngine(v)) return; |
|
487 } |
|
488 |
|
489 switch (v->type) { |
|
490 case VEH_TRAIN: error_str = CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE); break; |
|
491 case VEH_ROAD: error_str = CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE); break; |
|
492 case VEH_SHIP: error_str = CMD_MSG(STR_980D_CAN_T_BUILD_SHIP); break; |
|
493 case VEH_AIRCRAFT: error_str = CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT); break; |
|
494 default: return; |
|
495 } |
|
496 |
|
497 DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | error_str); |
|
498 |
|
499 ResetObjectToPlace(); |
|
500 } |
|
501 |
|
502 static void ClonePlaceObj(const Window *w) |
|
503 { |
|
504 const Vehicle *v = CheckMouseOverVehicle(); |
|
505 |
|
506 if (v != NULL) HandleCloneVehClick(v, w); |
|
507 } |
|
508 |
|
509 static void ResizeDepotButtons(Window *w) |
|
510 { |
|
511 ResizeButtons(w, DEPOT_WIDGET_BUILD, DEPOT_WIDGET_LOCATION); |
|
512 |
|
513 if (WP(w, depot_d).type == VEH_TRAIN) { |
|
514 /* Divide the size of DEPOT_WIDGET_SELL into two equally big buttons so DEPOT_WIDGET_SELL and DEPOT_WIDGET_SELL_CHAIN will get the same size. |
|
515 * This way it will stay the same even if DEPOT_WIDGET_SELL_CHAIN is resized for some reason */ |
|
516 w->widget[DEPOT_WIDGET_SELL_CHAIN].top = ((w->widget[DEPOT_WIDGET_SELL_CHAIN].bottom - w->widget[DEPOT_WIDGET_SELL].top) / 2) + w->widget[DEPOT_WIDGET_SELL].top; |
|
517 w->widget[DEPOT_WIDGET_SELL].bottom = w->widget[DEPOT_WIDGET_SELL_CHAIN].top - 1; |
|
518 } |
|
519 } |
|
520 |
|
521 /* Function to set up vehicle specific sprites and strings |
|
522 * Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites |
|
523 * Vehicle specific text/sprites, that's in a widget, that's only shown for one vehicle type (like sell whole train) is set in the widget array |
|
524 */ |
|
525 static void SetupStringsForDepotWindow(Window *w, VehicleType type) |
|
526 { |
|
527 switch (type) { |
|
528 default: NOT_REACHED(); |
|
529 |
|
530 case VEH_TRAIN: |
|
531 w->widget[DEPOT_WIDGET_CAPTION].data = STR_8800_TRAIN_DEPOT; |
|
532 w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP; |
|
533 w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_TRAIN_TIP; |
|
534 w->widget[DEPOT_WIDGET_SELL].tooltips = STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE; |
|
535 w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP; |
|
536 w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_883F_TRAINS_CLICK_ON_TRAIN_FOR; |
|
537 |
|
538 w->widget[DEPOT_WIDGET_BUILD].data = STR_8815_NEW_VEHICLES; |
|
539 w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_8840_BUILD_NEW_TRAIN_VEHICLE; |
|
540 w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_TRAIN; |
|
541 w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_TRAIN_DEPOT_INFO; |
|
542 |
|
543 w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_8842_CENTER_MAIN_VIEW_ON_TRAIN; |
|
544 w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_TRAIN; |
|
545 w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TIP; |
|
546 w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_TRAIN_TIP; |
|
547 |
|
548 /* Sprites */ |
|
549 w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_TRAIN; |
|
550 w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_TRAIN; |
|
551 w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_TRAIN; |
|
552 break; |
|
553 |
|
554 case VEH_ROAD: |
|
555 w->widget[DEPOT_WIDGET_CAPTION].data = STR_9003_ROAD_VEHICLE_DEPOT; |
|
556 w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_ROADVEH_TIP; |
|
557 w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_ROADVEH_TIP; |
|
558 w->widget[DEPOT_WIDGET_SELL].tooltips = STR_9024_DRAG_ROAD_VEHICLE_TO_HERE; |
|
559 w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP; |
|
560 w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_9022_VEHICLES_CLICK_ON_VEHICLE; |
|
561 |
|
562 w->widget[DEPOT_WIDGET_BUILD].data = STR_9004_NEW_VEHICLES; |
|
563 w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9023_BUILD_NEW_ROAD_VEHICLE; |
|
564 w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_ROAD_VEHICLE; |
|
565 w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_ROAD_VEHICLE_DEPOT_INFO; |
|
566 |
|
567 w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9025_CENTER_MAIN_VIEW_ON_ROAD; |
|
568 w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_LORRY; |
|
569 w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_ROADVEH_TIP; |
|
570 w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_ROADVEH_TIP; |
|
571 |
|
572 /* Sprites */ |
|
573 w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_ROADVEH; |
|
574 w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_ROADVEH; |
|
575 w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_ROADVEH; |
|
576 break; |
|
577 |
|
578 case VEH_SHIP: |
|
579 w->widget[DEPOT_WIDGET_CAPTION].data = STR_9803_SHIP_DEPOT; |
|
580 w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_SHIP_TIP; |
|
581 w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_SHIP_TIP; |
|
582 w->widget[DEPOT_WIDGET_SELL].tooltips = STR_9821_DRAG_SHIP_TO_HERE_TO_SELL; |
|
583 w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP; |
|
584 w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_981F_SHIPS_CLICK_ON_SHIP_FOR; |
|
585 |
|
586 w->widget[DEPOT_WIDGET_BUILD].data = STR_9804_NEW_SHIPS; |
|
587 w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9820_BUILD_NEW_SHIP; |
|
588 w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_SHIP; |
|
589 w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_SHIP_DEPOT_INFO; |
|
590 |
|
591 w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9822_CENTER_MAIN_VIEW_ON_SHIP; |
|
592 w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_SHIP; |
|
593 w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_SHIP_TIP; |
|
594 w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_SHIP_TIP; |
|
595 |
|
596 /* Sprites */ |
|
597 w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_SHIP; |
|
598 w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_SHIP; |
|
599 w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_SHIP; |
|
600 break; |
|
601 |
|
602 case VEH_AIRCRAFT: |
|
603 w->widget[DEPOT_WIDGET_CAPTION].data = STR_A002_AIRCRAFT_HANGAR; |
|
604 w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TIP; |
|
605 w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_HANGAR_TIP; |
|
606 w->widget[DEPOT_WIDGET_SELL].tooltips = STR_A023_DRAG_AIRCRAFT_TO_HERE_TO; |
|
607 w->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP; |
|
608 w->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT; |
|
609 |
|
610 w->widget[DEPOT_WIDGET_BUILD].data = STR_A003_NEW_AIRCRAFT; |
|
611 w->widget[DEPOT_WIDGET_BUILD].tooltips = STR_A022_BUILD_NEW_AIRCRAFT; |
|
612 w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_AIRCRAFT; |
|
613 w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW; |
|
614 |
|
615 w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR; |
|
616 w->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_PLANE; |
|
617 w->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_AIRCRAFT_TIP; |
|
618 w->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_AIRCRAFT_TIP; |
|
619 |
|
620 /* Sprites */ |
|
621 w->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_AIRCRAFT; |
|
622 w->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_AIRCRAFT; |
|
623 w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT; |
|
624 break; |
|
625 } |
|
626 } |
|
627 |
|
628 |
175 |
629 /* Array to hold the block sizes |
176 /* Array to hold the block sizes |
630 * First part is the vehicle type, while the last is 0 = x, 1 = y */ |
177 * First part is the vehicle type, while the last is 0 = x, 1 = y */ |
631 uint _block_sizes[4][2]; |
178 uint _block_sizes[4][2]; |
632 |
179 |
689 ResizeDefaultWindowSizeForRoadVehicles(); |
237 ResizeDefaultWindowSizeForRoadVehicles(); |
690 ResizeDefaultWindowSize(VEH_SHIP); |
238 ResizeDefaultWindowSize(VEH_SHIP); |
691 ResizeDefaultWindowSize(VEH_AIRCRAFT); |
239 ResizeDefaultWindowSize(VEH_AIRCRAFT); |
692 } |
240 } |
693 |
241 |
694 static void CreateDepotListWindow(Window *w, VehicleType type) |
242 static void DepotSellAllConfirmationCallback(Window *w, bool confirmed); |
|
243 const Sprite *GetAircraftSprite(EngineID engine); |
|
244 |
|
245 struct DepotWindow : Window { |
|
246 VehicleID sel; |
|
247 VehicleType type; |
|
248 bool generate_list; |
|
249 uint16 engine_list_length; |
|
250 uint16 wagon_list_length; |
|
251 uint16 engine_count; |
|
252 uint16 wagon_count; |
|
253 Vehicle **vehicle_list; |
|
254 Vehicle **wagon_list; |
|
255 |
|
256 DepotWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
|
257 { |
|
258 this->sel = INVALID_VEHICLE; |
|
259 this->vehicle_list = NULL; |
|
260 this->wagon_list = NULL; |
|
261 this->engine_count = 0; |
|
262 this->wagon_count = 0; |
|
263 this->generate_list = true; |
|
264 |
|
265 this->FindWindowPlacementAndResize(desc); |
|
266 } |
|
267 |
|
268 ~DepotWindow() |
|
269 { |
|
270 DeleteWindowById(WC_BUILD_VEHICLE, this->window_number); |
|
271 free((void*)this->vehicle_list); |
|
272 free((void*)this->wagon_list); |
|
273 } |
|
274 |
|
275 /** Draw a vehicle in the depot window in the box with the top left corner at x,y |
|
276 * @param *w Window to draw in |
|
277 * @param *v Vehicle to draw |
|
278 * @param x Left side of the box to draw in |
|
279 * @param y Top of the box to draw in |
|
280 */ |
|
281 void DrawVehicleInDepot(Window *w, const Vehicle *v, int x, int y) |
|
282 { |
|
283 byte diff_x = 0, diff_y = 0; |
|
284 |
|
285 int sprite_y = y + this->resize.step_height - GetVehicleListHeight(v->type); |
|
286 |
|
287 switch (v->type) { |
|
288 case VEH_TRAIN: |
|
289 DrawTrainImage(v, x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos); |
|
290 |
|
291 /* Number of wagons relative to a standard length wagon (rounded up) */ |
|
292 SetDParam(0, (v->u.rail.cached_total_length + 7) / 8); |
|
293 DrawStringRightAligned(this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter |
|
294 break; |
|
295 |
|
296 case VEH_ROAD: DrawRoadVehImage( v, x + 24, sprite_y, this->sel, 1); break; |
|
297 case VEH_SHIP: DrawShipImage( v, x + 19, sprite_y - 1, this->sel); break; |
|
298 case VEH_AIRCRAFT: { |
|
299 const Sprite *spr = GetSprite(v->GetImage(DIR_W)); |
|
300 DrawAircraftImage(v, x + 12, |
|
301 y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset |
|
302 this->sel); |
|
303 } break; |
|
304 default: NOT_REACHED(); |
|
305 } |
|
306 |
|
307 if (this->resize.step_height == 14) { |
|
308 /* VEH_TRAIN and VEH_ROAD, which are low */ |
|
309 diff_x = 15; |
|
310 } else { |
|
311 /* VEH_SHIP and VEH_AIRCRAFT, which are tall */ |
|
312 diff_y = 12; |
|
313 } |
|
314 |
|
315 DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, x + diff_x, y + diff_y); |
|
316 |
|
317 SetDParam(0, v->unitnumber); |
|
318 DrawString(x, y + 2, (uint16)(v->max_age - 366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING); |
|
319 } |
|
320 |
|
321 void DrawDepotWindow(Window *w) |
|
322 { |
|
323 Vehicle **vl = this->vehicle_list; |
|
324 TileIndex tile = this->window_number; |
|
325 int x, y, i, maxval; |
|
326 uint16 hnum; |
|
327 uint16 num = this->engine_count; |
|
328 |
|
329 /* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */ |
|
330 uint16 rows_in_display = this->widget[DEPOT_WIDGET_MATRIX].data >> 8; |
|
331 uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF; |
|
332 |
|
333 /* setup disabled buttons */ |
|
334 this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_player), |
|
335 DEPOT_WIDGET_STOP_ALL, |
|
336 DEPOT_WIDGET_START_ALL, |
|
337 DEPOT_WIDGET_SELL, |
|
338 DEPOT_WIDGET_SELL_CHAIN, |
|
339 DEPOT_WIDGET_SELL_ALL, |
|
340 DEPOT_WIDGET_BUILD, |
|
341 DEPOT_WIDGET_CLONE, |
|
342 DEPOT_WIDGET_AUTOREPLACE, |
|
343 WIDGET_LIST_END); |
|
344 |
|
345 /* determine amount of items for scroller */ |
|
346 if (this->type == VEH_TRAIN) { |
|
347 hnum = 8; |
|
348 for (num = 0; num < this->engine_count; num++) { |
|
349 const Vehicle *v = vl[num]; |
|
350 hnum = max(hnum, v->u.rail.cached_total_length); |
|
351 } |
|
352 /* Always have 1 empty row, so people can change the setting of the train */ |
|
353 SetVScrollCount(w, this->engine_count + this->wagon_count + 1); |
|
354 SetHScrollCount(w, WagonLengthToPixels(hnum)); |
|
355 } else { |
|
356 SetVScrollCount(w, (num + this->hscroll.cap - 1) / this->hscroll.cap); |
|
357 } |
|
358 |
|
359 /* locate the depot struct */ |
|
360 if (this->type == VEH_AIRCRAFT) { |
|
361 SetDParam(0, GetStationIndex(tile)); // Airport name |
|
362 } else { |
|
363 Depot *depot = GetDepotByTile(tile); |
|
364 assert(depot != NULL); |
|
365 |
|
366 SetDParam(0, depot->town_index); |
|
367 } |
|
368 |
|
369 w->DrawWidgets(); |
|
370 |
|
371 num = this->vscroll.pos * boxes_in_each_row; |
|
372 maxval = min(this->engine_count, num + (rows_in_display * boxes_in_each_row)); |
|
373 |
|
374 for (x = 2, y = 15; num < maxval; y += this->resize.step_height, x = 2) { // Draw the rows |
|
375 byte i; |
|
376 |
|
377 for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += this->resize.step_width) { |
|
378 /* Draw all vehicles in the current row */ |
|
379 const Vehicle *v = vl[num]; |
|
380 DrawVehicleInDepot(w, v, x, y); |
|
381 } |
|
382 } |
|
383 |
|
384 maxval = min(this->engine_count + this->wagon_count, (this->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row)); |
|
385 |
|
386 /* draw the train wagons, that do not have an engine in front */ |
|
387 for (; num < maxval; num++, y += 14) { |
|
388 const Vehicle *v = this->wagon_list[num - this->engine_count]; |
|
389 const Vehicle *u; |
|
390 |
|
391 DrawTrainImage(v, x + 50, y, this->sel, this->hscroll.cap - 29, 0); |
|
392 DrawString(x, y + 2, STR_8816, TC_FROMSTRING); |
|
393 |
|
394 /*Draw the train counter */ |
|
395 i = 0; |
|
396 u = v; |
|
397 do i++; while ((u = u->Next()) != NULL); // Determine length of train |
|
398 SetDParam(0, i); // Set the counter |
|
399 DrawStringRightAligned(this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter |
|
400 } |
|
401 } |
|
402 |
|
403 struct GetDepotVehiclePtData { |
|
404 Vehicle *head; |
|
405 Vehicle *wagon; |
|
406 }; |
|
407 |
|
408 enum DepotGUIAction { |
|
409 MODE_ERROR, |
|
410 MODE_DRAG_VEHICLE, |
|
411 MODE_SHOW_VEHICLE, |
|
412 MODE_START_STOP, |
|
413 }; |
|
414 |
|
415 DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, Vehicle **veh, GetDepotVehiclePtData *d) const |
|
416 { |
|
417 Vehicle **vl = this->vehicle_list; |
|
418 uint xt, row, xm = 0, ym = 0; |
|
419 int pos, skip = 0; |
|
420 uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF; |
|
421 |
|
422 if (this->type == VEH_TRAIN) { |
|
423 xt = 0; |
|
424 x -= 23; |
|
425 } else { |
|
426 xt = x / this->resize.step_width; |
|
427 xm = x % this->resize.step_width; |
|
428 if (xt >= this->hscroll.cap) return MODE_ERROR; |
|
429 |
|
430 ym = (y - 14) % this->resize.step_height; |
|
431 } |
|
432 |
|
433 row = (y - 14) / this->resize.step_height; |
|
434 if (row >= this->vscroll.cap) return MODE_ERROR; |
|
435 |
|
436 pos = ((row + this->vscroll.pos) * boxes_in_each_row) + xt; |
|
437 |
|
438 if (this->engine_count + this->wagon_count <= pos) { |
|
439 if (this->type == VEH_TRAIN) { |
|
440 d->head = NULL; |
|
441 d->wagon = NULL; |
|
442 return MODE_DRAG_VEHICLE; |
|
443 } else { |
|
444 return MODE_ERROR; // empty block, so no vehicle is selected |
|
445 } |
|
446 } |
|
447 |
|
448 if (this->engine_count > pos) { |
|
449 *veh = vl[pos]; |
|
450 skip = this->hscroll.pos; |
|
451 } else { |
|
452 vl = this->wagon_list; |
|
453 pos -= this->engine_count; |
|
454 *veh = vl[pos]; |
|
455 /* free wagons don't have an initial loco. */ |
|
456 x -= _traininfo_vehicle_width; |
|
457 } |
|
458 |
|
459 switch (this->type) { |
|
460 case VEH_TRAIN: { |
|
461 Vehicle *v = *veh; |
|
462 d->head = d->wagon = v; |
|
463 |
|
464 /* either pressed the flag or the number, but only when it's a loco */ |
|
465 if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE; |
|
466 |
|
467 skip = (skip * 8) / _traininfo_vehicle_width; |
|
468 x = (x * 8) / _traininfo_vehicle_width; |
|
469 |
|
470 /* Skip vehicles that are scrolled off the list */ |
|
471 x += skip; |
|
472 |
|
473 /* find the vehicle in this row that was clicked */ |
|
474 while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->Next(); |
|
475 |
|
476 /* if an articulated part was selected, find its parent */ |
|
477 while (v != NULL && IsArticulatedPart(v)) v = v->Previous(); |
|
478 |
|
479 d->wagon = v; |
|
480 |
|
481 return MODE_DRAG_VEHICLE; |
|
482 } |
|
483 break; |
|
484 |
|
485 case VEH_ROAD: |
|
486 if (xm >= 24) return MODE_DRAG_VEHICLE; |
|
487 if (xm <= 16) return MODE_SHOW_VEHICLE; |
|
488 break; |
|
489 |
|
490 case VEH_SHIP: |
|
491 if (xm >= 19) return MODE_DRAG_VEHICLE; |
|
492 if (ym <= 10) return MODE_SHOW_VEHICLE; |
|
493 break; |
|
494 |
|
495 case VEH_AIRCRAFT: |
|
496 if (xm >= 12) return MODE_DRAG_VEHICLE; |
|
497 if (ym <= 12) return MODE_SHOW_VEHICLE; |
|
498 break; |
|
499 |
|
500 default: NOT_REACHED(); |
|
501 } |
|
502 return MODE_START_STOP; |
|
503 } |
|
504 |
|
505 void DepotClick(int x, int y) |
|
506 { |
|
507 GetDepotVehiclePtData gdvp = { NULL, NULL }; |
|
508 Vehicle *v = NULL; |
|
509 DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp); |
|
510 |
|
511 /* share / copy orders */ |
|
512 if (_thd.place_mode != VHM_NONE && mode != MODE_ERROR) { |
|
513 _place_clicked_vehicle = (this->type == VEH_TRAIN ? gdvp.head : v); |
|
514 return; |
|
515 } |
|
516 |
|
517 if (this->type == VEH_TRAIN) v = gdvp.wagon; |
|
518 |
|
519 switch (mode) { |
|
520 case MODE_ERROR: // invalid |
|
521 return; |
|
522 |
|
523 case MODE_DRAG_VEHICLE: { // start dragging of vehicle |
|
524 VehicleID sel = this->sel; |
|
525 |
|
526 if (this->type == VEH_TRAIN && sel != INVALID_VEHICLE) { |
|
527 this->sel = INVALID_VEHICLE; |
|
528 TrainDepotMoveVehicle(v, sel, gdvp.head); |
|
529 } else if (v != NULL) { |
|
530 int image = v->GetImage(DIR_W); |
|
531 |
|
532 this->sel = v->index; |
|
533 this->SetDirty(); |
|
534 SetObjectToPlaceWnd(image, GetVehiclePalette(v), VHM_DRAG, this); |
|
535 _cursor.vehchain = _ctrl_pressed; |
|
536 } |
|
537 } break; |
|
538 |
|
539 case MODE_SHOW_VEHICLE: // show info window |
|
540 ShowVehicleViewWindow(v); |
|
541 break; |
|
542 |
|
543 case MODE_START_STOP: { // click start/stop flag |
|
544 uint command; |
|
545 |
|
546 switch (this->type) { |
|
547 case VEH_TRAIN: command = CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN); break; |
|
548 case VEH_ROAD: command = CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE); break; |
|
549 case VEH_SHIP: command = CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP); break; |
|
550 case VEH_AIRCRAFT: command = CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT); break; |
|
551 default: NOT_REACHED(); command = 0; |
|
552 } |
|
553 DoCommandP(v->tile, v->index, 0, NULL, command); |
|
554 } break; |
|
555 |
|
556 default: NOT_REACHED(); |
|
557 } |
|
558 } |
|
559 |
|
560 /** |
|
561 * Clones a vehicle |
|
562 * @param *v is the original vehicle to clone |
|
563 * @param *w is the window of the depot where the clone is build |
|
564 */ |
|
565 void HandleCloneVehClick(const Vehicle *v, const Window *w) |
|
566 { |
|
567 uint error_str; |
|
568 |
|
569 if (v == NULL) return; |
|
570 |
|
571 if (!v->IsPrimaryVehicle()) { |
|
572 v = v->First(); |
|
573 /* Do nothing when clicking on a train in depot with no loc attached */ |
|
574 if (v->type == VEH_TRAIN && !IsFrontEngine(v)) return; |
|
575 } |
|
576 |
|
577 switch (v->type) { |
|
578 case VEH_TRAIN: error_str = CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE); break; |
|
579 case VEH_ROAD: error_str = CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE); break; |
|
580 case VEH_SHIP: error_str = CMD_MSG(STR_980D_CAN_T_BUILD_SHIP); break; |
|
581 case VEH_AIRCRAFT: error_str = CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT); break; |
|
582 default: return; |
|
583 } |
|
584 |
|
585 DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | error_str); |
|
586 |
|
587 ResetObjectToPlace(); |
|
588 } |
|
589 |
|
590 void ResizeDepotButtons(Window *w) |
|
591 { |
|
592 ResizeButtons(w, DEPOT_WIDGET_BUILD, DEPOT_WIDGET_LOCATION); |
|
593 |
|
594 if (this->type == VEH_TRAIN) { |
|
595 /* Divide the size of DEPOT_WIDGET_SELL into two equally big buttons so DEPOT_WIDGET_SELL and DEPOT_WIDGET_SELL_CHAIN will get the same size. |
|
596 * This way it will stay the same even if DEPOT_WIDGET_SELL_CHAIN is resized for some reason */ |
|
597 this->widget[DEPOT_WIDGET_SELL_CHAIN].top = ((this->widget[DEPOT_WIDGET_SELL_CHAIN].bottom - this->widget[DEPOT_WIDGET_SELL].top) / 2) + this->widget[DEPOT_WIDGET_SELL].top; |
|
598 this->widget[DEPOT_WIDGET_SELL].bottom = this->widget[DEPOT_WIDGET_SELL_CHAIN].top - 1; |
|
599 } |
|
600 } |
|
601 |
|
602 /* Function to set up vehicle specific sprites and strings |
|
603 * Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites |
|
604 * Vehicle specific text/sprites, that's in a widget, that's only shown for one vehicle type (like sell whole train) is set in the widget array |
|
605 */ |
|
606 void SetupStringsForDepotWindow(VehicleType type) |
|
607 { |
|
608 switch (type) { |
|
609 default: NOT_REACHED(); |
|
610 |
|
611 case VEH_TRAIN: |
|
612 this->widget[DEPOT_WIDGET_CAPTION].data = STR_8800_TRAIN_DEPOT; |
|
613 this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP; |
|
614 this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_TRAIN_TIP; |
|
615 this->widget[DEPOT_WIDGET_SELL].tooltips = STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE; |
|
616 this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP; |
|
617 this->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_883F_TRAINS_CLICK_ON_TRAIN_FOR; |
|
618 |
|
619 this->widget[DEPOT_WIDGET_BUILD].data = STR_8815_NEW_VEHICLES; |
|
620 this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_8840_BUILD_NEW_TRAIN_VEHICLE; |
|
621 this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_TRAIN; |
|
622 this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_TRAIN_DEPOT_INFO; |
|
623 |
|
624 this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_8842_CENTER_MAIN_VIEW_ON_TRAIN; |
|
625 this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_TRAIN; |
|
626 this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TIP; |
|
627 this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_TRAIN_TIP; |
|
628 |
|
629 /* Sprites */ |
|
630 this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_TRAIN; |
|
631 this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_TRAIN; |
|
632 this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_TRAIN; |
|
633 break; |
|
634 |
|
635 case VEH_ROAD: |
|
636 this->widget[DEPOT_WIDGET_CAPTION].data = STR_9003_ROAD_VEHICLE_DEPOT; |
|
637 this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_ROADVEH_TIP; |
|
638 this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_ROADVEH_TIP; |
|
639 this->widget[DEPOT_WIDGET_SELL].tooltips = STR_9024_DRAG_ROAD_VEHICLE_TO_HERE; |
|
640 this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP; |
|
641 this->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_9022_VEHICLES_CLICK_ON_VEHICLE; |
|
642 |
|
643 this->widget[DEPOT_WIDGET_BUILD].data = STR_9004_NEW_VEHICLES; |
|
644 this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9023_BUILD_NEW_ROAD_VEHICLE; |
|
645 this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_ROAD_VEHICLE; |
|
646 this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_ROAD_VEHICLE_DEPOT_INFO; |
|
647 |
|
648 this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9025_CENTER_MAIN_VIEW_ON_ROAD; |
|
649 this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_LORRY; |
|
650 this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_ROADVEH_TIP; |
|
651 this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_ROADVEH_TIP; |
|
652 |
|
653 /* Sprites */ |
|
654 this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_ROADVEH; |
|
655 this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_ROADVEH; |
|
656 this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_ROADVEH; |
|
657 break; |
|
658 |
|
659 case VEH_SHIP: |
|
660 this->widget[DEPOT_WIDGET_CAPTION].data = STR_9803_SHIP_DEPOT; |
|
661 this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_SHIP_TIP; |
|
662 this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_SHIP_TIP; |
|
663 this->widget[DEPOT_WIDGET_SELL].tooltips = STR_9821_DRAG_SHIP_TO_HERE_TO_SELL; |
|
664 this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP; |
|
665 this->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_981F_SHIPS_CLICK_ON_SHIP_FOR; |
|
666 |
|
667 this->widget[DEPOT_WIDGET_BUILD].data = STR_9804_NEW_SHIPS; |
|
668 this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9820_BUILD_NEW_SHIP; |
|
669 this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_SHIP; |
|
670 this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_SHIP_DEPOT_INFO; |
|
671 |
|
672 this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9822_CENTER_MAIN_VIEW_ON_SHIP; |
|
673 this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_SHIP; |
|
674 this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_SHIP_TIP; |
|
675 this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_SHIP_TIP; |
|
676 |
|
677 /* Sprites */ |
|
678 this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_SHIP; |
|
679 this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_SHIP; |
|
680 this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_SHIP; |
|
681 break; |
|
682 |
|
683 case VEH_AIRCRAFT: |
|
684 this->widget[DEPOT_WIDGET_CAPTION].data = STR_A002_AIRCRAFT_HANGAR; |
|
685 this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TIP; |
|
686 this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_HANGAR_TIP; |
|
687 this->widget[DEPOT_WIDGET_SELL].tooltips = STR_A023_DRAG_AIRCRAFT_TO_HERE_TO; |
|
688 this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP; |
|
689 this->widget[DEPOT_WIDGET_MATRIX].tooltips = STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT; |
|
690 |
|
691 this->widget[DEPOT_WIDGET_BUILD].data = STR_A003_NEW_AIRCRAFT; |
|
692 this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_A022_BUILD_NEW_AIRCRAFT; |
|
693 this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_AIRCRAFT; |
|
694 this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW; |
|
695 |
|
696 this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR; |
|
697 this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_PLANE; |
|
698 this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_AIRCRAFT_TIP; |
|
699 this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_AIRCRAFT_TIP; |
|
700 |
|
701 /* Sprites */ |
|
702 this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_AIRCRAFT; |
|
703 this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_AIRCRAFT; |
|
704 this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT; |
|
705 break; |
|
706 } |
|
707 } |
|
708 |
|
709 void CreateDepotListWindow(VehicleType type) |
|
710 { |
|
711 this->type = type; |
|
712 _backup_orders_tile = 0; |
|
713 |
|
714 assert(IsPlayerBuildableVehicleType(type)); // ensure that we make the call with a valid type |
|
715 |
|
716 /* Resize the window according to the vehicle type */ |
|
717 |
|
718 /* Set the number of blocks in each direction */ |
|
719 this->vscroll.cap = _resize_cap[type][0]; |
|
720 this->hscroll.cap = _resize_cap[type][1]; |
|
721 |
|
722 /* Set the block size */ |
|
723 this->resize.step_width = _block_sizes[type][0]; |
|
724 this->resize.step_height = _block_sizes[type][1]; |
|
725 |
|
726 /* Enlarge the window to fit with the selected number of blocks of the selected size */ |
|
727 ResizeWindow(this, |
|
728 _block_sizes[type][0] * this->hscroll.cap, |
|
729 _block_sizes[type][1] * this->vscroll.cap); |
|
730 |
|
731 if (type == VEH_TRAIN) { |
|
732 /* Make space for the horizontal scrollbar vertically, and the unit |
|
733 * number, flag, and length counter horizontally. */ |
|
734 ResizeWindow(this, 36, 12); |
|
735 /* substract the newly added space from the matrix since it was meant for the scrollbar */ |
|
736 this->widget[DEPOT_WIDGET_MATRIX].bottom -= 12; |
|
737 } |
|
738 |
|
739 /* Set the minimum window size to the current window size */ |
|
740 this->resize.width = this->width; |
|
741 this->resize.height = this->height; |
|
742 |
|
743 this->SetupStringsForDepotWindow(type); |
|
744 |
|
745 this->widget[DEPOT_WIDGET_MATRIX].data = |
|
746 (this->vscroll.cap * 0x100) // number of rows to draw on the background |
|
747 + (type == VEH_TRAIN ? 1 : this->hscroll.cap); // number of boxes in each row. Trains always have just one |
|
748 |
|
749 |
|
750 this->SetWidgetsHiddenState(type != VEH_TRAIN, |
|
751 DEPOT_WIDGET_H_SCROLL, |
|
752 DEPOT_WIDGET_SELL_CHAIN, |
|
753 WIDGET_LIST_END); |
|
754 |
|
755 ResizeDepotButtons(this); |
|
756 } |
|
757 |
|
758 virtual void OnInvalidateData(int data) |
|
759 { |
|
760 this->generate_list = true; |
|
761 } |
|
762 |
|
763 virtual void OnPaint() |
|
764 { |
|
765 if (this->generate_list) { |
|
766 /* Generate the vehicle list |
|
767 * It's ok to use the wagon pointers for non-trains as they will be ignored */ |
|
768 BuildDepotVehicleList(this->type, this->window_number, |
|
769 &this->vehicle_list, &this->engine_list_length, &this->engine_count, |
|
770 &this->wagon_list, &this->wagon_list_length, &this->wagon_count); |
|
771 this->generate_list = false; |
|
772 DepotSortList(this->vehicle_list, this->engine_count); |
|
773 } |
|
774 DrawDepotWindow(this); |
|
775 } |
|
776 |
|
777 virtual void OnClick(Point pt, int widget) |
|
778 { |
|
779 switch (widget) { |
|
780 case DEPOT_WIDGET_MATRIX: // List |
|
781 this->DepotClick(pt.x, pt.y); |
|
782 break; |
|
783 |
|
784 case DEPOT_WIDGET_BUILD: // Build vehicle |
|
785 ResetObjectToPlace(); |
|
786 ShowBuildVehicleWindow(this->window_number, this->type); |
|
787 break; |
|
788 |
|
789 case DEPOT_WIDGET_CLONE: // Clone button |
|
790 this->InvalidateWidget(DEPOT_WIDGET_CLONE); |
|
791 this->ToggleWidgetLoweredState(DEPOT_WIDGET_CLONE); |
|
792 |
|
793 if (this->IsWidgetLowered(DEPOT_WIDGET_CLONE)) { |
|
794 static const CursorID clone_icons[] = { |
|
795 SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH, |
|
796 SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE |
|
797 }; |
|
798 |
|
799 _place_clicked_vehicle = NULL; |
|
800 SetObjectToPlaceWnd(clone_icons[this->type], PAL_NONE, VHM_RECT, this); |
|
801 } else { |
|
802 ResetObjectToPlace(); |
|
803 } |
|
804 break; |
|
805 |
|
806 case DEPOT_WIDGET_LOCATION: |
|
807 if (_ctrl_pressed) { |
|
808 ShowExtraViewPortWindow(this->window_number); |
|
809 } else { |
|
810 ScrollMainWindowToTile(this->window_number); |
|
811 } |
|
812 break; |
|
813 |
|
814 case DEPOT_WIDGET_STOP_ALL: |
|
815 case DEPOT_WIDGET_START_ALL: |
|
816 DoCommandP(this->window_number, 0, this->type | (widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP); |
|
817 break; |
|
818 |
|
819 case DEPOT_WIDGET_SELL_ALL: |
|
820 /* Only open the confimation window if there are anything to sell */ |
|
821 if (this->engine_count != 0 || this->wagon_count != 0) { |
|
822 static const StringID confirm_captions[] = { |
|
823 STR_8800_TRAIN_DEPOT, |
|
824 STR_9003_ROAD_VEHICLE_DEPOT, |
|
825 STR_9803_SHIP_DEPOT, |
|
826 STR_A002_AIRCRAFT_HANGAR |
|
827 }; |
|
828 TileIndex tile = this->window_number; |
|
829 byte vehtype = this->type; |
|
830 |
|
831 SetDParam(0, (vehtype == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotByTile(tile)->town_index); |
|
832 ShowQuery( |
|
833 confirm_captions[vehtype], |
|
834 STR_DEPOT_SELL_CONFIRMATION_TEXT, |
|
835 this, |
|
836 DepotSellAllConfirmationCallback |
|
837 ); |
|
838 } |
|
839 break; |
|
840 |
|
841 case DEPOT_WIDGET_VEHICLE_LIST: |
|
842 ShowVehicleListWindow(GetTileOwner(this->window_number), this->type, (TileIndex)this->window_number); |
|
843 break; |
|
844 |
|
845 case DEPOT_WIDGET_AUTOREPLACE: |
|
846 DoCommandP(this->window_number, this->type, 0, NULL, CMD_DEPOT_MASS_AUTOREPLACE); |
|
847 break; |
|
848 |
|
849 } |
|
850 } |
|
851 |
|
852 virtual void OnPlaceObject(Point pt, TileIndex tile) |
|
853 { |
|
854 const Vehicle *v = CheckMouseOverVehicle(); |
|
855 |
|
856 if (v != NULL) HandleCloneVehClick(v, this); |
|
857 } |
|
858 |
|
859 virtual void OnPlaceObjectAbort() |
|
860 { |
|
861 /* abort clone */ |
|
862 this->RaiseWidget(DEPOT_WIDGET_CLONE); |
|
863 this->InvalidateWidget(DEPOT_WIDGET_CLONE); |
|
864 |
|
865 /* abort drag & drop */ |
|
866 this->sel = INVALID_VEHICLE; |
|
867 this->InvalidateWidget(DEPOT_WIDGET_MATRIX); |
|
868 }; |
|
869 |
|
870 /* check if a vehicle in a depot was clicked.. */ |
|
871 virtual void OnMouseLoop() |
|
872 { |
|
873 const Vehicle *v = _place_clicked_vehicle; |
|
874 |
|
875 /* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */ |
|
876 if (v != NULL && this->IsWidgetLowered(DEPOT_WIDGET_CLONE)) { |
|
877 _place_clicked_vehicle = NULL; |
|
878 HandleCloneVehClick(v, this); |
|
879 } |
|
880 } |
|
881 |
|
882 virtual void OnDragDrop(Point pt, int widget) |
|
883 { |
|
884 switch (widget) { |
|
885 case DEPOT_WIDGET_MATRIX: { |
|
886 Vehicle *v; |
|
887 VehicleID sel = this->sel; |
|
888 |
|
889 this->sel = INVALID_VEHICLE; |
|
890 this->SetDirty(); |
|
891 |
|
892 if (this->type == VEH_TRAIN) { |
|
893 GetDepotVehiclePtData gdvp = { NULL, NULL }; |
|
894 |
|
895 if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && |
|
896 sel != INVALID_VEHICLE) { |
|
897 if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) { |
|
898 DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN)); |
|
899 } else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { |
|
900 TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); |
|
901 } else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) { |
|
902 ShowVehicleViewWindow(gdvp.head); |
|
903 } |
|
904 } |
|
905 } else if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, NULL) == MODE_DRAG_VEHICLE && |
|
906 v != NULL && |
|
907 sel == v->index) { |
|
908 ShowVehicleViewWindow(v); |
|
909 } |
|
910 } break; |
|
911 |
|
912 case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN: |
|
913 if (!this->IsWidgetDisabled(DEPOT_WIDGET_SELL) && |
|
914 this->sel != INVALID_VEHICLE) { |
|
915 Vehicle *v; |
|
916 uint command; |
|
917 int sell_cmd; |
|
918 bool is_engine; |
|
919 |
|
920 if (this->IsWidgetDisabled(widget)) return; |
|
921 if (this->sel == INVALID_VEHICLE) return; |
|
922 |
|
923 this->HandleButtonClick(widget); |
|
924 |
|
925 v = GetVehicle(this->sel); |
|
926 this->sel = INVALID_VEHICLE; |
|
927 this->SetDirty(); |
|
928 |
|
929 sell_cmd = (v->type == VEH_TRAIN && (widget == DEPOT_WIDGET_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0; |
|
930 |
|
931 is_engine = (!(v->type == VEH_TRAIN && !IsFrontEngine(v))); |
|
932 |
|
933 if (is_engine) { |
|
934 _backup_orders_tile = v->tile; |
|
935 BackupVehicleOrders(v); |
|
936 } |
|
937 |
|
938 switch (v->type) { |
|
939 case VEH_TRAIN: command = CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE); break; |
|
940 case VEH_ROAD: command = CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE); break; |
|
941 case VEH_SHIP: command = CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP); break; |
|
942 case VEH_AIRCRAFT: command = CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT); break; |
|
943 default: NOT_REACHED(); command = 0; |
|
944 } |
|
945 |
|
946 if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, command) && is_engine) _backup_orders_tile = 0; |
|
947 } |
|
948 break; |
|
949 default: |
|
950 this->sel = INVALID_VEHICLE; |
|
951 this->SetDirty(); |
|
952 } |
|
953 _cursor.vehchain = false; |
|
954 } |
|
955 |
|
956 virtual void OnResize(Point new_size, Point delta) |
|
957 { |
|
958 this->vscroll.cap += delta.y / (int)this->resize.step_height; |
|
959 this->hscroll.cap += delta.x / (int)this->resize.step_width; |
|
960 this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << 8) + (this->type == VEH_TRAIN ? 1 : this->hscroll.cap); |
|
961 ResizeDepotButtons(this); |
|
962 } |
|
963 |
|
964 virtual bool OnCTRLStateChange() |
|
965 { |
|
966 if (this->sel != INVALID_VEHICLE) { |
|
967 _cursor.vehchain = _ctrl_pressed; |
|
968 this->InvalidateWidget(DEPOT_WIDGET_MATRIX); |
|
969 } |
|
970 |
|
971 return true; |
|
972 } |
|
973 }; |
|
974 |
|
975 static void DepotSellAllConfirmationCallback(Window *win, bool confirmed) |
695 { |
976 { |
696 WP(w, depot_d).type = type; |
977 if (confirmed) { |
697 _backup_orders_tile = 0; |
978 DepotWindow *w = (DepotWindow*)win; |
698 |
979 TileIndex tile = w->window_number; |
699 assert(IsPlayerBuildableVehicleType(type)); // ensure that we make the call with a valid type |
980 byte vehtype = w->type; |
700 |
981 DoCommandP(tile, vehtype, 0, NULL, CMD_DEPOT_SELL_ALL_VEHICLES); |
701 /* Resize the window according to the vehicle type */ |
|
702 |
|
703 /* Set the number of blocks in each direction */ |
|
704 w->vscroll.cap = _resize_cap[type][0]; |
|
705 w->hscroll.cap = _resize_cap[type][1]; |
|
706 |
|
707 /* Set the block size */ |
|
708 w->resize.step_width = _block_sizes[type][0]; |
|
709 w->resize.step_height = _block_sizes[type][1]; |
|
710 |
|
711 /* Enlarge the window to fit with the selected number of blocks of the selected size */ |
|
712 ResizeWindow(w, |
|
713 _block_sizes[type][0] * w->hscroll.cap, |
|
714 _block_sizes[type][1] * w->vscroll.cap); |
|
715 |
|
716 if (type == VEH_TRAIN) { |
|
717 /* Make space for the horizontal scrollbar vertically, and the unit |
|
718 * number, flag, and length counter horizontally. */ |
|
719 ResizeWindow(w, 36, 12); |
|
720 /* substract the newly added space from the matrix since it was meant for the scrollbar */ |
|
721 w->widget[DEPOT_WIDGET_MATRIX].bottom -= 12; |
|
722 } |
|
723 |
|
724 /* Set the minimum window size to the current window size */ |
|
725 w->resize.width = w->width; |
|
726 w->resize.height = w->height; |
|
727 |
|
728 SetupStringsForDepotWindow(w, type); |
|
729 |
|
730 w->widget[DEPOT_WIDGET_MATRIX].data = |
|
731 (w->vscroll.cap * 0x100) // number of rows to draw on the background |
|
732 + (type == VEH_TRAIN ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one |
|
733 |
|
734 |
|
735 w->SetWidgetsHiddenState(type != VEH_TRAIN, |
|
736 DEPOT_WIDGET_H_SCROLL, |
|
737 DEPOT_WIDGET_SELL_CHAIN, |
|
738 WIDGET_LIST_END); |
|
739 |
|
740 ResizeDepotButtons(w); |
|
741 } |
|
742 |
|
743 void DepotSortList(Vehicle **v, uint16 length); |
|
744 |
|
745 static void DepotWndProc(Window *w, WindowEvent *e) |
|
746 { |
|
747 switch (e->event) { |
|
748 case WE_CREATE: |
|
749 WP(w, depot_d).sel = INVALID_VEHICLE; |
|
750 WP(w, depot_d).vehicle_list = NULL; |
|
751 WP(w, depot_d).wagon_list = NULL; |
|
752 WP(w, depot_d).engine_count = 0; |
|
753 WP(w, depot_d).wagon_count = 0; |
|
754 WP(w, depot_d).generate_list = true; |
|
755 break; |
|
756 |
|
757 case WE_INVALIDATE_DATA: |
|
758 WP(w, depot_d).generate_list = true; |
|
759 break; |
|
760 |
|
761 case WE_PAINT: |
|
762 if (WP(w, depot_d).generate_list) { |
|
763 /* Generate the vehicle list |
|
764 * It's ok to use the wagon pointers for non-trains as they will be ignored */ |
|
765 BuildDepotVehicleList(WP(w, depot_d).type, w->window_number, |
|
766 &WP(w, depot_d).vehicle_list, &WP(w, depot_d).engine_list_length, &WP(w, depot_d).engine_count, |
|
767 &WP(w, depot_d).wagon_list, &WP(w, depot_d).wagon_list_length, &WP(w, depot_d).wagon_count); |
|
768 WP(w, depot_d).generate_list = false; |
|
769 DepotSortList(WP(w, depot_d).vehicle_list, WP(w, depot_d).engine_count); |
|
770 //#ifndef NDEBUG |
|
771 #if 0 |
|
772 /* We disabled this check for now, but will keep it to quickly make this test again later (if we change some code) */ |
|
773 } else { |
|
774 /* Here we got a piece of code, that only checks if we got a different number of vehicles in the depot list and the number of vehicles actually being in the depot. |
|
775 * IF they aren't the same, then WE_INVALIDATE_DATA should have been called somewhere, but it wasn't and we got a bug |
|
776 * Since this is a time consuming check and not nice to memory fragmentation, it may not stay for long, but it's a good way to check this |
|
777 * We can turn it on/off by switching between #ifndef NDEBUG and #if 0 */ |
|
778 Vehicle **engines = NULL, **wagons = NULL; |
|
779 uint16 engine_count = 0, engine_length = 0; |
|
780 uint16 wagon_count = 0, wagon_length = 0; |
|
781 BuildDepotVehicleList(WP(w, depot_d).type, w->window_number, &engines, &engine_length, &engine_count, |
|
782 &wagons, &wagon_length, &wagon_count); |
|
783 |
|
784 assert(engine_count == WP(w, depot_d).engine_count); |
|
785 assert(wagon_count == WP(w, depot_d).wagon_count); |
|
786 free((void*)engines); |
|
787 free((void*)wagons); |
|
788 #endif |
|
789 } |
|
790 DrawDepotWindow(w); |
|
791 break; |
|
792 |
|
793 case WE_CLICK: |
|
794 switch (e->we.click.widget) { |
|
795 case DEPOT_WIDGET_MATRIX: // List |
|
796 DepotClick(w, e->we.click.pt.x, e->we.click.pt.y); |
|
797 break; |
|
798 |
|
799 case DEPOT_WIDGET_BUILD: // Build vehicle |
|
800 ResetObjectToPlace(); |
|
801 ShowBuildVehicleWindow(w->window_number, WP(w, depot_d).type); |
|
802 break; |
|
803 |
|
804 case DEPOT_WIDGET_CLONE: // Clone button |
|
805 w->InvalidateWidget(DEPOT_WIDGET_CLONE); |
|
806 w->ToggleWidgetLoweredState(DEPOT_WIDGET_CLONE); |
|
807 |
|
808 if (w->IsWidgetLowered(DEPOT_WIDGET_CLONE)) { |
|
809 static const CursorID clone_icons[] = { |
|
810 SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH, |
|
811 SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE |
|
812 }; |
|
813 |
|
814 _place_clicked_vehicle = NULL; |
|
815 SetObjectToPlaceWnd(clone_icons[WP(w, depot_d).type], PAL_NONE, VHM_RECT, w); |
|
816 } else { |
|
817 ResetObjectToPlace(); |
|
818 } |
|
819 break; |
|
820 |
|
821 case DEPOT_WIDGET_LOCATION: ScrollMainWindowToTile(w->window_number); break; |
|
822 |
|
823 case DEPOT_WIDGET_STOP_ALL: |
|
824 case DEPOT_WIDGET_START_ALL: |
|
825 DoCommandP(w->window_number, 0, WP(w, depot_d).type | (e->we.click.widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP); |
|
826 break; |
|
827 |
|
828 case DEPOT_WIDGET_SELL_ALL: |
|
829 /* Only open the confimation window if there are anything to sell */ |
|
830 if (WP(w, depot_d).engine_count != 0 || WP(w, depot_d).wagon_count != 0) { |
|
831 static const StringID confirm_captions[] = { |
|
832 STR_8800_TRAIN_DEPOT, |
|
833 STR_9003_ROAD_VEHICLE_DEPOT, |
|
834 STR_9803_SHIP_DEPOT, |
|
835 STR_A002_AIRCRAFT_HANGAR |
|
836 }; |
|
837 TileIndex tile = w->window_number; |
|
838 byte vehtype = WP(w, depot_d).type; |
|
839 |
|
840 SetDParam(0, (vehtype == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotByTile(tile)->town_index); |
|
841 ShowQuery( |
|
842 confirm_captions[vehtype], |
|
843 STR_DEPOT_SELL_CONFIRMATION_TEXT, |
|
844 w, |
|
845 DepotSellAllConfirmationCallback |
|
846 ); |
|
847 } |
|
848 break; |
|
849 |
|
850 case DEPOT_WIDGET_VEHICLE_LIST: |
|
851 ShowVehicleListWindow(GetTileOwner(w->window_number), WP(w, depot_d).type, (TileIndex)w->window_number); |
|
852 break; |
|
853 |
|
854 case DEPOT_WIDGET_AUTOREPLACE: |
|
855 DoCommandP(w->window_number, WP(w, depot_d).type, 0, NULL, CMD_DEPOT_MASS_AUTOREPLACE); |
|
856 break; |
|
857 |
|
858 } |
|
859 break; |
|
860 |
|
861 case WE_PLACE_OBJ: { |
|
862 ClonePlaceObj(w); |
|
863 } break; |
|
864 |
|
865 case WE_ABORT_PLACE_OBJ: { |
|
866 /* abort clone */ |
|
867 w->RaiseWidget(DEPOT_WIDGET_CLONE); |
|
868 w->InvalidateWidget(DEPOT_WIDGET_CLONE); |
|
869 |
|
870 /* abort drag & drop */ |
|
871 WP(w, depot_d).sel = INVALID_VEHICLE; |
|
872 w->InvalidateWidget(DEPOT_WIDGET_MATRIX); |
|
873 } break; |
|
874 |
|
875 /* check if a vehicle in a depot was clicked.. */ |
|
876 case WE_MOUSELOOP: { |
|
877 const Vehicle *v = _place_clicked_vehicle; |
|
878 |
|
879 /* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */ |
|
880 if (v != NULL && w->IsWidgetLowered(DEPOT_WIDGET_CLONE)) { |
|
881 _place_clicked_vehicle = NULL; |
|
882 HandleCloneVehClick(v, w); |
|
883 } |
|
884 } break; |
|
885 |
|
886 case WE_DESTROY: |
|
887 DeleteWindowById(WC_BUILD_VEHICLE, w->window_number); |
|
888 free((void*)WP(w, depot_d).vehicle_list); |
|
889 free((void*)WP(w, depot_d).wagon_list); |
|
890 break; |
|
891 |
|
892 case WE_DRAGDROP: |
|
893 switch (e->we.click.widget) { |
|
894 case DEPOT_WIDGET_MATRIX: { |
|
895 Vehicle *v; |
|
896 VehicleID sel = WP(w, depot_d).sel; |
|
897 |
|
898 WP(w, depot_d).sel = INVALID_VEHICLE; |
|
899 SetWindowDirty(w); |
|
900 |
|
901 if (WP(w, depot_d).type == VEH_TRAIN) { |
|
902 GetDepotVehiclePtData gdvp; |
|
903 |
|
904 if (GetVehicleFromDepotWndPt(w, e->we.dragdrop.pt.x, e->we.dragdrop.pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && |
|
905 sel != INVALID_VEHICLE) { |
|
906 if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) { |
|
907 DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN)); |
|
908 } else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { |
|
909 TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); |
|
910 } else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) { |
|
911 ShowVehicleViewWindow(gdvp.head); |
|
912 } |
|
913 } |
|
914 } else if (GetVehicleFromDepotWndPt(w, e->we.dragdrop.pt.x, e->we.dragdrop.pt.y, &v, NULL) == MODE_DRAG_VEHICLE && |
|
915 v != NULL && |
|
916 sel == v->index) { |
|
917 ShowVehicleViewWindow(v); |
|
918 } |
|
919 } break; |
|
920 |
|
921 case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN: |
|
922 if (!w->IsWidgetDisabled(DEPOT_WIDGET_SELL) && |
|
923 WP(w, depot_d).sel != INVALID_VEHICLE) { |
|
924 Vehicle *v; |
|
925 uint command; |
|
926 int sell_cmd; |
|
927 bool is_engine; |
|
928 |
|
929 if (w->IsWidgetDisabled(e->we.click.widget)) return; |
|
930 if (WP(w, depot_d).sel == INVALID_VEHICLE) return; |
|
931 |
|
932 w->HandleButtonClick(e->we.click.widget); |
|
933 |
|
934 v = GetVehicle(WP(w, depot_d).sel); |
|
935 WP(w, depot_d).sel = INVALID_VEHICLE; |
|
936 SetWindowDirty(w); |
|
937 |
|
938 sell_cmd = (v->type == VEH_TRAIN && (e->we.click.widget == DEPOT_WIDGET_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0; |
|
939 |
|
940 is_engine = (!(v->type == VEH_TRAIN && !IsFrontEngine(v))); |
|
941 |
|
942 if (is_engine) { |
|
943 _backup_orders_tile = v->tile; |
|
944 BackupVehicleOrders(v); |
|
945 } |
|
946 |
|
947 switch (v->type) { |
|
948 case VEH_TRAIN: command = CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE); break; |
|
949 case VEH_ROAD: command = CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE); break; |
|
950 case VEH_SHIP: command = CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP); break; |
|
951 case VEH_AIRCRAFT: command = CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT); break; |
|
952 default: NOT_REACHED(); command = 0; |
|
953 } |
|
954 |
|
955 if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, command) && is_engine) _backup_orders_tile = 0; |
|
956 } |
|
957 break; |
|
958 default: |
|
959 WP(w, depot_d).sel = INVALID_VEHICLE; |
|
960 SetWindowDirty(w); |
|
961 } |
|
962 _cursor.vehchain = false; |
|
963 break; |
|
964 |
|
965 case WE_RESIZE: |
|
966 w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height; |
|
967 w->hscroll.cap += e->we.sizing.diff.x / (int)w->resize.step_width; |
|
968 w->widget[DEPOT_WIDGET_MATRIX].data = (w->vscroll.cap << 8) + (WP(w, depot_d).type == VEH_TRAIN ? 1 : w->hscroll.cap); |
|
969 ResizeDepotButtons(w); |
|
970 break; |
|
971 |
|
972 case WE_CTRL_CHANGED: |
|
973 if (WP(w, depot_d).sel != INVALID_VEHICLE) { |
|
974 _cursor.vehchain = _ctrl_pressed; |
|
975 w->InvalidateWidget(DEPOT_WIDGET_MATRIX); |
|
976 } |
|
977 break; |
|
978 } |
982 } |
979 } |
983 } |
980 |
984 |
981 /** Opens a depot window |
985 /** Opens a depot window |
982 * @param tile The tile where the depot/hangar is located |
986 * @param tile The tile where the depot/hangar is located |
983 * @param type The type of vehicles in the depot |
987 * @param type The type of vehicles in the depot |
984 */ |
988 */ |
985 void ShowDepotWindow(TileIndex tile, VehicleType type) |
989 void ShowDepotWindow(TileIndex tile, VehicleType type) |
986 { |
990 { |
987 Window *w; |
991 DepotWindow *w; |
988 |
992 |
989 switch (type) { |
993 switch (type) { |
990 default: NOT_REACHED(); |
994 default: NOT_REACHED(); |
991 case VEH_TRAIN: |
995 case VEH_TRAIN: |
992 w = AllocateWindowDescFront(&_train_depot_desc, tile); break; |
996 w = AllocateWindowDescFront<DepotWindow>(&_train_depot_desc, tile); break; |
993 case VEH_ROAD: |
997 case VEH_ROAD: |
994 w = AllocateWindowDescFront(&_road_depot_desc, tile); break; |
998 w = AllocateWindowDescFront<DepotWindow>(&_road_depot_desc, tile); break; |
995 case VEH_SHIP: |
999 case VEH_SHIP: |
996 w = AllocateWindowDescFront(&_ship_depot_desc, tile); break; |
1000 w = AllocateWindowDescFront<DepotWindow>(&_ship_depot_desc, tile); break; |
997 case VEH_AIRCRAFT: |
1001 case VEH_AIRCRAFT: |
998 w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); break; |
1002 w = AllocateWindowDescFront<DepotWindow>(&_aircraft_depot_desc, tile); break; |
999 } |
1003 } |
1000 |
1004 |
1001 if (w != NULL) { |
1005 if (w == NULL) return; |
1002 w->caption_color = GetTileOwner(tile); |
1006 |
1003 CreateDepotListWindow(w, type); |
1007 w->caption_color = GetTileOwner(tile); |
1004 } |
1008 w->CreateDepotListWindow(type); |
1005 } |
1009 } |
1006 |
1010 |
1007 /** Removes the highlight of a vehicle in a depot window |
1011 /** Removes the highlight of a vehicle in a depot window |
1008 * @param *v Vehicle to remove all highlights from |
1012 * @param *v Vehicle to remove all highlights from |
1009 */ |
1013 */ |
1010 void DeleteDepotHighlightOfVehicle(const Vehicle *v) |
1014 void DeleteDepotHighlightOfVehicle(const Vehicle *v) |
1011 { |
1015 { |
1012 Window *w; |
1016 DepotWindow *w; |
1013 |
1017 |
1014 /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any depots either |
1018 /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any depots either |
1015 * If that is the case, we can skip looping though the windows and save time */ |
1019 * If that is the case, we can skip looping though the windows and save time |
|
1020 */ |
1016 if (_special_mouse_mode != WSM_DRAGDROP) return; |
1021 if (_special_mouse_mode != WSM_DRAGDROP) return; |
1017 |
1022 |
1018 w = FindWindowById(WC_VEHICLE_DEPOT, v->tile); |
1023 w = dynamic_cast<DepotWindow*>(FindWindowById(WC_VEHICLE_DEPOT, v->tile)); |
1019 if (w != NULL) { |
1024 if (w != NULL) { |
1020 WP(w, depot_d).sel = INVALID_VEHICLE; |
1025 w->sel = INVALID_VEHICLE; |
1021 ResetObjectToPlace(); |
1026 ResetObjectToPlace(); |
1022 } |
1027 } |
1023 } |
1028 } |